Beispiel #1
0
def genetic_prune(conf, entity='All'):
    """Check all saved genetic_tester tests for an entity, prune failures"""
    if entity == 'All':
        for target in list(entity_tester.EntityTester.pull_entities()):
            genetic_prune(conf, target)
    else:
        test_file = Path('data/genetic_tests/{}.yaml'.format(entity))
        logger.debug('Current target file: {}'.format(test_file))
        to_remove = []
        if test_file.exists() and test_file.stat().st_size > 10:
            logger.debug('Beginning tests for {}'.format(entity))
            tests = yaml.load(test_file.open('r'))
            for test in tests:
                ent, method, mode = test.split(' ')
                if mode == 'positive':
                    logger.debug('Running test {}'.format(method))
                    result = genetic_tester.GeneticEntityTester(
                        conf, entity, method).run_best()
                    if result == -1:
                        logger.debug('{} failed.'.format(test))
                        to_remove.append(test)
                    else:
                        logger.debug('{} passed.'.format(test))
            for test in to_remove:
                logger.warning('Removing {} from {}'.format(test, test_file))
                del tests[test]
            logger.debug('Deleting file {}'.format(test_file))
            test_file.unlink()
            logger.debug('Writing tests to {}'.format(test_file))
            yaml.dump(tests, test_file.open('w+'), default_flow_style=False)
            logger.info('Done pruning {}'.format(entity))
        if test_file.exists() and test_file.stat().st_size < 10:
            logger.warning('Deleting empty file {}'.format(test_file))
            test_file.unlink()
Beispiel #2
0
def test_positive_mock_run():
    """Run a mock series of genetic algorithm-based tests"""
    gen_test = genetic_tester.GeneticEntityTester(CONF,
                                                  'Organization',
                                                  'create',
                                                  max_generations=10)
    gen_test.run(mock=True)
Beispiel #3
0
def test_positive_config_overrides():
    """Check that the post init overrides config values"""
    gen_test = genetic_tester.GeneticEntityTester(
        CONF,
        'Organization',
        'create',
        max_recursive_generations=1337,
        disable_recursion=True,
        max_recursive_depth=1337)
    assert gen_test.config.RIZZA['GENETICS'][
        'MAX RECURSIVE GENERATIONS'] == 1337
    assert not gen_test.config.RIZZA['GENETICS']['ALLOW RECURSION']
    assert gen_test.config.RIZZA['GENETICS']['MAX RECURSIVE DEPTH'] == 1337
Beispiel #4
0
def test_positive_create():
    """Init the class and check the defaults match the config"""
    gen_test = genetic_tester.GeneticEntityTester(CONF, 'Organization',
                                                  'create')
    assert gen_test.config
    assert gen_test.entity == 'Organization'
    assert gen_test.method == 'create'
    assert not gen_test.fresh
    assert not gen_test.seek_bad
    assert gen_test.max_generations == gen_test.config.RIZZA['GENETICS'][
        'MAX GENERATIONS']
    assert gen_test.population_count == gen_test.config.RIZZA['GENETICS'][
        'POPULATION COUNT']
    assert gen_test.test_name == 'Organization create positive'
Beispiel #5
0
                disable_dependencies=args.disable_dependencies,
                disable_recursion=args.disable_recursion,
                seek_bad=args.seek_bad,
                fresh=args.fresh,
                max_running=args.async_limit)
            self.conf.init_logger(path=self.conf.base_dir.joinpath(
                'logs/genetic/{}.log'.format(gtester.test_name)),
                                  level='debug' if args.debug else None)
            gtester.run()
        else:
            gtester = genetic_tester.GeneticEntityTester(
                config=self.conf,
                entity=args.entity,
                method=args.method,
                population_count=args.population_count,
                max_generations=args.max_generations,
                max_recursive_generations=args.max_recursive_generations,
                max_recursive_depth=args.max_recursive_depth,
                disable_dependencies=args.disable_dependencies,
                disable_recursion=args.disable_recursion,
                seek_bad=args.seek_bad,
                fresh=args.fresh)
            self.conf.init_logger(path=self.conf.base_dir.joinpath(
                'logs/genetic/{}.log'.format(gtester.test_name)),
                                  level='debug' if args.debug else None)
            gtester.run()

    def config(self):
        parser = argparse.ArgumentParser()
        subparsers = parser.add_subparsers(
            dest="project",
            help="The component's config you want to change or view.")
Beispiel #6
0
def test_positive_mock_judge():
    """Make sure that the mock judge function return an integer"""
    gen_test = genetic_tester.GeneticEntityTester(CONF, 'Organization',
                                                  'create')
    assert isinstance(gen_test._judge(mock=True), int)
Beispiel #7
0
def test_positive_judge():
    """Make sure that the judge function returns a correct result"""
    gen_test = genetic_tester.GeneticEntityTester(CONF, 'Organization',
                                                  'create')
    for criteria, points in CONF.RIZZA['GENETICS']['CRITERIA'].items():
        assert gen_test._judge(result=criteria) == points