diff --git a/bin/problem.py b/bin/problem.py index 27aad5db..50699ee1 100644 --- a/bin/problem.py +++ b/bin/problem.py @@ -194,7 +194,9 @@ def get_testdata_yaml(p, path, key, name=None) -> str | None: if key == 'grading': raise NotImplementedError(key) if key != 'input_validator_flags' and name is not None: - raise ValueError(f"Only input validators support flags by validator name, got {key} and {name}") + raise ValueError( + f"Only input validators support flags by validator name, got {key} and {name}" + ) for dir in [path] + list(path.parents): f = dir / 'testdata.yaml' @@ -211,21 +213,23 @@ def get_testdata_yaml(p, path, key, name=None) -> str | None: if isinstance(flags[key], str): continue for name in flags[key]: - input_validator_names = list(val.name for val in p.validators(validate.InputValidator)) + input_validator_names = list( + val.name for val in p.validators(validate.InputValidator) + ) if not name in input_validator_names: - warn(f'Unknown input validator {name}; expected {input_validator_names}') + warn( + f'Unknown input validator {name}; expected {input_validator_names}' + ) case 'grading' | 'run_samples': warn(f'{key} not implemented in BAPCtools') case _: warn(f'Unknown testdata.yaml key: {key}') - - # Store testdata.yaml files in a cache. if f not in p._testdata_yamls: p._testdata_yamls[f] = read_yaml(f, plain=True) - #flags = p._testdata_yamls[f] + # flags = p._testdata_yamls[f] if key in flags: if isinstance(flags[key], str): return flags[key] diff --git a/bin/testcase.py b/bin/testcase.py index 84a193af..5cfbef2b 100644 --- a/bin/testcase.py +++ b/bin/testcase.py @@ -116,9 +116,10 @@ def __init__(self, base_problem, path: Path, *, short_path=None): # Read using the short_path instead of the in_path, because during # generate the testcase will live in a temporary directory, where # testdata.yaml doesn't exist. - self.testdata_yaml = self.problem.get_testdata_yaml( - self.problem.path / 'data' / self.short_path - ) + + # self.testdata_yaml = self.problem.get_testdata_yaml( TODO Thore + # self.problem.path / 'data' / self.short_path + # ) def __repr__(self): return self.name @@ -128,7 +129,7 @@ def with_suffix(self, ext): def testdata_yaml_validator_flags(self, validator) -> list[str] | None | Literal[False]: """ - The flags specified in testdata.yaml for the given validator, + The flags specified in testdata.yaml for the given validator applying to this testcase. Arguments --------- @@ -150,19 +151,20 @@ def testdata_yaml_validator_flags(self, validator) -> list[str] | None | Literal if self.problem.settings.validation == 'default' and isinstance(validator, OutputValidator): return None - if self.testdata_yaml is None: - return None - key = ( - 'input_validator_flags' - if isinstance(validator, InputValidator) - else 'output_validator_flags' - ) - if key not in self.testdata_yaml: - return None - flags = self.testdata_yaml[key] + if isinstance(validator, InputValidator): + key = 'input_validator_flags' + name = validator.name + else: + key = 'output_validator_flags' + name = None + + path = self.problem.path / 'data' / self.short_path + flags = self.problem.get_testdata_yaml(path, key, name=name) # Note: support for lists/dicts for was removed in #259. + if flags is None: + return None if not isinstance(flags, str): - fatal(f'{key} must be a string in testdata.yaml') + fatal(f'{key} must be a string in testdata.yaml, got {flags}') return flags.split() def validator_hashes(self, cls: Type[Validator]):