Skip to content

Commit df13a98

Browse files
committed
Rename testdata.yaml to test_group.yaml
Also took the time to replace some occurrences of test{case,group,node} with test{ ,_}{case,group,node}. Verified by grepping `(?<![Cc]heck)testdata` that the phrase "testdata" no longer occurs, except in upgrade.py.
1 parent abb49f8 commit df13a98

30 files changed

+403
-361
lines changed

bin/export.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def add_testcase(in_file: Path) -> None:
213213
# substitute constants.
214214
if problem.settings.constants:
215215
constants_supported = [
216-
"data/**/testdata.yaml",
216+
"data/**/test_group.yaml",
217217
f"{InputValidator.source_dir}/**/*",
218218
f"{AnswerValidator.source_dir}/**/*",
219219
f"{OutputValidator.source_dir}/**/*",
@@ -298,7 +298,7 @@ def add_testcase(in_file: Path) -> None:
298298
ryaml_filter(limits, "time_limit")
299299
# validator_flags
300300
validator_flags = " ".join(
301-
problem.get_testdata_yaml(
301+
problem.get_test_group_yaml(
302302
problem.path / "data",
303303
OutputValidator.args_key,
304304
PrintBar("Getting validator_flags for legacy export"),
@@ -325,13 +325,6 @@ def add_testcase(in_file: Path) -> None:
325325
else:
326326
util.error(f"{f}: no name set for language {lang}.")
327327

328-
# rename output_validator dir
329-
if (export_dir / OutputValidator.source_dir).exists():
330-
(export_dir / "output_validators").mkdir(parents=True)
331-
(export_dir / OutputValidator.source_dir).rename(
332-
export_dir / "output_validators" / OutputValidator.source_dir
333-
)
334-
335328
# rename statement dirs
336329
if (export_dir / "statement").exists():
337330
(export_dir / "statement").rename(export_dir / "problem_statement")
@@ -352,6 +345,18 @@ def add_testcase(in_file: Path) -> None:
352345
add_file(out, f)
353346
shutil.rmtree(export_dir / d)
354347

348+
# rename output_validator dir
349+
if (export_dir / OutputValidator.source_dir).exists():
350+
(export_dir / "output_validators").mkdir(parents=True)
351+
(export_dir / OutputValidator.source_dir).rename(
352+
export_dir / "output_validators" / OutputValidator.source_dir
353+
)
354+
355+
# rename test_group.yaml back to testdata.yaml
356+
for f in (export_dir / "data").rglob("test_group.yaml"):
357+
f.rename(f.with_name("testdata.yaml"))
358+
# TODO potentially, some keys also need to be renamed, but we don't use this often enough for this to matter (I hope)
359+
355360
# handle yaml updates
356361
yaml_path.unlink()
357362
write_yaml(yaml_data, yaml_path)

bin/generate.py

Lines changed: 75 additions & 77 deletions
Large diffs are not rendered by default.

bin/interactive.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def get_validator_command():
5656
run.testcase.ans_path.resolve(),
5757
run.feedbackdir.resolve(),
5858
]
59-
+ run.testcase.testdata_yaml_args(
59+
+ run.testcase.test_group_yaml_args(
6060
output_validator,
6161
bar or PrintBar("Run interactive test case"),
6262
)

bin/problem.py

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,9 @@ def __init__(
283283
self.limits = ProblemLimits(parse_setting(yaml_data, "limits", {}), problem, self)
284284

285285
parse_deprecated_setting(
286-
yaml_data, "validator_flags", f"{validate.OutputValidator.args_key}' in 'testdata.yaml"
286+
yaml_data,
287+
"validator_flags",
288+
f"{validate.OutputValidator.args_key}' in 'test_group.yaml",
287289
)
288290

289291
self.keywords: list[str] = parse_optional_list_setting(yaml_data, "keywords", str)
@@ -362,9 +364,9 @@ def __init__(self, path: Path, tmpdir: Path, label: Optional[str] = None):
362364
self._programs = dict[Path, "Program"]()
363365
self._program_callbacks = dict[Path, list[Callable[["Program"], None]]]()
364366
# Dictionary from path to parsed file contents.
365-
# TODO #102: Add type for testdata.yaml (typed Namespace?)
366-
self._testdata_yamls = dict[Path, dict[str, Any]]()
367-
self._testdata_lock = threading.Lock()
367+
# TODO #102: Add type for test_group.yaml (typed Namespace?)
368+
self._test_group_yamls = dict[Path, dict[str, Any]]()
369+
self._test_group_lock = threading.Lock()
368370

369371
# The label for the problem: A, B, A1, A2, X, ...
370372
self.label = label
@@ -457,25 +459,25 @@ def _read_settings(self):
457459
self.multi_pass: bool = self.settings.multi_pass
458460
self.custom_output: bool = self.settings.custom_output
459461

460-
# TODO #102 move to TestData class
461-
def _parse_testdata_yaml(p, path, bar):
462+
# TODO #102 move to a new TestGroup class
463+
def _parse_test_group_yaml(p, path, bar):
462464
assert path.is_relative_to(p.path / "data")
463465
for dir in [path] + list(path.parents):
464466
# Do not go above the data directory.
465467
if dir == p.path:
466468
return
467469

468-
f = dir / "testdata.yaml"
469-
if not f.is_file() or f in p._testdata_yamls:
470+
f = dir / "test_group.yaml"
471+
if not f.is_file() or f in p._test_group_yamls:
470472
continue
471-
with p._testdata_lock:
472-
if f not in p._testdata_yamls:
473+
with p._test_group_lock:
474+
if f not in p._test_group_yamls:
473475
raw = substitute(
474476
f.read_text(),
475477
p.settings.constants,
476478
pattern=config.CONSTANT_SUBSTITUTE_REGEX,
477479
)
478-
p._testdata_yamls[f] = flags = parse_yaml(raw, path=f, plain=True)
480+
p._test_group_yamls[f] = flags = parse_yaml(raw, path=f, plain=True)
479481

480482
parse_deprecated_setting(
481483
flags, "output_validator_flags", validate.OutputValidator.args_key
@@ -484,7 +486,7 @@ def _parse_testdata_yaml(p, path, bar):
484486
flags, "input_validator_flags", validate.InputValidator.args_key
485487
)
486488

487-
# Verify testdata.yaml
489+
# Verify test_group.yaml
488490
for k in flags:
489491
match k:
490492
case (
@@ -524,7 +526,7 @@ def _parse_testdata_yaml(p, path, bar):
524526
| "static_validation"
525527
):
526528
bar.warn(
527-
f"{k} in testdata.yaml not implemented in BAPCtools",
529+
f"{k} in test_group.yaml not implemented in BAPCtools",
528530
print_item=False,
529531
)
530532
case _:
@@ -534,28 +536,28 @@ def _parse_testdata_yaml(p, path, bar):
534536
if dir == p.path / "data":
535537
break
536538

537-
def get_testdata_yaml(
539+
def get_test_group_yaml(
538540
p,
539541
path: Path,
540542
key: str,
541543
bar: BAR_TYPE,
542544
name: Optional[str] = None,
543545
) -> list[str]:
544546
"""
545-
Find the testdata flags applying at the given path for the given key.
546-
If necessary, walk up from `path` looking for the first testdata.yaml file that applies,
547+
Find the value of the given test_group.yaml key applying at the given path.
548+
If necessary, walk up from `path` looking for the first test_group.yaml file that applies.
547549
548550
Side effects: parses and caches the file.
549551
550552
Arguments
551553
---------
552554
path: absolute path (a file or a directory)
553-
key: The testdata.yaml key to look for (TODO: 'grading' is not yet implemented)
555+
key: The test_group.yaml key to look for (TODO: 'grading' is not yet implemented)
554556
name: If key == 'input_validator_args', optionally the name of the input validator.
555557
556558
Returns:
557559
--------
558-
A list of string arguments, which is empty if no testdata.yaml is found.
560+
A list of string arguments, which is empty if no test_group.yaml is found.
559561
TODO: when 'grading' is supported, it also can return dict
560562
"""
561563
known_args_keys = [
@@ -572,19 +574,19 @@ def get_testdata_yaml(
572574
f"Only input validators support flags by validator name, got {key} and {name}"
573575
)
574576

575-
# parse and cache testdata.yaml
576-
p._parse_testdata_yaml(path, bar)
577+
# parse and cache test_group.yaml
578+
p._parse_test_group_yaml(path, bar)
577579

578580
# extract the flags
579581
for dir in [path] + list(path.parents):
580582
# Do not go above the data directory.
581583
if dir == p.path:
582584
return []
583585

584-
f = dir / "testdata.yaml"
585-
if f not in p._testdata_yamls:
586+
f = dir / "test_group.yaml"
587+
if f not in p._test_group_yamls:
586588
continue
587-
flags = p._testdata_yamls[f]
589+
flags = p._test_group_yamls[f]
588590
if key in flags:
589591
args = flags[key]
590592
if key == validate.InputValidator.args_key:
@@ -1331,7 +1333,7 @@ def validate_valid_extra_data(p) -> bool:
13311333
if not p.validators(validate.OutputValidator, strict=True, print_warn=False):
13321334
return True
13331335

1334-
args = p.get_testdata_yaml(
1336+
args = p.get_test_group_yaml(
13351337
p.path / "data" / "valid_output",
13361338
"output_validator_args",
13371339
PrintBar("Generic Output Validation"),
@@ -1492,7 +1494,7 @@ def run_all(select_verdict, select):
14921494
return None, None, None
14931495

14941496
def get_slowest(result):
1495-
slowest_pair = result.slowest_testcase()
1497+
slowest_pair = result.slowest_test_case()
14961498
assert slowest_pair is not None
14971499
return slowest_pair
14981500

bin/run.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def _validate_output(self, bar: BAR_TYPE) -> Optional[ExecResult]:
228228
return output_validator.run(
229229
self.testcase,
230230
self,
231-
args=self.testcase.testdata_yaml_args(output_validator, bar),
231+
args=self.testcase.test_group_yaml_args(output_validator, bar),
232232
)
233233

234234
def _visualize_output(self, bar: BAR_TYPE) -> Optional[ExecResult]:
@@ -242,7 +242,7 @@ def _visualize_output(self, bar: BAR_TYPE) -> Optional[ExecResult]:
242242
self.testcase.ans_path.resolve(),
243243
self.out_path if not self.problem.interactive else None,
244244
self.feedbackdir,
245-
args=self.testcase.testdata_yaml_args(output_visualizer, bar),
245+
args=self.testcase.test_group_yaml_args(output_visualizer, bar),
246246
)
247247

248248

@@ -501,15 +501,15 @@ def process_run(run: Run):
501501
else:
502502
color = Fore.GREEN if self.verdict in self.expected_verdicts else Fore.RED
503503

504-
(salient_testcase, salient_duration) = verdicts.salient_testcase()
504+
(salient_testcase, salient_duration) = verdicts.salient_test_case()
505505
salient_print_verdict = self.verdict
506506
salient_duration_style = Style.BRIGHT if salient_duration >= self.limits["timeout"] else ""
507507

508508
# Summary line is the only thing shown.
509509
message = f"{color}{salient_print_verdict.short():>3}{salient_duration_style}{salient_duration:6.3f}s{Style.RESET_ALL} {Style.DIM}@ {salient_testcase:{max_testcase_len}}{Style.RESET_ALL}"
510510

511511
if verdicts.run_until in [RunUntil.DURATION, RunUntil.ALL]:
512-
slowest_pair = verdicts.slowest_testcase()
512+
slowest_pair = verdicts.slowest_test_case()
513513
assert slowest_pair is not None
514514
(slowest_testcase, slowest_duration) = slowest_pair
515515
slowest_verdict = verdicts[slowest_testcase]

bin/skel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def new_problem() -> None:
122122
"author": author,
123123
"type": problem_type,
124124
OutputValidator.args_key: output_validator_args,
125-
"testdata_yaml_comment": "#" if output_validator_args[0] == "#" else "",
125+
"test_group_yaml_comment": "#" if output_validator_args[0] == "#" else "",
126126
}
127127

128128
source_name = ask_variable_string(

bin/testcase.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import problem
2323

2424

25+
# TODO #102: Consistently separate the compound noun "test case", e.g. "TestCase" or "test_case"
2526
class Testcase:
2627
"""
2728
A single test case. It consists of files with matching base names, typically
@@ -59,8 +60,8 @@ class Testcase:
5960
ans_path: Path
6061
Like `hamiltonicity/data/secret/cubic/petersen.ans`.
6162
62-
testdata_yaml: dict
63-
The YAML-parsed test data flags that apply to this test case.
63+
out_path: Path
64+
Like `hamiltonicity/data/secret/cubic/petersen.out`.
6465
6566
"""
6667

@@ -115,13 +116,13 @@ def __repr__(self) -> str:
115116
def with_suffix(self, ext: str) -> Path:
116117
return self.in_path.with_suffix(ext)
117118

118-
def testdata_yaml_args(
119+
def test_group_yaml_args(
119120
self,
120121
program: "validate.AnyValidator | visualize.AnyVisualizer",
121122
bar: BAR_TYPE,
122123
) -> list[str]:
123124
"""
124-
The flags specified in testdata.yaml for the given validator applying to this testcase.
125+
The flags specified in test_group.yaml for the given validator applying to this testcase.
125126
126127
Returns
127128
-------
@@ -131,7 +132,7 @@ def testdata_yaml_args(
131132
"""
132133

133134
path = self.problem.path / "data" / self.short_path
134-
return self.problem.get_testdata_yaml(
135+
return self.problem.get_test_group_yaml(
135136
path,
136137
type(program).args_key,
137138
bar,
@@ -156,7 +157,7 @@ def validator_hashes(
156157
d = dict()
157158

158159
for validator in validators:
159-
flags = self.testdata_yaml_args(validator, bar)
160+
flags = self.test_group_yaml_args(validator, bar)
160161
flags_string = " ".join(flags)
161162
h = combine_hashes_dict(
162163
{
@@ -287,7 +288,7 @@ def _run_validators(
287288
if isinstance(validator, validate.OutputValidator) and mode == validate.Mode.ANSWER:
288289
args += ["case_sensitive", "space_change_sensitive"]
289290
name = f"{name} (ans)"
290-
flags = self.testdata_yaml_args(validator, bar)
291+
flags = self.test_group_yaml_args(validator, bar)
291292
flags = flags + args
292293

293294
ret = validator.run(self, mode=mode, constraints=constraints, args=flags)

0 commit comments

Comments
 (0)