def validate(self): """Collect and validate all new features""" changes = self.change_collector.collect_changes() features = [] imported_okay = True for importer, modname, modpath in changes.new_feature_info: try: mod = importer() features.extend(_collect_contrib_features(mod)) except (ImportError, SyntaxError): logger.info(f'Failed to import module at {modpath}') logger.exception('Exception details: ') imported_okay = False if not imported_okay: return False # if no features were added at all, reject if not features: logger.info('Failed to collect any new features.') return False return all( validate_feature_api(feature, self.X_df, self.y, False) for feature in features )
def mock_contrib_module(self, modname, content, n): with tempfile.TemporaryDirectory() as tmpdir: modpath = pathlib.Path(tmpdir).joinpath(modname) modpath.mkdir() create_contrib_modules_at_dir(modpath, content, n=n) mod = import_module_at_path(modname, modpath) features = _collect_contrib_features(mod) yield mod, features
def test_collect_contrib_features_stdlib(self): # give a nonsense *module*, shouldn't import anything. this is a bad # test because it relies on module not defining certain names import math features = _collect_contrib_features(math) # features should be an empty list self.assertEqual(len(features), 0)
def test_collect_contrib_features_thirdparty(self): # give a nonsense *package*, shouldn't import anything. this is a bad # test because it relies on module not defining certain names import funcy features = _collect_contrib_features(funcy) self.assertEqual(len(features), 0)