Skip to content
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 .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ jobs:
- name: Run mypy
run: |
venv/bin/mypy --non-interactive --config-file mypy.ini -p problemtools
- name: Run mypy on tests
run: |
venv/bin/mypy --non-interactive --config-file mypy.ini --exclude '^tests/data/' tests/

packages: # Use a separate job to test debian packaging to speed things up (no need to test this for every python version above)
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ venv/bin/ruff check .
venv/bin/ruff format --check .
venv/bin/pytest
venv/bin/mypy --non-interactive --config-file mypy.ini -p problemtools
venv/bin/mypy --non-interactive --config-file mypy.ini --exclude '^tests/data/' tests/
12 changes: 12 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
"""Shared pytest fixtures and test doubles."""

from pathlib import Path

import pytest

from problemtools.diagnostics import Diagnostics


def datadir() -> Path:
"""Root directory holding static test fixture data."""
return (Path(__file__).parent / 'data').resolve()


def example_directory(problem_name: str) -> Path:
"""Path to one of the example problems shipped in the repo's top-level examples/ directory."""
return (Path(__file__).parent.parent / 'examples' / problem_name).resolve()


class RecordingDiagnostics(Diagnostics):
"""A Diagnostics that records messages instead of emitting them, for asserting on in tests."""

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/default_validator_tests/run_and_generate_expected.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from pathlib import Path


def main():
def main() -> None:
"""Main function"""
parser = argparse.ArgumentParser(description='Run default_validator and generate expected output files.')
parser.add_argument('test_dir', type=Path, help='Path to the test directory.')
Expand Down
1 change: 0 additions & 1 deletion tests/hello/data/secret/hello.ans

This file was deleted.

Empty file removed tests/hello/data/secret/hello.in
Empty file.
8 changes: 0 additions & 8 deletions tests/hello/input_validators/validate.py

This file was deleted.

9 changes: 0 additions & 9 deletions tests/hello/problem.yaml

This file was deleted.

9 changes: 0 additions & 9 deletions tests/hello/problem_statement/problem.en.tex

This file was deleted.

10 changes: 0 additions & 10 deletions tests/hello/problem_statement/problem.sv.tex

This file was deleted.

6 changes: 0 additions & 6 deletions tests/hello/submissions/accepted/hello.cc

This file was deleted.

5 changes: 0 additions & 5 deletions tests/hello/submissions/accepted/hello.java

This file was deleted.

4 changes: 0 additions & 4 deletions tests/hello/submissions/accepted/hello.kt

This file was deleted.

3 changes: 0 additions & 3 deletions tests/hello/submissions/accepted/hello.py

This file was deleted.

35 changes: 0 additions & 35 deletions tests/hello/submissions/accepted/hello_alarm.c

This file was deleted.

11 changes: 0 additions & 11 deletions tests/hello/submissions/run_time_error/memory_limit.cc

This file was deleted.

6 changes: 0 additions & 6 deletions tests/hello/submissions/wrong_answer/hello.cc

This file was deleted.

19 changes: 10 additions & 9 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
from pathlib import Path

import pytest

from problemtools import config
from tests.conftest import datadir


def config_paths_mock():
from pathlib import Path

return [Path(__file__).parent / 'config1', Path(__file__).parent / 'config2']
def config_paths_mock() -> list[Path]:
return [datadir() / 'config1', datadir() / 'config2']


def test_load_basic_config(monkeypatch):
def test_load_basic_config(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(config, '__config_file_paths', config_paths_mock)

conf = config.load_config('test.yaml')
assert conf == {'prop1': 'hello', 'prop2': 5}


def test_load_updated_config(monkeypatch):
def test_load_updated_config(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(config, '__config_file_paths', config_paths_mock)

conf = config.load_config('test2.yaml')
assert conf == {'prop1': 'abc', 'prop2': 23, 'prop3': ['hello', 'world']}


def test_load_missing_config(monkeypatch):
def test_load_missing_config(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(config, '__config_file_paths', config_paths_mock)

with pytest.raises(config.ConfigError):
config.load_config('non_existent_file')


def test_load_broken_config(monkeypatch):
def test_load_broken_config(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(config, '__config_file_paths', config_paths_mock)

with pytest.raises(config.ConfigError):
config.load_config('broken.yaml')


def test_update_dict():
def test_update_dict() -> None:
update_dict = config.__dict__['__update_dict']

dict1 = {'a': 1, 'b': {'sub1': 1, 'sub2': False}, 'c': 3}
Expand Down
6 changes: 3 additions & 3 deletions tests/test_default_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def validator() -> Path:
return VALIDATOR_PATH


def discover_test_cases():
def discover_test_cases() -> list[Path]:
"""
Finds and returns a list of all test case directories.
A test case directory is expected to start with 'test_'.
Expand All @@ -46,7 +46,7 @@ def discover_test_cases():


@pytest.mark.parametrize('test_dir', discover_test_cases(), ids=lambda d: d.name)
def test_default_validator(validator: Path, test_dir: Path):
def test_default_validator(validator: Path, test_dir: Path) -> None:
"""
Runs a single validator test case.
The test is parametrized to run for each directory discovered by `discover_test_cases`.
Expand Down Expand Up @@ -90,4 +90,4 @@ def test_default_validator(validator: Path, test_dir: Path):
# If no message is expected, assert that no message was generated.
if judgemessage_path.is_file():
actual_message = judgemessage_path.read_bytes()
assert not actual_message, f'A validation message was generated but none was expected: {actual_message}'
assert not actual_message, f'A validation message was generated but none was expected: {actual_message!r}'
Loading