How to use _generate_test_name method in localstack

Best Python code snippet using localstack_python

test_factory.py

Source:test_factory.py Github

copy

Full Screen

...66 self._create_test_method(67 ddt.file_data(data_path)(getattr(self.test_class, self.test_method.__name__))68 )69 return True70 ddt._add_tests_from_data(self.test_class, self._generate_test_name(), self.test_method, self.scenario['data'])71 return True72 def _validate_scenario(self):73 """Method validates test scenario structure.74 Returns:75 bool: True - valid, False - invalid76 """77 if not self.validator.validate_scenario(self.scenario):78 setattr(self.test_class, "errors", str(self.validator.get_errors()))79 self._create_test_method()80 return False81 return True82 def _validate_drivers(self):83 """Method validates names of drivers specified in drivers object.84 Returns:85 bool: True - valid, False - invalid86 """87 if 'drivers' in self.scenario:88 if self.scenario['drivers'].__len__() > 0:89 if any(i not in self.drivers for i in self.scenario['drivers']):90 setattr(self.test_class, "errors", str(self.validator.get_errors()))91 self._create_test_method()92 return False93 return True94 def _check_skip(self):95 """Method checks skip object in test scenario and decorates test method with function `unittest.skip`96 if the object has value True.97 Returns:98 bool: True - Test is skipped, False - Test is not skipped99 """100 if "skip" in self.scenario:101 self._create_test_method(102 unittest.skip(self.scenario['skip'])(getattr(self.test_class, self.test_method.__name__))103 )104 return True105 return False106 def _create_test_method(self, function=None):107 """Method generates test method based on a base method from base test class108 Args:109 function (type): Parameters used for specifying decorated test method110 Returns:111 BaseTest: Generated test method of a test class112 """113 setattr(self.test_class, self._generate_test_name(), self.test_method if function is None else function)114 return self.test_method115 def _generate_test_name(self):116 """Method generates test method name based of a name specified in test scenario.117 Returns:118 str: Generated test method name119 """...

Full Screen

Full Screen

__init__.py

Source:__init__.py Github

copy

Full Screen

...9OUTPUT = 210if yamlish.py3k:11 unicode = str12#logging.basicConfig(level=logging.DEBUG)13def _generate_test_name(source):14 """15 Clean up human-friendly test name into a method name.16 """17 out = source.replace(' ', '_').replace(':', '').replace(',', '').lower()18 return "test_%s" % out19def _create_input_test(test_src, tested_function, options=None):20 """21 Decorate tested function to be used as a method for TestCase.22 """23 def do_test_expected(self):24 """25 Execute a test by calling a tested_function on test_src data.26 """27 self.maxDiff = None28 got = ""29 if 'error' in test_src:30 self.assertRaises(test_src['error'], tested_function,31 test_src['in'], options)32 else:33 want = test_src['out']34 got = tested_function(test_src['in'], options)35 logging.debug('got = type %s', type(got))36 logging.debug("test_src['out'] = %s",37 unicode(test_src['out']))38 self.assertEqual(got, want, """Result matches39 expected = %s40 observed = %s41 """ % (want, got))42 return do_test_expected43def _create_output_test(test_src, tested_function, options=None):44 """45 Decorate tested function to be used as a method for TestCase.46 """47 def do_test_expected(self):48 """49 Execute a test by calling a tested_function on test_src data.50 """51 self.maxDiff = None52 # We currently don't throw any exceptions in Writer, so this53 # this is always false54 if 'error' in test_src:55 self.assertRaises(test_src['error'], yamlish.dumps,56 test_src['in'], options)57 else:58 logging.debug("out:\n%s", textwrap.dedent(test_src['out']))59 want = yaml.load(textwrap.dedent(test_src['out']))60 logging.debug("want:\n%s", want)61 with tempfile.NamedTemporaryFile() as test_file:62 tested_function(test_src['in'], test_file)63 test_file.seek(0)64 got_str = test_file.read()65 logging.debug("got_str = %s", got_str)66 got = yaml.load(got_str)67 self.assertEqual(got, want, "Result matches")68 return do_test_expected69def generate_testsuite(test_data, test_case_shell, test_fce, direction=INPUT,70 options=None):71 """72 Generate tests from the test data, class to build upon and function73 to use for testing.74 """75 for in_test in test_data:76 if ('skip' in in_test) and in_test['skip']:77 logging.debug("test %s skipped!", in_test['name'])78 continue79 name = _generate_test_name(in_test['name'])80 if direction == INPUT:81 test_method = _create_input_test(in_test, test_fce,82 options=options)83 elif direction == OUTPUT:84 test_method = _create_output_test(in_test, test_fce,85 options=options)86 test_method.__name__ = str('test_%s' % name)...

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 localstack 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