diff --git a/bin/generate.py b/bin/generate.py index f910b49f..4af0f3f7 100644 --- a/bin/generate.py +++ b/bin/generate.py @@ -439,7 +439,7 @@ def __init__(self, problem, generator_config, key, name: str, yaml, parent): self.parse_error = ( f'Empty yaml entry (Testcases must be generated not only mentioned). Skipping.' ) - config.n_error += 1 + generator_config.n_parse_error += 1 return else: check_type('testcase', yaml, [str, dict]) @@ -462,7 +462,7 @@ def __init__(self, problem, generator_config, key, name: str, yaml, parent): check_type('generate', yaml['generate'], str) if len(yaml['generate']) == 0: self.parse_error = f'`generate` must not be empty. Skipping.' - config.n_error += 1 + generator_config.n_parse_error += 1 return self.generator = GeneratorInvocation(problem, yaml['generate']) @@ -513,7 +513,7 @@ def __init__(self, problem, generator_config, key, name: str, yaml, parent): for key in yaml: if key in RESERVED_TESTCASE_KEYS: self.parse_error = f'Testcase must not contain reserved key {key}. Skipping.' - config.n_error += 1 + generator_config.n_parse_error += 1 return if key not in KNOWN_TESTCASE_KEYS: if config.args.action == 'generate': @@ -539,7 +539,7 @@ def __init__(self, problem, generator_config, key, name: str, yaml, parent): self.parse_error = ( f'Found identical input at {generator_config.rules_cache[self.hash]}. Skipping.' ) - config.n_error += 1 + generator_config.n_parse_error += 1 return generator_config.rules_cache[self.hash] = self.path @@ -1152,6 +1152,7 @@ def __init__(self, problem, restriction=None): self.problem = problem yaml_path = self.problem.path / 'generators' / 'generators.yaml' self.ok = True + self.n_parse_error = 0 # A map of paths `secret/testgroup/testcase` to their canonical TestcaseRule. # For generated cases this is the rule itself. @@ -1674,13 +1675,13 @@ def testcases(problem, includes=False): if gen_config.ok: if includes: return { - problem.path / 'data' / x.parent / (x.name + '.in') - for x in gen_config.known_cases + problem.path / 'data' / p.parent / (p.name + '.in') + for p, x in gen_config.known_cases.items() if x.parse_error is None } else: return { (problem.path / 'data' / x.path).with_suffix('.in') - for x in gen_config.known_cases.values() + for x in gen_config.known_cases.values() if x.parse_error is None } return set() else: diff --git a/test/test_generators_yaml.py b/test/test_generators_yaml.py index 8ec8361b..d4ff3b9f 100644 --- a/test/test_generators_yaml.py +++ b/test/test_generators_yaml.py @@ -21,6 +21,8 @@ def __init__(self): class MockGeneratorConfig(generate.GeneratorConfig): def __init__(self, problem, restriction=None): self.problem = problem + self.ok = True + self.n_parse_error = 0 # A map of paths `secret/testgroup/testcase` to their canonical TestcaseRule. # For generated cases this is the rule itself. @@ -53,9 +55,8 @@ class TestGeneratorConfig: ), ) def test_bad_generators_yamls(self, yamldoc): - config.n_error = 0 - config.n_warn = 0 with pytest.raises(SystemExit) as e: - MockGeneratorConfig(MockProblem()).parse_yaml(yamldoc) - if config.n_error > 0 or config.n_warn > 0: + gen_config = MockGeneratorConfig(MockProblem()) + gen_config.parse_yaml(yamldoc) + if gen_config.n_parse_error > 0: raise SystemExit