Best Python code snippet using tappy_python
test_loader.py
Source:test_loader.py
...20 temp = tempfile.NamedTemporaryFile(delete=False)21 temp.write(sample.encode('utf-8'))22 temp.close()23 loader = Loader()24 suite = loader.load_suite_from_file(temp.name)25 # The bail line counts as a failed test.26 self.assertEqual(3, len(suite._tests))27 def test_file_does_not_exist(self):28 """The loader records a failure when a file does not exist."""29 loader = Loader()30 suite = loader.load_suite_from_file('phony.tap')31 self.assertEqual(1, len(suite._tests))32 self.assertEqual(33 'phony.tap does not exist.', suite._tests[0]._line.description)34 def test_handles_directory(self):35 directory = tempfile.mkdtemp()36 sub_directory = os.path.join(directory, 'sub')37 os.mkdir(sub_directory)38 with open(os.path.join(directory, 'a_file.tap'), 'w') as f:39 f.write('ok A passing test')40 with open(os.path.join(sub_directory, 'another_file.tap'), 'w') as f:41 f.write('not ok A failing test')42 loader = Loader()43 suite = loader.load([directory])44 self.assertEqual(2, len(suite._tests))45 def test_errors_with_multiple_version_lines(self):46 sample = inspect.cleandoc(47 """TAP version 1348 TAP version 1349 1..050 """)51 temp = tempfile.NamedTemporaryFile(delete=False)52 temp.write(sample.encode('utf-8'))53 temp.close()54 loader = Loader()55 suite = loader.load_suite_from_file(temp.name)56 self.assertEqual(1, len(suite._tests))57 self.assertEqual(58 'Multiple version lines appeared.',59 suite._tests[0]._line.description)60 def test_errors_with_version_not_on_first_line(self):61 sample = inspect.cleandoc(62 """# Something that doesn't belong.63 TAP version 1364 1..065 """)66 temp = tempfile.NamedTemporaryFile(delete=False)67 temp.write(sample.encode('utf-8'))68 temp.close()69 loader = Loader()70 suite = loader.load_suite_from_file(temp.name)71 self.assertEqual(1, len(suite._tests))72 self.assertEqual(73 'The version must be on the first line.',74 suite._tests[0]._line.description)75 def test_skip_plan_aborts_loading(self):76 sample = inspect.cleandoc(77 """1..0 # Skipping this test file.78 ok This should not get processed.79 """)80 temp = tempfile.NamedTemporaryFile(delete=False)81 temp.write(sample.encode('utf-8'))82 temp.close()83 loader = Loader()84 suite = loader.load_suite_from_file(temp.name)85 self.assertEqual(1, len(suite._tests))86 self.assertEqual(...
loader.py
Source:loader.py
...20 for filepath in files:21 if os.path.isdir(filepath):22 self._find_tests_in_directory(filepath, suite)23 else:24 suite.addTest(self.load_suite_from_file(filepath))25 return suite26 def load_suite_from_file(self, filename):27 """Load a test suite with test lines from the provided TAP file.28 :returns: A ``unittest.TestSuite`` instance29 """30 suite = unittest.TestSuite()31 rules = Rules(filename, suite)32 if not os.path.exists(filename):33 rules.handle_file_does_not_exist()34 return suite35 line_generator = self._parser.parse_file(filename)36 return self._load_lines(filename, line_generator, suite, rules)37 def load_suite_from_stdin(self):38 """Load a test suite with test lines from the TAP stream on STDIN.39 :returns: A ``unittest.TestSuite`` instance40 """41 suite = unittest.TestSuite()42 rules = Rules('stream', suite)43 line_generator = self._parser.parse_stdin()44 return self._load_lines('stream', line_generator, suite, rules)45 def _find_tests_in_directory(self, directory, suite):46 """Find test files in the directory and add them to the suite."""47 for dirpath, dirnames, filenames in os.walk(directory):48 for filename in filenames:49 filepath = os.path.join(dirpath, filename)50 suite.addTest(self.load_suite_from_file(filepath))51 def _load_lines(self, filename, line_generator, suite, rules):52 """Load a suite with lines produced by the line generator."""53 line_counter = 054 for line in line_generator:55 line_counter += 156 if line.category in self.ignored_lines:57 continue58 if line.category == 'test':59 suite.addTest(Adapter(filename, line))60 rules.saw_test()61 elif line.category == 'plan':62 if line.skip:63 rules.handle_skipping_plan(line)64 return suite...
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!!