How to use _prepare_test_args method in Lemoncheesecake

Best Python code snippet using lemoncheesecake

runner.py

Source:runner.py Github

copy

Full Screen

...101 self._handle_disabled_test(context)102 else:103 context.session.skip_test(self.test, "Test skipped because %s" % reason if reason else None)104 @staticmethod105 def _prepare_test_args(test, scheduled_fixtures):106 args = {}107 for arg_name in test.get_arguments():108 if arg_name in test.parameters:109 args[arg_name] = test.parameters[arg_name]110 else:111 args[arg_name] = scheduled_fixtures.get_fixture_result(arg_name)112 return args113 def run(self, context):114 ###115 # Checker whether the test must be executed or not116 ###117 if self._is_test_disabled(context):118 self._handle_disabled_test(context)119 return120 ###121 # Begin test122 ###123 context.session.start_test(self.test)124 ###125 # Setup test (setup and fixtures)126 ###127 suite = self.test.parent_suite128 if suite.has_hook("setup_test"):129 def setup_test_wrapper():130 suite.get_hook("setup_test")(self.test)131 else:132 setup_test_wrapper = None133 if suite.has_hook("teardown_test"):134 def teardown_test_wrapper():135 status_so_far = "passed" if context.session.is_successful(ReportLocation.in_test(self.test)) else "failed"136 suite.get_hook("teardown_test")(self.test, status_so_far)137 else:138 teardown_test_wrapper = None139 setup_teardown_funcs = list()140 setup_teardown_funcs.append((setup_test_wrapper, teardown_test_wrapper))141 scheduled_fixtures = context.fixture_registry.get_fixtures_scheduled_for_test(142 self.test, self.suite_scheduled_fixtures143 )144 setup_teardown_funcs.extend(scheduled_fixtures.get_setup_teardown_pairs())145 context.session.set_step("Setup test")146 if any(setup for setup, _ in setup_teardown_funcs):147 teardown_funcs = context.run_setup_funcs(setup_teardown_funcs, ReportLocation.in_test(self.test))148 else:149 teardown_funcs = [teardown for _, teardown in setup_teardown_funcs if teardown]150 ###151 # Run test:152 ###153 if context.session.is_successful(ReportLocation.in_test(self.test)):154 test_args = self._prepare_test_args(self.test, scheduled_fixtures)155 context.session.set_step(self.test.description)156 try:157 self.test.callback(**test_args)158 except Exception as e:159 context.handle_exception(e, suite)160 ###161 # Teardown162 ###163 if any(teardown_funcs):164 context.session.set_step("Teardown test")165 context.run_teardown_funcs(teardown_funcs)166 context.session.end_test(self.test)167 if not context.session.is_successful(ReportLocation.in_test(self.test)):168 raise TaskFailure("test '%s' failed" % self.test.path)...

Full Screen

Full Screen

test_adt.py

Source:test_adt.py Github

copy

Full Screen

...42from cor.util import split_args43class Input(Enum):44 Good = 'good'45 Bad = 'bad'46def _prepare_test_args(*data, good=list(), bad=list()):47 args, kwargs = split_args(Input, *data)48 assert not args49 good = list(good) + kwargs.get('good', [])50 bad = list(bad) + kwargs.get('bad', [])51 return good + kwargs.get('good', []), bad + kwargs.get('bad', []),52def _test_good_bad(info, convert, good, bad):53 for input_data, expected in good:54 test_info = '{}: Correct input: {}'.format(info, input_data)55 res = convert(*input_data)56 assert res == expected, test_info57 for input_data, err in bad:58 test_info = '{}: Should cause exception: {}'.format(info, input_data)59 with pytest.raises(err):60 convert(*input_data)61 pytest.fail(test_info)62def _test_conversion(conversion, *args, **kwargs):63 good, bad = _prepare_test_args(*args, **kwargs)64 good = [([value], res) for value, res in good]65 bad = [([value], res) for value, res in bad]66 _test_good_bad(conversion.info, conversion.convert, good, bad)67def _test_prepare_field(conversion, *args, **kwargs):68 good, bad = _prepare_test_args(*args, **kwargs)69 good = [([name, value], res) for name, value, res in good]70 bad = [([name, value], res) for name, value, res in bad]71 _test_good_bad(conversion.info, conversion.prepare_field, good, bad)72def test_convert():73 conversion = convert(int)74 _test_conversion(75 conversion,76 Input.Good, ('1', 1), (2, 2),77 Input.Bad, (None, TypeError), ('s', ValueError),78 )79def test_provide_missing():80 _test_conversion(81 provide_missing('foo'),82 Input.Good, (13, 13), ('', ''), (None, 'foo'),83 )84 _test_conversion(85 provide_missing({'a': 1, 'b': 2}),86 Input.Good, (13, 13), ('', ''), (None, {'a': 1, 'b': 2}),87 )88def test_only_if():89 conversion = only_if(lambda x: x < 10, 'less than 10')90 _test_conversion(91 conversion,92 Input.Good, (9, 9),93 Input.Bad, (10, ValueError)94 )95 _test_prepare_field(96 conversion,97 Input.Good,98 ('foo', {'foo': 9}, 9),99 Input.Bad,100 ('foo', {'foo': 10}, InvalidFieldError),101 ('foo', {'bar': 10}, MissingFieldError),102 )103def test_skip_missing():104 conversion = skip_missing105 _test_prepare_field(106 conversion,107 Input.Good,108 ('foo', {}, None),109 ('foo', {'bar': 1, 'foo': 2}, 2),110 )111def test_something():112 conversion = something113 _test_prepare_field(114 conversion,115 Input.Good,116 ('foo', {'foo': 1}, 1),117 ('foo', {'foo': '1'}, '1'),118 Input.Bad,119 ('foo', None, TypeError),120 ('foo', {}, KeyError),121 ('foo', {'bar': 1}, KeyError),122 )123def test_anything():124 conversion = anything125 _test_prepare_field(126 conversion,127 Input.Good,128 ('foo', {}, None),129 ('foo', {'foo': 1}, 1),130 ('foo', {'foo': '1'}, '1'),131 Input.Bad,132 ('foo', None, AttributeError),133 )134def test_expect_types():135 conversion = expect_types(str, float)136 _test_conversion(137 conversion,138 good=(139 (v, v) for v in140 ['', 'foo', 1.1]141 ),142 bad=(143 (v, TypeError) for v in144 [b'', 1, None]145 )146 )147 conversion = expect_type(bytes)148 _test_conversion(conversion, Input.Good, (b'bar', b'bar'))149 _test_prepare_field(150 conversion,151 Input.Good, ('foo', {'foo': b'bar'}, b'bar'),152 Input.Bad, ('foo', 1, InvalidFieldError),153 )154def test_should_be():155 v = dict()156 conversion = should_be(v)157 _test_conversion(158 conversion,159 Input.Good, (v, v),160 Input.Bad, (dict(), ValueError),161 )162def _test_binop_conversion(conversion, *args, **kwargs):163 '''binary op provides only prepare_field method'''164 good, bad = _prepare_test_args(*args, **kwargs)165 good = [166 ('foo', {'foo': value}, res)167 for value, res in good168 ]169 bad = [170 ('foo', {'foo': value}, err)171 for value, err in bad172 ]173 _test_prepare_field(conversion, good=good, bad=bad)174def test_or():175 conversion = convert(int) | convert(str)176 class NoStr:177 def __str__(self):178 raise OverflowError()...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Lemoncheesecake automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful