def search_old(module: Optional[Module] = None, **kwds: Any) -> dict: """Search for algorithms, that pass given filters. Args: module: Module instance, which is used to recursively search in submodules for algorithms. Default: Use the module of the caller of this function. **kwds: Attributes, which are testet by using the filter rules Returns: Dictionary with function information. """ # Set default value of 'module' to module of caller module = module or stack.get_caller_module() # Create filter rules for attributes rules = { 'tags': lambda a, b: set(a) <= set(b), # requires all 'classes': lambda a, b: bool(set(a) & set(b)) } # requires any # Search for algorithms return pkg.search(module=module, rules=rules, **kwds)
# if __name__ == "__main__": argv = sys.argv[1:] module = argv[0] if argv else None # Import package and tests path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) sys.path.insert(0, path) package = importlib.import_module(package_name) tests = importlib.import_module('tests') # Search and filter TestCases within tests loader = unittest.TestLoader() suite = unittest.TestSuite() cases = pkg.search( module=tests, classinfo=unittest.TestCase, val='reference', errors=True) for ref in cases.values(): if module: if not hasattr(ref, 'module'): continue if not hasattr(ref.module, '__name__'): continue if not fnmatch.fnmatch(ref.module.__name__, f'*{module}*'): continue suite.addTests(loader.loadTestsFromTestCase(ref)) # Initialize TestRunner and run TestCases package_version = getattr(package, '__version__', '') ui.info(f"testing {package_name} {package_version}") cur_level = ui.get_notification_level() ui.set_notification_level('CRITICAL')
def test_search(self) -> None: count = len(pkg.search(module=pkg, name='search')) self.assertEqual(count, 1)