Exemplo n.º 1
0
class ProjectStructureValidator(BaseValidator):
    def __init__(self, project):
        self.change_collector = ChangeCollector(project)

    def validate(self):
        changes = self.change_collector.collect_changes()
        return not changes.inadmissible_diffs
Exemplo n.º 2
0
class FeatureApiValidator(BaseValidator):
    def __init__(self, project):
        self.change_collector = ChangeCollector(project)

        X, y = project.load_data()
        self.X, self.y = subsample_data_for_validation(X, y)

    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('Failed to import module at {}'.format(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, self.y, subsample=False)
            for feature in features)
Exemplo n.º 3
0
def test_change_collector_collect_changes(quickstart):
    repo = quickstart.repo
    contrib_path = quickstart.project.config.get('contrib.module_path')

    path_content = [
        ('something.txt', None),  # invalid
        ('invalid.py', None),  # invalid
        (f'{contrib_path}/foo/bar/baz.py', None),  # invalid

        # candidate_feature, and also new_feature_info
        (f'{contrib_path}/user_foo/feature_bar.py', None),
        (f'{contrib_path}/user_foo/__init__.py', None),  # valid_init
    ]

    old_head = repo.head.commit

    for path, content in path_content:
        make_mock_commit(repo, path=path, content=content)

    new_head = repo.head.commit

    differ = CustomDiffer(endpoints=(old_head, new_head))
    change_collector = ChangeCollector(quickstart.project, differ=differ)
    changes = change_collector.collect_changes()

    assert len(changes.file_diffs) == 5
    assert len(changes.candidate_feature_diffs) == 1
    assert len(changes.valid_init_diffs) == 1
    assert len(changes.inadmissible_diffs) == 3
    assert len(changes.new_feature_info) == 1

    actual_inadmissible = [diff.b_path for diff in changes.inadmissible_diffs]
    expected_inadmissible = [
        'something.txt', 'invalid.py', f'{contrib_path}/foo/bar/baz.py'
    ]
    assert set(actual_inadmissible) == set(expected_inadmissible)