Skip to content

Commit

Permalink
fix: allow testcase.root to be 'test' for pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
thorehusfeldt committed Feb 1, 2024
1 parent c3caeec commit 9c1f7c3
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions bin/testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from util import fatal, is_relative_to, combine_hashes_dict, shorten_path, print_name, warn, error
from colorama import Fore, Style
from problem import Problem
import validate
import config

Expand All @@ -18,10 +17,10 @@ class Testcase:
# tested, and `short_path` is the name of the testcase relative to
# `problem.path / 'data'`.
"""
def __init__(self, problem: Problem, path: Path, *, short_path=None):
def __init__(self, base_problem, path: Path, *, short_path=None):
assert path.suffix == '.in' or path.suffixes == [".in", ".statement"]

self.problem = problem
self.problem = base_problem

self.in_path = path
self.ans_path = (
Expand All @@ -32,9 +31,9 @@ def __init__(self, problem: Problem, path: Path, *, short_path=None):
# TODO add self.out_path
if short_path is None:
try:
self.short_path = path.relative_to(problem.path / 'data')
self.short_path = path.relative_to(self.problem.path / 'data')
except ValueError:
fatal(f"Testcase {path} is not inside {problem.path / 'data'}.")
fatal(f"Testcase {path} is not inside {self.problem.path / 'data'}.")
else:
assert short_path is not None
self.short_path = short_path
Expand All @@ -48,13 +47,13 @@ def __init__(self, problem: Problem, path: Path, *, short_path=None):
if self.root == 'bad':
warn('data/bad is deprecated. Use data/{invalid_inputs,invalid_answers} instead.')
self.root = 'invalid_inputs' if self.ans_path.is_file() else 'invalid_answers'
assert self.root in ['invalid_inputs', 'invalid_answers', 'secret', 'sample'] # TODO add invalid_outputs
assert self.root in ['invalid_inputs', 'invalid_answers', 'secret', 'sample', 'test'], self.root # TODO add invalid_outputs


self.included = False
if path.is_symlink():
include_target = Path(os.path.normpath(path.parent / os.readlink(path)))
if is_relative_to(problem.path / 'data', include_target):
if is_relative_to(self.problem.path / 'data', include_target):
self.included = True
else:
# The case is an unlisted cases included from generators/.
Expand All @@ -64,7 +63,7 @@ def __init__(self, problem: 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 = problem.get_testdata_yaml(self.problem.path / 'data' / self.short_path)
self.testdata_yaml = self.problem.get_testdata_yaml(self.problem.path / 'data' / self.short_path)

def with_suffix(self, ext):
return self.in_path.with_suffix(ext)
Expand Down

0 comments on commit 9c1f7c3

Please sign in to comment.