Best Python code snippet using slash
test_scope_manager.py
Source:test_scope_manager.py
1# pylint: disable=redefined-outer-name2import collections3import functools4import itertools5import pytest6import slash7from slash.core.scope_manager import ScopeManager, get_current_scope8from .utils import make_runnable_tests9from .utils.suite_writer import Suite10def test_requirement_mismatch_end_of_module():11 """Test that unmet requirements at end of file(module) still enable scope manager to detect the end and properly pop contextx"""12 suite = Suite()13 num_files = 314 num_tests_per_file = 515 for i in range(num_files): # pylint: disable=unused-variable16 file1 = suite.add_file()17 for j in range(num_tests_per_file): # pylint: disable=unused-variable18 file1.add_function_test()19 t = file1.add_function_test()20 t.add_decorator('slash.requires(lambda: False)')21 t.expect_skip()22 suite.run()23def test_scope_manager(dummy_fixture_store, scope_manager, tests_by_module):24 # pylint: disable=protected-access25 last_scopes = None26 for module_index, tests in enumerate(tests_by_module):27 for test_index, test in enumerate(tests):28 scope_manager.begin_test(test)29 assert dummy_fixture_store._scopes == ['session', 'module', 'test']30 expected = _increment_scope(31 last_scopes,32 test=1,33 module=1 if test_index == 0 else 0,34 session=1 if test_index == 0 and module_index == 0 else 0)35 assert dummy_fixture_store._scope_ids == expected36 # make sure the dict is copied37 assert expected is not dummy_fixture_store._scope_ids38 last_scopes = expected39 scope_manager.end_test(test)40 assert dummy_fixture_store._scopes == ['session', 'module']41 assert dummy_fixture_store._scope_ids == last_scopes42 scope_manager.flush_remaining_scopes()43 assert not dummy_fixture_store._scopes44def test_get_current_scope(suite_builder):45 @suite_builder.first_file.add_code46 def __code__():47 # pylint: disable=unused-variable,redefined-outer-name,reimported48 import slash49 import gossip50 TOKEN = 'testing-current-scope-token'51 def _validate_current_scope(expected_scope):52 assert slash.get_current_scope() == expected_scope53 @gossip.register('slash.after_session_start', token=TOKEN)54 def session_validation():55 assert slash.get_current_scope() == 'session'56 @gossip.register('slash.configure', token=TOKEN)57 @gossip.register('slash.app_quit', token=TOKEN)58 def _no_scope():59 assert slash.get_current_scope() is None60 def test_something():61 assert slash.get_current_scope() == 'test'62 gossip.unregister_token(TOKEN)63 suite_builder.build().run().assert_success(1)64 assert get_current_scope() is None65@pytest.fixture66def scope_manager(dummy_fixture_store, forge):67 session = slash.Session()68 forge.replace_with(session, 'fixture_store', dummy_fixture_store)69 return ScopeManager(session)70@pytest.fixture71def dummy_fixture_store():72 return DummyFixtureStore()73@pytest.fixture74def tests_by_module():75 def test_func():76 pass77 num_modules = 578 num_tests_per_module = 379 returned = []80 with slash.Session():81 for module_index in range(num_modules):82 module_name = '__module_{}'.format(module_index)83 returned.append([])84 for test_index in range(num_tests_per_module): # pylint: disable=unused-variable85 [test] = make_runnable_tests(test_func) # pylint: disable=unbalanced-tuple-unpacking86 assert test.__slash__.module_name87 test.__slash__.module_name = module_name88 returned[-1].append(test)89 return returned90def _increment_scope(prev_scopes, **increments):91 if not prev_scopes:92 returned = {}93 else:94 returned = prev_scopes.copy()95 for key, value in increments.items():96 if value == 0:97 continue98 if key not in returned:99 returned[key] = 0100 returned[key] += value101 return returned102class DummyFixtureStore(object):103 def __init__(self):104 super(DummyFixtureStore, self).__init__()105 self._scopes = []106 self._counters = collections.defaultdict(107 functools.partial(itertools.count, 1))108 self._scope_ids = {}109 def push_scope(self, scope):110 self._scopes.append(scope)111 self._scope_ids[scope] = next(self._counters[scope])112 def pop_scope(self, scope):113 latest_scope = self._scopes.pop()...
test_t1_add.py
Source:test_t1_add.py
...56 import_from_csv(io.StringIO(csv_updated), task_v1_session)57 query = Task.query.all()58 assert len(query) == 159 assert query[0].resolution == "done"60def test_latest_scope(task_v1_session):61 csv_test_file = """desc,scopes62task 1,2020-ww39.1 2020-ww39.2 2020-ww39.363"""64 import_from_csv(io.StringIO(csv_test_file), task_v1_session)65 t: Task = Task.query.all()[0]66 assert len(list(matching_scopes(t.task_id))) == 367 assert latest_scope(t.task_id, TimeScope("2020-ww39.1")) == "2020-ww39.3"...
test_cleanup_manager.py
Source:test_cleanup_manager.py
1# pylint: disable=redefined-outer-name2import pytest3from slash.core.cleanup_manager import CleanupManager4from .conftest import Checkpoint5@pytest.mark.parametrize('in_failure', [True, False])6@pytest.mark.parametrize('in_interruption', [True, False])7def test_cleanup_default_scope(cleanup_manager, cleanup, in_failure, in_interruption):8 cleanup_manager.add_cleanup(cleanup)9 assert not cleanup.called10 cleanup_manager.call_cleanups(scope=cleanup_manager.latest_scope, in_failure=in_failure, in_interruption=in_interruption)11 assert cleanup.called == (not in_interruption)12def test_default_scope(cleanup_manager):13 cleanup1 = cleanup_manager.add_cleanup(Checkpoint())14 with cleanup_manager.scope('session'):15 cleanup2 = cleanup_manager.add_cleanup(Checkpoint())16 with cleanup_manager.scope('module'):17 cleanup3 = cleanup_manager.add_cleanup(Checkpoint())18 assert not cleanup3.called19 assert not cleanup2.called20 assert not cleanup1.called21 cleanup_manager.call_cleanups(scope=cleanup_manager.latest_scope, in_failure=False, in_interruption=False)22 assert cleanup1.called23 assert cleanup2.called24 assert cleanup3.called25 assert cleanup3.timestamp < cleanup2.timestamp < cleanup1.timestamp26@pytest.fixture27def cleanup_manager():28 returned = CleanupManager()29 returned.push_scope(None)30 return returned31@pytest.fixture32def cleanup(checkpoint):...
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!!