Skip to content

Commit 4cf4b28

Browse files
committed
Add some more tests and be stricter
1 parent dd0657c commit 4cf4b28

File tree

3 files changed

+76
-2
lines changed

3 files changed

+76
-2
lines changed

tested/judge/evaluation.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,9 @@ def _add_channel(
498498
if should_show(output, channel):
499499
if isinstance(output, FileOutputChannel):
500500
for i, file in enumerate(output.files):
501-
if file.path is None:
502-
continue
501+
assert (
502+
file.path is not None
503+
), "File path must be set when using output_files"
503504

504505
updates.append(
505506
StartTest(

tested/testsuite.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,11 @@ class FileOutputChannel(WithFeatures):
316316
factory=lambda: GenericTextOracle(name=TextBuiltin.FILE)
317317
)
318318

319+
def __attrs_post_init__(self):
320+
for f in self.files:
321+
if f.path is None:
322+
raise ValueError("File path must be set when using output_files.")
323+
319324
def get_used_features(self) -> FeatureSet:
320325
return NOTHING
321326

tests/test_collector.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@
2222
from tested.serialisation import FunctionCall, FunctionType
2323
from tested.testsuite import (
2424
Context,
25+
FileOutputChannel,
2526
MainInput,
2627
Output,
2728
Suite,
2829
SupportedLanguage,
2930
Tab,
3031
Testcase,
32+
TextData,
3133
)
3234
from tests.manual_utils import assert_valid_output, configuration
3335

@@ -196,3 +198,69 @@ def test_mid_tab_is_completed(tmp_path: Path, pytestconfig: pytest.Config):
196198
"wrong",
197199
"wrong",
198200
]
201+
202+
203+
FILE_OUTPUT_SUITE = Suite(
204+
tabs=[
205+
Tab(
206+
name="Tab 1",
207+
contexts=[
208+
Context(
209+
testcases=[
210+
Testcase(
211+
input=MainInput(arguments=["hello 1"]),
212+
output=Output(
213+
file=FileOutputChannel(
214+
files=[
215+
TextData(path="out1.txt", content="expected1"),
216+
TextData(path="out2.txt", content="expected2"),
217+
]
218+
)
219+
),
220+
),
221+
]
222+
),
223+
],
224+
),
225+
]
226+
)
227+
228+
229+
def test_complete_evaluation_with_file_output(
230+
tmp_path: Path, pytestconfig: pytest.Config
231+
):
232+
"""Test that complete_evaluation emits per-file NOT_EXECUTED tests."""
233+
conf = configuration(pytestconfig, "", SupportedLanguage.JAVASCRIPT, tmp_path)
234+
result = StringIO()
235+
bundle = create_bundle(conf, result, FILE_OUTPUT_SUITE)
236+
collector = OutputManager(out=result)
237+
238+
# Open judgement but don't execute anything.
239+
collector.add(StartJudgement())
240+
241+
terminate(bundle, collector, status_if_unclosed=Status.RUNTIME_ERROR)
242+
243+
updates = assert_valid_output(result.getvalue(), pytestconfig)
244+
245+
# Each file should produce its own NOT_EXECUTED test.
246+
start_tests = updates.find_all("start-test")
247+
assert len(start_tests) == 2
248+
assert start_tests[0]["channel"] == "out1.txt"
249+
assert start_tests[1]["channel"] == "out2.txt"
250+
251+
assert updates.find_status_enum() == [
252+
"runtime error",
253+
"wrong",
254+
"wrong",
255+
]
256+
257+
258+
def test_file_output_channel_rejects_none_path():
259+
"""Test that FileOutputChannel rejects files with path=None."""
260+
with pytest.raises(ValueError, match="File path must be set"):
261+
FileOutputChannel(
262+
files=[
263+
TextData(path=None, content="expected1"),
264+
TextData(path="out2.txt", content="expected2"),
265+
]
266+
)

0 commit comments

Comments
 (0)