Best Python code snippet using localstack_python
test_factory.py
Source: test_factory.py
...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 """...
__init__.py
Source: __init__.py
...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)...
Check out the latest blogs from LambdaTest on this topic:
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.
QA testers have a unique role and responsibility to serve the customer. Serving the customer in software testing means protecting customers from application defects, failures, and perceived failures from missing or misunderstood requirements. Testing for known requirements based on documentation or discussion is the core of the testing profession. One unique way QA testers can both differentiate themselves and be innovative occurs when senseshaping is used to improve the application user experience.
Having a good web design can empower business and make your brand stand out. According to a survey by Top Design Firms, 50% of users believe that website design is crucial to an organization’s overall brand. Therefore, businesses should prioritize website design to meet customer expectations and build their brand identity. Your website is the face of your business, so it’s important that it’s updated regularly as per the current web design trends.
Enterprise resource planning (ERP) is a form of business process management software—typically a suite of integrated applications—that assists a company in managing its operations, interpreting data, and automating various back-office processes. The introduction of a new ERP system is analogous to the introduction of a new product into the market. If the product is not handled appropriately, it will fail, resulting in significant losses for the business. Most significantly, the employees’ time, effort, and morale would suffer as a result of the procedure.
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!!