Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MasloMaslane committed Sep 24, 2023
1 parent f475320 commit 88bc597
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 51 deletions.
53 changes: 46 additions & 7 deletions tests/commands/run/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ def test_print_expected_scores_diff(capsys, create_package):
new_expected_scores={
"abc.cpp": {1: {"status": "OK", "points": 100}, 2: {"status": "OK", "points": 100},
3: {"status": "OK", "points": 100}, 4: {"status": "OK", "points": 100}},
}
},
unknown_change=False,
)
command.print_expected_scores_diff(results)
out = capsys.readouterr().out
Expand All @@ -201,7 +202,8 @@ def test_print_expected_scores_diff(capsys, create_package):
new_expected_scores={
"abc.cpp": {1: {"status": "WA", "points": 0}, 2: {"status": "OK", "points": 100},
3: {"status": "OK", "points": 100}, 4: {"status": "OK", "points": 100}},
}
},
unknown_change=False,
)
with pytest.raises(SystemExit) as e:
command.print_expected_scores_diff(results)
Expand All @@ -226,7 +228,8 @@ def test_print_expected_scores_diff(capsys, create_package):
3: {"status": "OK", "points": 100}, 4: {"status": "OK", "points": 100}},
"abc5.cpp": {1: {"status": "OK", "points": 100}, 2: {"status": "OK", "points": 100},
3: {"status": "OK", "points": 100}, 4: {"status": "OK", "points": 100}},
}
},
unknown_change=False,
)
with pytest.raises(SystemExit) as e:
command.print_expected_scores_diff(results)
Expand All @@ -251,7 +254,8 @@ def test_print_expected_scores_diff(capsys, create_package):
new_expected_scores={
"abc.cpp": {1: {"status": "OK", "points": 100}, 2: {"status": "OK", "points": 100},
3: {"status": "OK", "points": 100}, 4: {"status": "OK", "points": 100}},
}
},
unknown_change=False,
)
with pytest.raises(SystemExit) as e:
command.print_expected_scores_diff(results)
Expand All @@ -275,7 +279,8 @@ def test_print_expected_scores_diff(capsys, create_package):
"abc.cpp": {1: {"status": "OK", "points": 100}, 2: {"status": "OK", "points": 100},
3: {"status": "OK", "points": 100}, 4: {"status": "OK", "points": 100},
5: {"status": "OK", "points": 100}},
}
},
unknown_change=False,
)
with pytest.raises(SystemExit) as e:
command.print_expected_scores_diff(results)
Expand All @@ -299,7 +304,8 @@ def test_print_expected_scores_diff(capsys, create_package):
new_expected_scores={
"abc.cpp": {1: {"status": "OK", "points": 100}, 2: {"status": "OK", "points": 100},
3: {"status": "OK", "points": 100}, 4: {"status": "OK", "points": 100}},
}
},
unknown_change=False,
)
with pytest.raises(SystemExit) as e:
command.print_expected_scores_diff(results)
Expand Down Expand Up @@ -341,7 +347,8 @@ def test_print_expected_scores_diff(capsys, create_package):
3: {"status": "OK", "points": 25}, 5: {"status": "OK", "points": 0}},
"points": 75
}
}
},
unknown_change=False,
)
command.print_expected_scores_diff(results)
out = capsys.readouterr().out
Expand Down Expand Up @@ -382,6 +389,38 @@ def test_print_expected_scores_diff(capsys, create_package):
}
}

# Test with `unknown_changes = True`
command.args = argparse.Namespace(apply_suggestions=False)
results = ValidationResult(
added_solutions=set(),
removed_solutions=set(),
added_groups=set(),
removed_groups=set(),
changes=[],
expected_scores={
"abc.cpp": {
"expected": {1: {"status": "OK", "points": 25}, 2: {"status": "OK", "points": 25},
3: {"status": "OK", "points": 25}, 4: {"status": "OK", "points": 25}},
"points": 100
},
},
new_expected_scores={
"abc.cpp": {
"expected": {1: {"status": "OK", "points": 25}, 2: {"status": "OK", "points": 25},
3: {"status": "OK", "points": 25}, 4: {"status": "OK", "points": 25}},
"points": 100
},
},
unknown_change=True,
)
with pytest.raises(SystemExit) as e:
command.print_expected_scores_diff(results)
out = capsys.readouterr().out
assert e.type == SystemExit
assert e.value.code == 1
assert "There was an unknown change in expected scores." in out



@pytest.mark.parametrize("create_package", [get_simple_package_path()], indirect=True)
def test_set_scores(create_package):
Expand Down
14 changes: 14 additions & 0 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import resource
import requests_mock
import pytest
import yaml

from sinol_make import util, configure_parsers
from tests import util as test_util
Expand Down Expand Up @@ -95,3 +96,16 @@ def test_check_version(**kwargs):
mocker.get("https://pypi.python.org/pypi/sinol-make/json", exc=requests.exceptions.ConnectTimeout)
util.check_version()
assert not version_file.is_file()


@pytest.mark.parametrize("create_package", [test_util.get_simple_package_path()], indirect=True)
def test_version_change(create_package):
with open("config.yml", "r") as config_file:
config = yaml.load(config_file, Loader=yaml.FullLoader)
old_expected_scores = config["sinol_expected_scores"]
config["sinol_expected_scores"] = {'abc.cpp': {'points': 100, 'expected': {1: 'OK', 2: 'OK', 3: 'OK', 4: 'OK'}},
'abc1.cpp': {'points': 75, 'expected': {1: 'OK', 2: 'OK', 3: 'OK', 4: 'WA'}},
'abc2.cpp': {'points': 25, 'expected': {1: 'OK', 2: 'WA', 3: 'WA', 4: 'TL'}},
'abc3.cpp': {'points': 25, 'expected': {1: 'OK', 2: 'WA', 3: 'WA', 4: 'ML'}},
'abc4.cpp': {'points': 50, 'expected': {1: 'OK', 2: 'OK', 3: 'WA', 4: 'RE'}}}
assert old_expected_scores == util.try_fix_config(config)["sinol_expected_scores"]
Empty file removed tests/version_changes/__init__.py
Empty file.
35 changes: 0 additions & 35 deletions tests/version_changes/test_expected_scores_format_change.py

This file was deleted.

9 changes: 0 additions & 9 deletions tests/version_changes/util.py

This file was deleted.

0 comments on commit 88bc597

Please sign in to comment.