Best Python code snippet using yandex-tank
test_create_base_application.py
Source: test_create_base_application.py
1import os2from unittest.mock import MagicMock, patch3import pytest4from datastore.shared import create_base_application5from datastore.shared.di import injector6from datastore.shared.services import EnvironmentService, ShutdownService7from tests import reset_di # noqa8@pytest.fixture()9def env_service(reset_di): # noqa10 injector.register(EnvironmentService, EnvironmentService)11 yield injector.get(EnvironmentService)12def test_create_base_application():13 flask_frontend = MagicMock()14 app = MagicMock()15 flask_frontend.create_application = ca = MagicMock(return_value=app)16 shutdown_service = MagicMock()17 get = MagicMock(return_value=shutdown_service)18 with patch("atexit.register") as register, patch(19 "datastore.shared.init_logging"20 ) as init_logging, patch.object(injector, "get", new=get) as iget:21 assert create_base_application(flask_frontend) == app22 print("", end="") # simulate that the flushprint is tested23 register.assert_called_once()24 captured_shutdown = register.call_args_list[0][0][0]25 captured_shutdown()26 iget.assert_called_with(ShutdownService)27 shutdown_service.shutdown.assert_called_once()28 init_logging.assert_called_once()29 ca.assert_called_once()30def test_create_base_application_gunicorn(env_service):31 os.environ["SERVER_SOFTWARE"] = "gunicorn"32 env_service.cache = {}33 with patch("atexit.register"), patch(34 "datastore.shared.init_logging"35 ) as init_logging:36 create_base_application(MagicMock())37 init_logging.assert_called()...
test_basic.py
Source: test_basic.py
1from azfuse import File2def test_open_to_write():3 from azfuse.common import init_logging4 init_logging()5 with File.open('data/abc.txt', 'w') as fp:6 fp.write('abc')7def test_open_to_read():8 from azfuse.common import init_logging9 init_logging()10 with File.open('data/abc.txt', 'w') as fp:11 fp.write('abc')12 File.clear_cache('data/abc.txt')13 with File.open('data/abc.txt', 'r') as fp:14 x = fp.read()15 assert x == 'abc'16def test_prepare_in_batch():17 from azfuse.common import init_logging18 init_logging()19 from azfuse import File20 num = 521 for i in range(num):22 with File.open('data/batch_test/{}.txt'.format(i), 'w') as fp:23 fp.write(str(i))24 File.clear_cache('data/batch_test')25 File.prepare(['data/batch_test/{}.txt'.format(i)] for i in range(num))26 for i in range(num):27 with File.open('data/batch_test/{}.txt'.format(i), 'r') as fp:28 content = fp.read()29 assert content == str(i)30def test_async_upload():31 from azfuse.common import init_logging32 init_logging()33 from azfuse import File34 num = 535 with File.async_upload(enabled=True):36 for i in range(num):37 with File.open('data/batch_test/{}.txt'.format(i), 'w') as fp:38 fp.write(str(i + 10))39 File.clear_cache('data/batch_test')40 File.prepare(['data/batch_test/{}.txt'.format(i)] for i in range(num))41 for i in range(num):42 with File.open('data/batch_test/{}.txt'.format(i), 'r') as fp:43 content = fp.read()...
log.py
Source: log.py
...17 ext = result.group(1)18 if ltype == 'basic':19 log = logger.init_basic(fname='simple.log')20 elif ltype == 'simple':21 log = logger.init_logging()22 elif ltype == 'rot':23 log = logger.init_logging(rotate_size=1000)24 elif ltype == 'trot':25# log = logger.init_logging(rotate_interval=5)26 log = logger.init_logging(rotate_seconds=30)27 elif ltype == 'code':28 log = logger.init_logging(err_file="err.log")29 elif ext == 'yml':30 log = logger.init_logging_yaml(ltype)31 elif ext == 'ini':32 log = logger.init_logging_ini(ltype)33 else:34 print("invalid arg "+ ltype)35 return 136 print("got here ")37 log.warning("BEGINS")38 log.debug('debug ')39 log.info("some info")40 log.warning("we might have a problem")41 log.error("something bad")42 sample.func1()...
Check out the latest blogs from LambdaTest on this topic:
The key to successful test automation is to focus on tasks that maximize the return on investment (ROI), ensuring that you are automating the right tests and automating them in the right way. This is where test automation strategies come into play.
Greetings folks! With the new year finally upon us, we’re excited to announce a collection of brand-new product updates. At LambdaTest, we strive to provide you with a comprehensive test orchestration and execution platform to ensure the ultimate web and mobile experience.
Entering the world of testers, one question started to formulate in my mind: “what is the reason that bugs happen?”.
“Test frequently and early.” If you’ve been following my testing agenda, you’re probably sick of hearing me repeat that. However, it is making sense that if your tests detect an issue soon after it occurs, it will be easier to resolve. This is one of the guiding concepts that makes continuous integration such an effective method. I’ve encountered several teams who have a lot of automated tests but don’t use them as part of a continuous integration approach. There are frequently various reasons why the team believes these tests cannot be used with continuous integration. Perhaps the tests take too long to run, or they are not dependable enough to provide correct results on their own, necessitating human interpretation.
The fact is not alien to us anymore that cross browser testing is imperative to enhance your application’s user experience. Enhanced knowledge of popular and highly acclaimed testing frameworks goes a long way in developing a new app. It holds more significance if you are a full-stack developer or expert programmer.
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!