Skip to content

Commit

Permalink
feat: allow using groups layout with cpp tester
Browse files Browse the repository at this point in the history
  • Loading branch information
kalabukdima committed Sep 11, 2023
1 parent 0edbc01 commit c5e7375
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 14 deletions.
3 changes: 3 additions & 0 deletions checker/actions/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def _check_single_task(
reference_config_dir = private_course_driver.get_task_config_dir(task)
reference_public_tests_dir = private_course_driver.get_task_public_test_dir(task)
reference_private_tests_dir = private_course_driver.get_task_private_test_dir(task)
reference_tests_root_dir = private_course_driver.root_dir
assert reference_source_dir, 'reference_source_dir have to exists'
assert reference_config_dir, 'reference_config_dir have to exists'
assert reference_public_tests_dir or reference_private_tests_dir, \

Check warning on line 29 in checker/actions/check.py

View check run for this annotation

Codecov / codecov/patch

checker/actions/check.py#L22-L29

Added lines #L22 - L29 were not covered by tests
Expand All @@ -38,6 +39,7 @@ def _check_single_task(
reference_config_dir,
reference_public_tests_dir,
reference_private_tests_dir,
reference_tests_root_dir,
verbose=verbose,
normalize_output=True,
)
Expand All @@ -54,6 +56,7 @@ def _check_single_task(
reference_config_dir,
reference_public_tests_dir,
reference_private_tests_dir,
reference_tests_root_dir,
verbose=verbose,
normalize_output=True,
)
Expand Down
2 changes: 2 additions & 0 deletions checker/actions/grade.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ def grade_single_task(
reference_config_dir = private_course_driver.get_task_config_dir(task)
reference_public_tests_dir = private_course_driver.get_task_public_test_dir(task)
reference_private_tests_dir = private_course_driver.get_task_private_test_dir(task)
reference_tests_root_dir = private_course_driver.root_dir
assert source_dir, 'source_dir have to exists'
assert reference_config_dir, 'reference_config_dir have to exists'
assert reference_public_tests_dir or reference_private_tests_dir, \

Check warning on line 166 in checker/actions/grade.py

View check run for this annotation

Codecov / codecov/patch

checker/actions/grade.py#L159-L166

Added lines #L159 - L166 were not covered by tests
Expand All @@ -171,6 +172,7 @@ def grade_single_task(
reference_config_dir,
reference_public_tests_dir,
reference_private_tests_dir,
reference_tests_root_dir,
verbose=inspect,
normalize_output=inspect,
)
Expand Down
9 changes: 4 additions & 5 deletions checker/testers/cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def _gen_build( # type: ignore[override]
source_dir: Path,
public_tests_dir: Path | None,
private_tests_dir: Path | None,
tests_root_dir: Path,
sandbox: bool = True,
verbose: bool = False,
normalize_output: bool = False,
Expand All @@ -56,9 +57,7 @@ def _gen_build( # type: ignore[override]
patterns=test_config.allow_change,
raise_on_found=True,
)
reference_root = public_tests_dir.parent # type: ignore
task_name = source_dir.name
task_dir = reference_root / task_name
task_dir = public_tests_dir
self._executor(
copy_files,
source=source_dir,
Expand All @@ -77,7 +76,7 @@ def _gen_build( # type: ignore[override]
try:
print_info('Running cmake...', color='orange')
self._executor(
['cmake', '-G', 'Ninja', str(reference_root),
['cmake', '-G', 'Ninja', str(tests_root_dir),
'-DGRADER=YES', '-DENABLE_PRIVATE_TESTS=YES',
f'-DCMAKE_BUILD_TYPE={test_config.build_type}'],
cwd=build_dir,
Expand All @@ -104,7 +103,7 @@ def _gen_build( # type: ignore[override]

try:
print_info('Running clang format...', color='orange')
format_path = reference_root / 'run-clang-format.py'
format_path = tests_root_dir / 'run-clang-format.py'
self._executor(
[str(format_path), '-r', str(task_dir)],
cwd=build_dir,
Expand Down
1 change: 1 addition & 0 deletions checker/testers/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def _gen_build( # type: ignore[override]
source_dir: Path,
public_tests_dir: Path | None,
private_tests_dir: Path | None,
tests_root_dir: Path,
sandbox: bool = True,
verbose: bool = False,
normalize_output: bool = False,
Expand Down
1 change: 1 addition & 0 deletions checker/testers/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def _gen_build( # type: ignore[override]
source_dir: Path,
public_tests_dir: Path | None,
private_tests_dir: Path | None,
tests_root_dir: Path,
sandbox: bool = True,
verbose: bool = False,
normalize_output: bool = False,
Expand Down
3 changes: 3 additions & 0 deletions checker/testers/tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def _gen_build(
source_dir: Path,
public_tests_dir: Path | None,
private_tests_dir: Path | None,
tests_root_dir: Path,
sandbox: bool = True,
verbose: bool = False,
normalize_output: bool = False,
Expand Down Expand Up @@ -167,6 +168,7 @@ def test_task(
config_dir: Path,
public_tests_dir: Path | None,
private_tests_dir: Path | None,
tests_root_dir: Path,
verbose: bool = False,
normalize_output: bool = False,
) -> float:
Expand Down Expand Up @@ -198,6 +200,7 @@ def test_task(
source_dir,
public_tests_dir,
private_tests_dir,
tests_root_dir,
sandbox=True,
verbose=verbose,
normalize_output=normalize_output,
Expand Down
8 changes: 7 additions & 1 deletion tests/testers/test_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ def init_task(tmp_path: Path, code: str, **kwargs):

format_path = reference_dir / 'run-clang-format.py'
format_path.chmod(format_path.stat().st_mode | stat.S_IEXEC)
return source_dir, private_tests_dir, public_tests_dir, private_tests_dir
return (
source_dir,
private_tests_dir, # config_dir
public_tests_dir,
private_tests_dir,
reference_dir, # tests_root_dir
)


STAGE_BUILD = 1
Expand Down
16 changes: 8 additions & 8 deletions tests/testers/test_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_nothing() -> None:
"""
create_single_file_task(tmp_path, CODE, PUBLIC_TESTS, PRIVATE_TESTS)

score = python_tester.test_task(tmp_path, tmp_path, tmp_path, tmp_path, normalize_output=True)
score = python_tester.test_task(tmp_path, tmp_path, tmp_path, tmp_path, tmp_path, normalize_output=True)
assert score == 1

captures = capsys.readouterr()
Expand All @@ -98,7 +98,7 @@ def test_nothing() -> None:
create_single_file_task(tmp_path, CODE, PUBLIC_TESTS)

with pytest.raises(StylecheckFailedError):
python_tester.test_task(tmp_path, tmp_path, tmp_path, tmp_path, normalize_output=True)
python_tester.test_task(tmp_path, tmp_path, tmp_path, tmp_path, tmp_path, normalize_output=True)

def test_disabled_mypy_error(
self,
Expand All @@ -119,7 +119,7 @@ def test_nothing() -> None:
"""
create_single_file_task(tmp_path, CODE, PUBLIC_TESTS, tester_config=CONFIG)

python_tester.test_task(tmp_path, tmp_path, tmp_path, tmp_path, normalize_output=True)
python_tester.test_task(tmp_path, tmp_path, tmp_path, tmp_path, tmp_path, normalize_output=True)

captures = capsys.readouterr()
assert 'Running mypy checks...' not in captures.err
Expand All @@ -143,7 +143,7 @@ def test_nothing() -> None:
create_single_file_task(tmp_path, CODE, PUBLIC_TESTS, tester_config=CONFIG)

with pytest.raises(StylecheckFailedError):
python_tester.test_task(tmp_path, tmp_path, tmp_path, tmp_path, normalize_output=True)
python_tester.test_task(tmp_path, tmp_path, tmp_path, tmp_path, tmp_path, normalize_output=True)

def test_ruff_error(
self,
Expand All @@ -164,7 +164,7 @@ def test_nothing() -> None:
create_single_file_task(tmp_path, CODE, PUBLIC_TESTS, tester_config=CONFIG)

with pytest.raises(StylecheckFailedError):
python_tester.test_task(tmp_path, tmp_path, tmp_path, tmp_path, normalize_output=True)
python_tester.test_task(tmp_path, tmp_path, tmp_path, tmp_path, tmp_path, normalize_output=True)

def test_pytest_error(
self,
Expand All @@ -185,7 +185,7 @@ def test_nothing() -> None:
create_single_file_task(tmp_path, CODE, PUBLIC_TESTS, tester_config=CONFIG)

with pytest.raises(TestsFailedError) as ex:
python_tester.test_task(tmp_path, tmp_path, tmp_path, tmp_path, normalize_output=True)
python_tester.test_task(tmp_path, tmp_path, tmp_path, tmp_path, tmp_path, normalize_output=True)

def test_pytest_error_no_duble_error(
self,
Expand All @@ -208,7 +208,7 @@ def test_nothing() -> None:
create_single_file_task(tmp_path, CODE, PUBLIC_TESTS, tester_config=CONFIG)

with pytest.raises(TestsFailedError) as ex:
python_tester.test_task(tmp_path, tmp_path, tmp_path, tmp_path, normalize_output=True)
python_tester.test_task(tmp_path, tmp_path, tmp_path, tmp_path, tmp_path, normalize_output=True)
captured = capsys.readouterr()

assert captured.err.count('short test summary info ') == 1
Expand Down Expand Up @@ -237,7 +237,7 @@ def test_nothing() -> None:
"""
create_single_file_task(tmp_path, CODE, PUBLIC_TESTS, tester_config=CONFIG, setup_file=SETUP)

score = python_tester.test_task(tmp_path, tmp_path, tmp_path, tmp_path, normalize_output=True)
score = python_tester.test_task(tmp_path, tmp_path, tmp_path, tmp_path, tmp_path, normalize_output=True)
assert score == 1

captures = capsys.readouterr()
Expand Down

0 comments on commit c5e7375

Please sign in to comment.