From 3a77ebc0c58d37264dbb42b9481f525863fe4b9f Mon Sep 17 00:00:00 2001 From: Ragnar Groot Koerkamp Date: Tue, 5 Mar 2024 21:18:45 +0100 Subject: [PATCH] fix tests: update config.n_error on delayed parse errors --- bin/generate.py | 4 ++++ test/test_generators_yaml.py | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/bin/generate.py b/bin/generate.py index df3a39b6..32993ffd 100644 --- a/bin/generate.py +++ b/bin/generate.py @@ -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]) @@ -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']) @@ -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': @@ -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 diff --git a/test/test_generators_yaml.py b/test/test_generators_yaml.py index 97ff0522..8ec8361b 100644 --- a/test/test_generators_yaml.py +++ b/test/test_generators_yaml.py @@ -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