Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow using groups layout with cpp tester #30

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions checker/actions/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
verbose: bool = False,
catch_output: bool = False,
) -> str | None:
reference_source_dir = private_course_driver.get_task_solution_dir(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
'reference_public_tests_dir or reference_private_tests_dir have to exists'

if catch_output:
Expand All @@ -38,6 +39,7 @@
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 @@
reference_config_dir,
reference_public_tests_dir,
reference_private_tests_dir,
reference_tests_root_dir,
verbose=verbose,
normalize_output=True,
)
Expand Down Expand Up @@ -96,7 +99,7 @@
else:
for task in tasks:
try:
_check_single_task(task, tester, private_course_driver, verbose=verbose, catch_output=False)

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

View check run for this annotation

Codecov / codecov/patch

checker/actions/check.py#L102

Added line #L102 was not covered by tests
except RunFailedError:
return False
except Exception as e:
Expand Down
2 changes: 2 additions & 0 deletions checker/actions/grade.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,14 @@
inspect: bool = False
) -> bool:
print_task_info(task.full_name)
source_dir = public_course_driver.get_task_solution_dir(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
'reference_public_tests_dir or reference_private_tests_dir have to exists'

try:
Expand All @@ -171,6 +172,7 @@
reference_config_dir,
reference_public_tests_dir,
reference_private_tests_dir,
reference_tests_root_dir,
verbose=inspect,
normalize_output=inspect,
)
Expand Down Expand Up @@ -300,7 +302,7 @@
tasks: list[Task] = []
groups: list[Group] = []
for changed_file in changes:
changed_task_dir = public_course_driver.get_task_dir_name(changed_file)

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

View check run for this annotation

Codecov / codecov/patch

checker/actions/grade.py#L305

Added line #L305 was not covered by tests
if changed_task_dir is None or changed_task_dir not in course_schedule.tasks:
continue

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 @@
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 @@ -36,8 +37,8 @@
verbose=verbose,
)

if public_tests_dir is not None:
self._executor(

Check warning on line 41 in checker/testers/make.py

View check run for this annotation

Codecov / codecov/patch

checker/testers/make.py#L40-L41

Added lines #L40 - L41 were not covered by tests
copy_files,
source=public_tests_dir,
target=build_dir,
Expand All @@ -45,8 +46,8 @@
verbose=verbose,
)

if private_tests_dir is not None:
self._executor(

Check warning on line 50 in checker/testers/make.py

View check run for this annotation

Codecov / codecov/patch

checker/testers/make.py#L49-L50

Added lines #L49 - L50 were not covered by tests
copy_files,
source=private_tests_dir,
target=build_dir,
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 @@
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 @@ -336,7 +337,7 @@
if normalize_output:
print_info(e.output, end='')
e.output = ''
output = ''

Check warning on line 340 in checker/testers/python.py

View check run for this annotation

Codecov / codecov/patch

checker/testers/python.py#L340

Added line #L340 was not covered by tests
print_info('ERROR', color='red')

# Check tests
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
Loading