Skip to content

Commit

Permalink
fix tests: update config.n_error on delayed parse errors
Browse files Browse the repository at this point in the history
  • Loading branch information
RagnarGrootKoerkamp committed Mar 5, 2024
1 parent 42d1a81 commit 3a77ebc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bin/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ def __init__(self, problem, generator_config, key, name: str, yaml, parent):
self.parse_error = (
f'Empty yaml key (Testcases must be generated not mentioned). Skipping.'
)
config.n_error += 1
return
else:
check_type('testcase', yaml, [str, dict])
Expand All @@ -461,6 +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
return

self.generator = GeneratorInvocation(problem, yaml['generate'])
Expand Down Expand Up @@ -511,6 +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
return
if key not in KNOWN_TESTCASE_KEYS:
if config.args.action == 'generate':
Expand All @@ -536,6 +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
return
generator_config.rules_cache[self.hash] = self.path

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

0 comments on commit 3a77ebc

Please sign in to comment.