class SuiteScanner(object): def __init__(self, search_path): super(SuiteScanner, self).__init__() self.search_path = path.abspath(search_path) self.plugin_manager = PikeManager([self.search_path]) def filter_by_module_name(self, classes, name): found = [ cls for cls in classes if name in '{}.{}'.format(cls.__module__, cls.__name__) ] # Only search children if the class cannot be found at the package lvl if not found: children = [cls.__get_all_child_describes__() for cls in classes] children = chain.from_iterable(children) found = [ cls for cls in children if name in '{}.{}'.format(cls.__module__, cls.__name__) ] return found def scan(self, module_name=None): if not path.exists(path.join(self.search_path)): return [] classes = self.plugin_manager.get_classes(Describe.plugin_filter) if module_name: classes = self.filter_by_module_name(classes, module_name) return classes def destroy(self): self.plugin_manager.cleanup()
class SuiteScanner(object): def __init__(self, search_path): super(SuiteScanner, self).__init__() self.search_path = path.abspath(search_path) self.plugin_manager = PikeManager([self.search_path]) def filter_by_module_name(self, classes, name): found = [cls for cls in classes if name in '{}.{}'.format(cls.__module__, cls.__name__)] # Only search children if the class cannot be found at the package lvl if not found: children = [cls.__get_all_child_describes__() for cls in classes] children = chain.from_iterable(children) found = [cls for cls in children if name in '{}.{}'.format(cls.__module__, cls.__name__)] return found def scan(self, module_name=None): if not path.exists(path.join(self.search_path)): return [] classes = self.plugin_manager.get_classes(Describe.plugin_filter) if module_name: classes = self.filter_by_module_name(classes, module_name) return classes def destroy(self): self.plugin_manager.cleanup()
def test_double_cleanup_shouldnt_fail(): """Making sure multiple cleanups don't cause problems This case happens when Python's GC calls the destructor on the manager """ mgr = PikeManager(['./']) mgr.cleanup() mgr.cleanup() assert mgr.module_finder not in sys.meta_path
class BaseTestCase(object): 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 teardown_method(self, method): self.manager.cleanup() utils.remove_dir(self.temp_folder)
def test_manager_with_normal_instantiation(): mgr = PikeManager(['./']) assert mgr.module_finder in sys.meta_path mgr.cleanup() assert mgr.module_finder not in sys.meta_path