def test__test_directories(self): file_set = FileSet(root_path()) expect_stubs = ['applications/app1/tests', 'applications/app2/tests'] expect = [os.path.join(root_path(), x) for x in expect_stubs] self.assertEqual(file_set.test_directories(), expect) return
def test__relative_modules(self): file_set = FileSet(root_path()) expect = ['applications.app1.tests.test_module_a', 'applications.app1.tests.test_module_b', 'applications.app2.tests.adir.test_module_d', 'applications.app2.tests.test_module_c'] self.assertEqual(file_set.relative_modules(), sorted(expect)) return
def test__all_test_files(self): file_set = FileSet(root_path()) expect_stubs = ['applications/app1/tests/test_module_a.py', 'applications/app1/tests/test_module_b.py', 'applications/app2/tests/adir/test_module_d.py' , 'applications/app2/tests/test_module_c.py'] expect = [File(os.path.join(root_path(), x), root_path()) for x in expect_stubs] self.assertEqual(file_set.all_test_files(), sorted(expect)) return
def main(): """ Main routine. """ testset = FileSet('/srv/http/igeejo.com/web2py', want=sys.argv[1:]) for test_file in testset.want_test_files(): print 'Updating: {script}'.format(script=test_file.filename) module_object = test_file.module_object() import_line = test_file.import_line() import_all = module_object.import_all_line() (os_handle, tmp_name) = tempfile.mkstemp(dir=TMP_DIR) file_h = os.fdopen(os_handle, 'w') with open(test_file.filename, 'r') as f_test_script: lines = f_test_script.readlines() for line in lines: if line.strip() == import_all: file_h.write(import_line) file_h.write('\n') else: file_h.write(line) file_h.close()
def test__want_test_files(self): # Want neither app nor file, ie get all file_set = FileSet(root_path()) expect_stubs = ['applications/app1/tests/test_module_a.py', 'applications/app1/tests/test_module_b.py', 'applications/app2/tests/adir/test_module_d.py' , 'applications/app2/tests/test_module_c.py'] expect = [File(os.path.join(root_path(), x), root_path()) for x in expect_stubs] self.assertEqual(file_set.want_test_files(), sorted(expect)) # Want an app # Want neither app nor file file_set = FileSet(root_path(), want=['app2']) expect_stubs = ['applications/app2/tests/adir/test_module_d.py' , 'applications/app2/tests/test_module_c.py'] expect = [File(os.path.join(root_path(), x), root_path()) for x in expect_stubs] self.assertEqual(file_set.want_test_files(), sorted(expect)) # Want two apps file_set = FileSet(root_path(), want=['app1', 'app2']) expect_stubs = ['applications/app1/tests/test_module_a.py', 'applications/app1/tests/test_module_b.py', 'applications/app2/tests/adir/test_module_d.py' , 'applications/app2/tests/test_module_c.py'] expect = [File(os.path.join(root_path(), x), root_path()) for x in expect_stubs] self.assertEqual(file_set.want_test_files(), sorted(expect)) # Want a file file_set = FileSet(root_path(), want=['test_module_b.py']) expect_stubs = ['applications/app1/tests/test_module_b.py'] expect = [File(os.path.join(root_path(), x), root_path()) for x in expect_stubs] self.assertEqual(file_set.want_test_files(), sorted(expect)) # Want two files file_set = FileSet(root_path(), want=['test_module_b.py', 'test_module_d.py']) expect_stubs = ['applications/app1/tests/test_module_b.py', 'applications/app2/tests/adir/test_module_d.py'] expect = [File(os.path.join(root_path(), x), root_path()) for x in expect_stubs] self.assertEqual(file_set.want_test_files(), sorted(expect)) # Want an app and file file_set = FileSet(root_path(), want=['app1', 'test_module_c.py' ]) expect_stubs = ['applications/app1/tests/test_module_a.py', 'applications/app1/tests/test_module_b.py', 'applications/app2/tests/test_module_c.py'] expect = [File(os.path.join(root_path(), x), root_path()) for x in expect_stubs] self.assertEqual(file_set.want_test_files(), sorted(expect)) return