예제 #1
0
파일: validator.py 프로젝트: ballet/ballet
    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
        )
예제 #2
0
 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
예제 #3
0
    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)
예제 #4
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)