Best Python code snippet using stestr_python
test_runfiles.py
Source:test_runfiles.py
...59 )60 self.files = self.MyTestRunner.find_import_files()61 self.modules = self.MyTestRunner.find_modules_from_files(self.files)62 self.all_tests = self.MyTestRunner.find_tests_from_modules(self.modules)63 self.filtered_tests = self.MyTestRunner.filter_tests(self.all_tests)64 def setUp(self):65 self.file_dir = [os.path.abspath(os.path.join(desired_runfiles_path, 'tests_runfiles/samples'))]66 self._setup_scenario(self.file_dir, None)67 def test_suite_used(self):68 for suite in self.all_tests + self.filtered_tests:69 self.assertTrue(isinstance(suite, pydev_runfiles_unittest.PydevTestSuite))70 def test_parse_cmdline(self):71 sys.argv = "pydev_runfiles.py ./".split()72 configuration = pydev_runfiles.parse_cmdline()73 self.assertEqual([sys.argv[1]], configuration.files_or_dirs)74 self.assertEqual(2, configuration.verbosity) # default value75 self.assertEqual(None, configuration.include_tests) # default value76 sys.argv = "pydev_runfiles.py ../images c:/temp".split()77 configuration = pydev_runfiles.parse_cmdline()78 self.assertEqual(sys.argv[1:3], configuration.files_or_dirs)79 self.assertEqual(2, configuration.verbosity)80 sys.argv = "pydev_runfiles.py --verbosity 3 ../junk c:/asdf ".split()81 configuration = pydev_runfiles.parse_cmdline()82 self.assertEqual(sys.argv[3:], configuration.files_or_dirs)83 self.assertEqual(int(sys.argv[2]), configuration.verbosity)84 sys.argv = "pydev_runfiles.py --include_tests test_def ./".split()85 configuration = pydev_runfiles.parse_cmdline()86 self.assertEqual([sys.argv[-1]], configuration.files_or_dirs)87 self.assertEqual([sys.argv[2]], configuration.include_tests)88 sys.argv = "pydev_runfiles.py --include_tests Abc.test_def,Mod.test_abc c:/junk/".split()89 configuration = pydev_runfiles.parse_cmdline()90 self.assertEqual([sys.argv[-1]], configuration.files_or_dirs)91 self.assertEqual(sys.argv[2].split(','), configuration.include_tests)92 sys.argv = ('C:\\eclipse-SDK-3.2-win32\\eclipse\\plugins\\org.python.pydev.debug_1.2.2\\pysrc\\pydev_runfiles.py ' +93 '--verbosity 1 ' +94 'C:\\workspace_eclipse\\fronttpa\\tests\\gui_tests\\calendar_popup_control_test.py ').split()95 configuration = pydev_runfiles.parse_cmdline()96 self.assertEqual([sys.argv[-1]], configuration.files_or_dirs)97 self.assertEqual(1, configuration.verbosity)98 sys.argv = "pydev_runfiles.py --verbosity 1 --include_tests Mod.test_abc c:/junk/ ./".split()99 configuration = pydev_runfiles.parse_cmdline()100 self.assertEqual(sys.argv[5:], configuration.files_or_dirs)101 self.assertEqual(int(sys.argv[2]), configuration.verbosity)102 self.assertEqual([sys.argv[4]], configuration.include_tests)103 sys.argv = "pydev_runfiles.py --exclude_files=*.txt,a*.py".split()104 configuration = pydev_runfiles.parse_cmdline()105 self.assertEqual(['*.txt', 'a*.py'], configuration.exclude_files)106 sys.argv = "pydev_runfiles.py --exclude_tests=*__todo,test*bar".split()107 configuration = pydev_runfiles.parse_cmdline()108 self.assertEqual(['*__todo', 'test*bar'], configuration.exclude_tests)109 def test___adjust_python_path_works_for_directories(self):110 orig_syspath = sys.path111 tempdir = tempfile.gettempdir()112 pydev_runfiles.PydevTestRunner(pydev_runfiles.Configuration(files_or_dirs=[tempdir]))113 self.assertEqual(1, tempdir in sys.path)114 sys.path = orig_syspath[:]115 def test___is_valid_py_file(self):116 isvalid = self.MyTestRunner._PydevTestRunner__is_valid_py_file117 self.assertEqual(1, isvalid("test.py"))118 self.assertEqual(0, isvalid("asdf.pyc"))119 self.assertEqual(0, isvalid("__init__.py"))120 self.assertEqual(0, isvalid("__init__.pyc"))121 self.assertEqual(1, isvalid("asdf asdf.pyw"))122 def test___unixify(self):123 unixify = self.MyTestRunner._PydevTestRunner__unixify124 self.assertEqual("c:/temp/junk/asdf.py", unixify("c:SEPtempSEPjunkSEPasdf.py".replace('SEP', os.sep)))125 def test___importify(self):126 importify = self.MyTestRunner._PydevTestRunner__importify127 self.assertEqual("temp.junk.asdf", importify("temp/junk/asdf.py"))128 self.assertEqual("asdf", importify("asdf.py"))129 self.assertEqual("abc.def.hgi", importify("abc/def/hgi"))130 def test_finding_a_file_from_file_system(self):131 test_file = "simple_test.py"132 self.MyTestRunner.files_or_dirs = [self.file_dir[0] + test_file]133 files = self.MyTestRunner.find_import_files()134 self.assertEqual(1, len(files))135 self.assertEqual(files[0], self.file_dir[0] + test_file)136 def test_finding_files_in_dir_from_file_system(self):137 self.assertEqual(1, len(self.files) > 0)138 for import_file in self.files:139 self.assertEqual(-1, import_file.find(".pyc"))140 self.assertEqual(-1, import_file.find("__init__.py"))141 self.assertEqual(-1, import_file.find("\\"))142 self.assertEqual(-1, import_file.find(".txt"))143 def test___get_module_from_str(self):144 my_importer = self.MyTestRunner._PydevTestRunner__get_module_from_str145 my_os_path = my_importer("os.path", True, 'unused')146 from os import path147 import os.path as path2148 self.assertEqual(path, my_os_path)149 self.assertEqual(path2, my_os_path)150 self.assertNotEqual(__import__("os.path"), my_os_path)151 self.assertNotEqual(__import__("os"), my_os_path)152 def test_finding_modules_from_import_strings(self):153 self.assertEqual(1, len(self.modules) > 0)154 def test_finding_tests_when_no_filter(self):155 # unittest.py will create a TestCase with 0 tests in it156 # since it just imports what is given157 self.assertEqual(1, len(self.all_tests) > 0)158 files_with_tests = [1 for t in self.all_tests if len(t._tests) > 0]159 self.assertNotEqual(len(self.files), len(files_with_tests))160 def count_suite(self, tests=None):161 total = 0162 for t in tests:163 total += t.countTestCases()164 return total165 def test___match(self):166 matcher = self.MyTestRunner._PydevTestRunner__match167 self.assertEqual(1, matcher(None, "aname"))168 self.assertEqual(1, matcher([".*"], "aname"))169 self.assertEqual(0, matcher(["^x$"], "aname"))170 self.assertEqual(0, matcher(["abc"], "aname"))171 self.assertEqual(1, matcher(["abc", "123"], "123"))172 def test_finding_tests_from_modules_with_bad_filter_returns_0_tests(self):173 self._setup_scenario(self.file_dir, ["NO_TESTS_ARE_SURE_TO_HAVE_THIS_NAME"])174 self.assertEqual(0, self.count_suite(self.all_tests))175 def test_finding_test_with_unique_name_returns_1_test(self):176 self._setup_scenario(self.file_dir, include_tests=["test_i_am_a_unique_test_name"])177 filtered_tests = self.MyTestRunner.filter_tests(self.all_tests)178 self.assertEqual(1, self.count_suite(filtered_tests))179 def test_finding_test_with_non_unique_name(self):180 self._setup_scenario(self.file_dir, include_tests=["test_non_unique_name"])181 filtered_tests = self.MyTestRunner.filter_tests(self.all_tests)182 self.assertEqual(1, self.count_suite(filtered_tests) > 2)183 def test_finding_tests_with_regex_filters(self):184 self._setup_scenario(self.file_dir, include_tests=["test_non*"])185 filtered_tests = self.MyTestRunner.filter_tests(self.all_tests)186 self.assertEqual(1, self.count_suite(filtered_tests) > 2)187 self._setup_scenario(self.file_dir, ["^$"])188 filtered_tests = self.MyTestRunner.filter_tests(self.all_tests)189 self.assertEqual(0, self.count_suite(filtered_tests))190 self._setup_scenario(self.file_dir, None, exclude_tests=["*"])191 filtered_tests = self.MyTestRunner.filter_tests(self.all_tests)192 self.assertEqual(0, self.count_suite(filtered_tests))193 def test_matching_tests(self):194 self._setup_scenario(self.file_dir, None, ['StillYetAnotherSampleTest'])195 filtered_tests = self.MyTestRunner.filter_tests(self.all_tests)196 self.assertEqual(1, self.count_suite(filtered_tests))197 self._setup_scenario(self.file_dir, None, ['SampleTest.test_xxxxxx1'])198 filtered_tests = self.MyTestRunner.filter_tests(self.all_tests)199 self.assertEqual(1, self.count_suite(filtered_tests))200 self._setup_scenario(self.file_dir, None, ['SampleTest'])201 filtered_tests = self.MyTestRunner.filter_tests(self.all_tests)202 self.assertEqual(8, self.count_suite(filtered_tests))203 self._setup_scenario(self.file_dir, None, ['AnotherSampleTest.todo_not_tested'])204 filtered_tests = self.MyTestRunner.filter_tests(self.all_tests)205 self.assertEqual(1, self.count_suite(filtered_tests))206 self._setup_scenario(self.file_dir, None, ['StillYetAnotherSampleTest', 'SampleTest.test_xxxxxx1'])207 filtered_tests = self.MyTestRunner.filter_tests(self.all_tests)208 self.assertEqual(2, self.count_suite(filtered_tests))209 self._setup_scenario(self.file_dir, None, exclude_tests=['*'])210 filtered_tests = self.MyTestRunner.filter_tests(self.all_tests)211 self.assertEqual(self.count_suite(filtered_tests), 0)212 self._setup_scenario(self.file_dir, None, exclude_tests=['*a*'])213 filtered_tests = self.MyTestRunner.filter_tests(self.all_tests)214 self.assertEqual(self.count_suite(filtered_tests), 6)215 self.assertEqual(216 set(self.MyTestRunner.list_test_names(filtered_tests)),217 set(['test_1', 'test_2', 'test_xxxxxx1', 'test_xxxxxx2', 'test_xxxxxx3', 'test_xxxxxx4'])218 )219 self._setup_scenario(self.file_dir, None, exclude_tests=['*a*', '*x*'])220 filtered_tests = self.MyTestRunner.filter_tests(self.all_tests)221 self.assertEqual(self.count_suite(filtered_tests), 2)222 self.assertEqual(223 set(self.MyTestRunner.list_test_names(filtered_tests)),224 set(['test_1', 'test_2'])225 )226 self._setup_scenario(self.file_dir, None, exclude_files=['simple_test.py'])227 filtered_tests = self.MyTestRunner.filter_tests(self.all_tests)228 names = self.MyTestRunner.list_test_names(filtered_tests)229 self.assertTrue('test_xxxxxx1' not in names, 'Found: %s' % (names,))230 self.assertEqual(231 set(['test_abc', 'test_non_unique_name', 'test_non_unique_name', 'test_asdf2', 'test_i_am_a_unique_test_name', 'test_non_unique_name', 'test_blank']),232 set(names)233 )234 self._setup_scenario(self.file_dir, None, include_files=['simple3_test.py'])235 filtered_tests = self.MyTestRunner.filter_tests(self.all_tests)236 names = self.MyTestRunner.list_test_names(filtered_tests)237 self.assertTrue('test_xxxxxx1' not in names, 'Found: %s' % (names,))238 self.assertEqual(239 set(['test_non_unique_name']),240 set(names)241 )242 def test_xml_rpc_communication(self):243 import sys244 sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'samples'))245 notifications = []246 class Server:247 def __init__(self, notifications):248 self.notifications = notifications249 def notifyConnected(self):...
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!!