def test_find_modules(self): """Test find_modules method""" test_path = "/some/test/path" find_packages_return_value = [ "/test/path1", "/test/path2", "/test/path3" ] # Patch setuptools module with patch("dodo.introspector.find_packages") as mock_find_packages,\ patch("dodo.introspector.iter_modules") as mock_iter_modules: mock_find_packages.return_value = find_packages_return_value actual_output = Introspector.find_modules(test_path) self.assertEqual(set(find_packages_return_value), actual_output) self.assertEqual(mock_find_packages.call_count, 1) self.assertEqual(mock_iter_modules.call_count, len(find_packages_return_value))
def execute_tests(self): """Execute tests""" # TODO: Use Python 3 Path module # Get the absolute path of supplied directory in case only directory # name is supplied instead of full path absolute_path = os.path.abspath(self._package_dir) # Parent directory is a parent directory of a package. i.e In # /tmp/testdir, /tmp is a parent directory parent_dir = os.path.normpath(os.path.join(absolute_path, "..")) # We need to put parent directory of package in PYTHONPATH to import it sys.path.append(parent_dir) # Get the basename of path. i.e In /tmp/testdir, testdir is a base name package_name = os.path.basename(absolute_path) # NOTE: Introspector.find_modules method doesn't retrieve modules # from top level directory of a package, so We need to process that # separately. # Import package dynamically to get modules in top level directory package_instance = importlib.import_module(package_name) # Get modules from top level package directory modules = Introspector.get_modules_from_package(package_instance) # Get modules recursively all_modules = Introspector.find_modules(self._package_dir) modules.extend(all_modules) # Get functions from all the modules self._module_functions = self._populate_module_functions_list( modules, package_name) self._functions_results = self._execute_test_functions( self._module_functions)