def test_recursive_find_packages(self): pkg_location = utils.create_working_package(self.temp_folder) utils.create_working_package(pkg_location, 'bam') pkgs = filesystem.recursive_find_packages(self.temp_folder) assert len(list(pkgs)) == 2
def test_recursive_find_modules(self): pkg_location = utils.create_working_package(self.temp_folder) subpkg_location = utils.create_working_package(pkg_location, 'bam') mod_location = os.path.join(pkg_location, 'app.py') utils.write_file(mod_location) mod_location = os.path.join(subpkg_location, 'other.py') utils.write_file(mod_location) pkgs = filesystem.recursive_find_modules(pkg_location) assert len(list(pkgs)) == 2
def test_get_inherited_classes(): temp_folder = utils.make_tmpdir() pkg_name = 'pike_mgr_inherited_classes' pkg_location = utils.create_working_package(temp_folder, pkg_name) test_file_content = textwrap.dedent(""" class SampleObj(object): pass class OtherObj(SampleObj): pass """) mod_location = os.path.join(pkg_location, 'app.py') utils.write_file(mod_location, test_file_content) # Include module directly on the search path second_file = textwrap.dedent(""" class AnotherObj(object): pass """) mod_location = os.path.join(temp_folder, 'more.py') utils.write_file(mod_location, second_file) classes = [] with PikeManager([temp_folder]) as mgr: app = py.get_module_by_name('{}.app'.format(pkg_name)) classes = mgr.get_all_inherited_classes(app.SampleObj) assert len(classes) == 1
def setup_method(self, method): self.temp_folder = utils.make_tmpdir() self.manager = PikeManager([self.temp_folder]) self.pkg_name = 'pike_{}'.format(method.__name__) self.pkg_location = utils.create_working_package( self.temp_folder, self.pkg_name )
def setup_method(self, method): self.temp_folder = utils.make_tmpdir() # Create a simple package self.pkg_location = utils.create_working_package( self.temp_folder, 'compile_test') self.mod_location = os.path.join(self.pkg_location, 'app.py') utils.write_file(self.mod_location, SIMPLE_CLASS) py_compile.compile(self.mod_location)
def setup_method(self, method): self.temp_folder = utils.make_tmpdir() # Create a simple package pkg_location = utils.create_working_package(self.temp_folder) mod_location = os.path.join(pkg_location, 'app.py') utils.write_file(mod_location, SIMPLE_CLASS) self.finder = PikeFinder([self.temp_folder]) self.loader = PikeLoader('pike_tests.app', mod_location)
def compiled_loader(): temp_folder = utils.make_tmpdir() # Create a simple package pkg_location = utils.create_working_package(temp_folder, 'compile_test') mod_location = os.path.join(pkg_location, 'app.py') utils.write_file(mod_location, SIMPLE_CLASS) py_compile.compile(mod_location) yield temp_folder utils.remove_dir(temp_folder)
def compiled_loader(): temp_folder = utils.make_tmpdir() # Create a simple package pkg_location = utils.create_working_package(temp_folder, 'compile_test') mod_location = os.path.join(pkg_location, 'app.py') utils.write_file(mod_location, SIMPLE_CLASS) py_compile.compile(mod_location) yield temp_folder utils.remove_dir(temp_folder)
def loader_finder(): temp_folder = utils.make_tmpdir() # Create a simple package pkg_location = utils.create_working_package(temp_folder) mod_location = os.path.join(pkg_location, 'app.py') utils.write_file(mod_location, SIMPLE_CLASS) finder = PikeFinder([temp_folder]) loader = PikeLoader('pike_tests.app', mod_location) yield loader, finder utils.remove_dir(temp_folder)
def loader_finder(): temp_folder = utils.make_tmpdir() # Create a simple package pkg_location = utils.create_working_package(temp_folder) mod_location = os.path.join(pkg_location, 'app.py') utils.write_file(mod_location, SIMPLE_CLASS) finder = PikeFinder([temp_folder]) loader = PikeLoader('pike_tests.app', mod_location) yield loader, finder utils.remove_dir(temp_folder)
def test_get_child_modules(self): subpkg_location = utils.create_working_package( self.pkg_location, 'sub_mod' ) mod_location = os.path.join(subpkg_location, 'something.py') utils.write_file(mod_location) module = py.get_module_by_name(self.pkg_name) # Recursive assert len(list(py.get_child_modules(module))) == 3 # Non-Recursive assert len(list(py.get_child_modules(module, False))) == 2
def test_child_modules_with_sub_packages(self): subpkg_location = utils.create_working_package( self.pkg_location, 'submod' ) mod_location = os.path.join(self.pkg_location, 'app.py') utils.write_file(mod_location) submod_location = os.path.join(subpkg_location, 'other.py') utils.write_file(submod_location) parent_module = py.get_module_by_name(self.pkg_name) child_modules = list(py._child_modules(parent_module)) assert len(child_modules) == 2
def test_find_packages(self): utils.create_working_package(self.temp_folder) assert len(list(filesystem.find_packages(self.temp_folder))) == 1
def test_find_modules_in_empty_package(self): pkg_location = utils.create_working_package(self.temp_folder) assert len(list(filesystem.find_modules(pkg_location))) == 0
def test_find_modules(self): pkg_location = utils.create_working_package(self.temp_folder) mod_location = os.path.join(pkg_location, 'app.py') utils.write_file(mod_location) assert len(list(filesystem.find_modules(pkg_location))) == 1