Skip to content

Commit

Permalink
Fixed buildin oracle tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BrentBlanckaert committed Feb 1, 2025
1 parent e01ebdc commit 2ce7892
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
6 changes: 4 additions & 2 deletions tested/oracles/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,12 @@ def evaluate_file(
strip_newlines = options.get("stripNewlines", False)
expected_lines = expected_value.splitlines(keepends=not strip_newlines)
actual_lines = actual_value.splitlines(keepends=not strip_newlines)
correct = len(actual_lines) == len(expected_lines)
result = len(actual_lines) == len(expected_lines)
for expected_line, actual_line in zip(expected_lines, actual_lines):
print(f"{expected_line}: {actual_line}")
new_result, _ = _text_comparison(options, expected_line, actual_line)
correct = correct and new_result
print(f"{new_result}")
result = result and new_result

return OracleResult(
result=StatusMessage(enum=Status.CORRECT if result else Status.WRONG),
Expand Down
26 changes: 13 additions & 13 deletions tests/test_oracles_builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
Suite,
SupportedLanguage,
TextOutputChannel,
ValueOutputChannel,
ValueOutputChannel, TextChannelType,
)
from tests.manual_utils import configuration

Expand Down Expand Up @@ -140,15 +140,15 @@ def test_file_oracle_full_wrong(
tmp_path: Path, pytestconfig: pytest.Config, mocker: MockerFixture
):
config = oracle_config(tmp_path, pytestconfig, {"mode": "full"})
s = mocker.spy(tested.oracles.text, name="compare_text") # type: ignore[reportAttributeAccessIssue]
s = mocker.spy(tested.oracles.text, name="_text_comparison") # type: ignore[reportAttributeAccessIssue]
mock_files = [
mocker.mock_open(read_data=content).return_value
for content in ["expected\nexpected", "actual\nactual"]
]
mock_opener = mocker.mock_open()
mock_opener.side_effect = mock_files
mocker.patch("builtins.open", mock_opener)
channel = FileOutputChannel(content="expected.txt", path="expected.txt")
channel = FileOutputChannel(content=["expected.txt"], path=["expected.txt"], content_type=[TextChannelType.FILE])
result = evaluate_file(config, channel, "")
s.assert_called_once_with(ANY, "expected\nexpected", "actual\nactual")
assert result.result.enum == Status.WRONG
Expand All @@ -160,15 +160,15 @@ def test_file_oracle_full_correct(
tmp_path: Path, pytestconfig: pytest.Config, mocker: MockerFixture
):
config = oracle_config(tmp_path, pytestconfig, {"mode": "full"})
s = mocker.spy(tested.oracles.text, name="compare_text") # type: ignore[reportAttributeAccessIssue]
s = mocker.spy(tested.oracles.text, name="_text_comparison") # type: ignore[reportAttributeAccessIssue]
mock_files = [
mocker.mock_open(read_data=content).return_value
for content in ["expected\nexpected", "expected\nexpected"]
]
mock_opener = mocker.mock_open()
mock_opener.side_effect = mock_files
mocker.patch("builtins.open", mock_opener)
channel = FileOutputChannel(content="expected.txt", path="expected.txt")
channel = FileOutputChannel(content=["expected.txt"], path=["expected.txt"], content_type=[TextChannelType.FILE])
result = evaluate_file(config, channel, "")
s.assert_called_once_with(ANY, "expected\nexpected", "expected\nexpected")
assert result.result.enum == Status.CORRECT
Expand All @@ -182,15 +182,15 @@ def test_file_oracle_line_wrong(
config = oracle_config(
tmp_path, pytestconfig, {"mode": "line", "stripNewlines": True}
)
s = mocker.spy(tested.oracles.text, name="compare_text") # type: ignore[reportAttributeAccessIssue]
s = mocker.spy(tested.oracles.text, name="_text_comparison") # type: ignore[reportAttributeAccessIssue]
mock_files = [
mocker.mock_open(read_data=content).return_value
for content in ["expected\nexpected2", "actual\nactual2"]
]
mock_opener = mocker.mock_open()
mock_opener.side_effect = mock_files
mocker.patch("builtins.open", mock_opener)
channel = FileOutputChannel(content="expected.txt", path="expected.txt")
channel = FileOutputChannel(content=["expected.txt"], path=["expected.txt"], content_type=[TextChannelType.FILE])
result = evaluate_file(config, channel, "")
s.assert_any_call(ANY, "expected", "actual")
s.assert_any_call(ANY, "expected2", "actual2")
Expand All @@ -206,15 +206,15 @@ def test_file_oracle_line_correct(
config = oracle_config(
tmp_path, pytestconfig, {"mode": "line", "stripNewlines": True}
)
s = mocker.spy(tested.oracles.text, name="compare_text") # type: ignore[reportAttributeAccessIssue]
s = mocker.spy(tested.oracles.text, name="_text_comparison") # type: ignore[reportAttributeAccessIssue]
mock_files = [
mocker.mock_open(read_data=content).return_value
for content in ["expected\nexpected2", "expected\nexpected2"]
]
mock_opener = mocker.mock_open()
mock_opener.side_effect = mock_files
mocker.patch("builtins.open", mock_opener)
channel = FileOutputChannel(content="expected.txt", path="expected.txt")
channel = FileOutputChannel(content=["expected.txt"], path=["expected.txt"], content_type=[TextChannelType.FILE])
result = evaluate_file(config, channel, "")
s.assert_any_call(ANY, "expected", "expected")
s.assert_any_call(ANY, "expected2", "expected2")
Expand All @@ -230,15 +230,15 @@ def test_file_oracle_strip_lines_correct(
config = oracle_config(
tmp_path, pytestconfig, {"mode": "line", "stripNewlines": True}
)
s = mocker.spy(tested.oracles.text, name="compare_text") # type: ignore[reportAttributeAccessIssue]
s = mocker.spy(tested.oracles.text, name="_text_comparison") # type: ignore[reportAttributeAccessIssue]
mock_files = [
mocker.mock_open(read_data=content).return_value
for content in ["expected\nexpected2\n", "expected\nexpected2"]
]
mock_opener = mocker.mock_open()
mock_opener.side_effect = mock_files
mocker.patch("builtins.open", mock_opener)
channel = FileOutputChannel(content="expected.txt", path="expected.txt")
channel = FileOutputChannel(content=["expected.txt"], path=["expected.txt"], content_type=[TextChannelType.FILE])
result = evaluate_file(config, channel, "")
s.assert_any_call(ANY, "expected", "expected")
s.assert_any_call(ANY, "expected2", "expected2")
Expand All @@ -254,15 +254,15 @@ def test_file_oracle_dont_strip_lines_correct(
config = oracle_config(
tmp_path, pytestconfig, {"mode": "line", "stripNewlines": False}
)
s = mocker.spy(tested.oracles.text, name="compare_text") # type: ignore[reportAttributeAccessIssue]
s = mocker.spy(tested.oracles.text, name="_text_comparison") # type: ignore[reportAttributeAccessIssue]
mock_files = [
mocker.mock_open(read_data=content).return_value
for content in ["expected\nexpected2\n", "expected\nexpected2\n"]
]
mock_opener = mocker.mock_open()
mock_opener.side_effect = mock_files
mocker.patch("builtins.open", mock_opener)
channel = FileOutputChannel(content="expected.txt", path="expected.txt")
channel = FileOutputChannel(content=["expected.txt"], path=["expected.txt"], content_type=[TextChannelType.FILE])
result = evaluate_file(config, channel, "")
s.assert_any_call(ANY, "expected\n", "expected\n")
s.assert_any_call(ANY, "expected2\n", "expected2\n")
Expand Down

0 comments on commit 2ce7892

Please sign in to comment.