|
| 1 | +import copy |
| 2 | +import sys |
1 | 3 | import pytest
|
2 | 4 |
|
3 | 5 | from ...fixtures import *
|
@@ -139,6 +141,66 @@ def test_flag_tests(create_package, time_tool):
|
139 | 141 | assert command.tests == [test]
|
140 | 142 |
|
141 | 143 |
|
| 144 | +@pytest.mark.parametrize("create_package", [get_checker_package_path()], indirect=True) |
| 145 | +def test_groups_in_flag_test(capsys, create_package, time_tool): |
| 146 | + """ |
| 147 | + Test flag --tests with whole and partial groups. |
| 148 | + """ |
| 149 | + package_path = create_package |
| 150 | + create_ins_outs(package_path) |
| 151 | + |
| 152 | + parser = configure_parsers() |
| 153 | + |
| 154 | + # Test with only one test from group 1. |
| 155 | + args = parser.parse_args(["run", "--tests", "in/chk1a.in", "--time-tool", time_tool]) |
| 156 | + command = Command() |
| 157 | + command.run(args) |
| 158 | + out = capsys.readouterr().out |
| 159 | + assert "Showing expected scores only for groups with all tests run." in out |
| 160 | + assert "sinol_expected_scores: {}" in out |
| 161 | + assert "Expected scores are correct!" in out |
| 162 | + |
| 163 | + # Test with all tests from group 1. |
| 164 | + args = parser.parse_args(["run", "--tests", "in/chk1a.in", "in/chk1b.in", "in/chk1c.in", "--time-tool", time_tool]) |
| 165 | + command = Command() |
| 166 | + command.run(args) |
| 167 | + out = capsys.readouterr().out |
| 168 | + assert 'sinol_expected_scores:\n' \ |
| 169 | + ' chk.cpp:\n' \ |
| 170 | + ' expected: {1: OK}\n' \ |
| 171 | + ' points: 50\n' \ |
| 172 | + ' chk1.cpp:\n' \ |
| 173 | + ' expected: {1: WA}\n' \ |
| 174 | + ' points: 0\n' \ |
| 175 | + ' chk2.cpp:\n' \ |
| 176 | + ' expected:\n' \ |
| 177 | + ' 1: {points: 25, status: OK}\n' \ |
| 178 | + ' points: 25\n' \ |
| 179 | + ' chk3.cpp:\n' \ |
| 180 | + ' expected: {1: OK}\n' \ |
| 181 | + ' points: 50' in out |
| 182 | + |
| 183 | + # Test with incorrect expected scores for first group. |
| 184 | + with open(os.path.join(package_path, "config.yml"), "r") as config_file: |
| 185 | + correct_config = yaml.load(config_file, Loader=yaml.SafeLoader) |
| 186 | + config = copy.deepcopy(correct_config) |
| 187 | + config["sinol_expected_scores"]["chk.cpp"]["expected"][1] = "WA" |
| 188 | + config["sinol_expected_scores"]["chk.cpp"]["points"] = 50 |
| 189 | + with open(os.path.join(package_path, "config.yml"), "w") as config_file: |
| 190 | + config_file.write(yaml.dump(config)) |
| 191 | + |
| 192 | + args = parser.parse_args(["run", "--tests", "in/chk1a.in", "in/chk1b.in", "in/chk1c.in", "--time-tool", time_tool, |
| 193 | + "--apply-suggestions"]) |
| 194 | + command = Command() |
| 195 | + command.run(args) |
| 196 | + out = capsys.readouterr().out |
| 197 | + sys.stdout.write(out) |
| 198 | + assert "Solution chk.cpp passed group 1 with status OK while it should pass with status WA." in out |
| 199 | + with open(os.path.join(package_path, "config.yml"), "r") as config_file: |
| 200 | + config = yaml.load(config_file, Loader=yaml.SafeLoader) |
| 201 | + assert config == correct_config |
| 202 | + |
| 203 | + |
142 | 204 | @pytest.mark.parametrize("create_package", [get_simple_package_path(), get_verify_status_package_path(),
|
143 | 205 | get_checker_package_path()], indirect=True)
|
144 | 206 | def test_flag_solutions(capsys, create_package, time_tool):
|
|
0 commit comments