Esempio n. 1
0
 def test_import_relative(self):
     """Tests if relative imports are tracked on the module object."""
     path = os.path.join(BASEDIR, 'selftests', 'functional',
                         'test_basic.py')
     module = safeloader.PythonModule(path)
     for _ in module.iter_classes():
         pass
     self.assertIn('TestCaseTmpDir', module.imported_objects)
Esempio n. 2
0
 def test_is_avocado_test(self):
     passtest_path = os.path.join(BASEDIR, 'examples', 'tests', 'passtest.py')
     passtest_module = safeloader.PythonModule(passtest_path)
     classes = [klass for klass in passtest_module.iter_classes()]
     # there's only one class and one *worthy* Test import in passtest.py
     self.assertEqual(len(classes), 1)
     self.assertEqual(len(passtest_module.klass_imports), 1)
     self.assertEqual(len(passtest_module.mod_imports), 0)
     self.assertTrue(passtest_module.is_matching_klass(classes[0]))
Esempio n. 3
0
    def test_import_of_all_module_level(self):
        """
        Checks if all levels of a module import are taken into account

        This specific source file imports unittest.mock, and we want to
        make sure that unittest is accounted for.
        """
        path = os.path.join(BASEDIR, 'selftests', 'unit', 'test_loader.py')
        module = safeloader.PythonModule(path, 'unittest', 'TestCase')
        for _ in module.iter_classes():
            pass
        self.assertIn('unittest', module.mod_imports)
Esempio n. 4
0
 def setUp(self):
     self.path = os.path.abspath(os.path.dirname(get_this_file()))
     self.module = safeloader.PythonModule(self.path)