Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
mzuenni committed Mar 6, 2024
1 parent 5c08363 commit e2baf4e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
15 changes: 8 additions & 7 deletions bin/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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'])
Expand Down Expand Up @@ -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':
Expand All @@ -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

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 5 additions & 4 deletions test/test_generators_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

0 comments on commit e2baf4e

Please sign in to comment.