mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-11-10 21:07:09 +01:00
kuhy chose the strict branch: no per-file-ignores at all, not even the S101 block that ruff's own docs and the rest of this fleet carry for test code. So 125 test assertions were rewritten to raise instead of assert. Rather than 125 copies of `if x != y: raise AssertionError(...)`, each course grows a small expect module -- expect_equal / expect_in / expect_true / expect_false. That is also strictly better output than a bare assert here: pytest's assertion rewriting does not reach into a helper, so the helper has to print both values, and it does. The rewrite itself went through ast, not a regex, because seven of ECOTE's asserts were wrapped over several lines. Everything else in the two courses is gone as well: - 66 argument and 37 return annotations on the translator, worked out from what each function actually returns rather than stamped on as Any -- `list[str] | str` where a function returns "Error!" or the parsed columns. - 16 prints became logger.error with %-style arguments. The messages still reach stderr with no basicConfig, via logging's last-resort handler, so the translator behaves exactly as before. - Two `open()` calls became Path.open / Path.write_text, six RET504 assign-then-return pairs collapsed, one 380-character expected-HTML literal split into implicitly concatenated pieces (it cannot be wrapped any other way, which is what ISC001 being off is for), and one block of commented-out code deleted. - ECRYPT_PROJECT/__init__.py removed. It made the COURSE directory a package, which nothing imports, and it was the sole cause of `N999 Invalid module name: 'ECRYPT_PROJECT'`; with it gone, sieve is the top-level package and its name is fine. Verified by running both, not by reading: ECOTE 26 tests pass and `python -m translator.main --filename examples/complicated/table1.tex` still writes the same HTML with the same three column-count warnings on stderr; ECRYPT_PROJECT 99 tests pass. Repo-wide: 3,686 findings -> 3,159. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0172dj34FDpao6wsix8ZuCzE
62 lines
2.1 KiB
Python
62 lines
2.1 KiB
Python
"""Turn the reference CSVs into one test case per prime and per composite.
|
|
|
|
``P-100000.csv`` and ``C-100000.csv`` sit beside this file and are read with a
|
|
relative path, which is why the suite has to be run from this directory (see
|
|
``../run.sh``). ``--primes`` and ``--composites`` cap how far up each table the
|
|
run goes; the defaults keep a plain ``pytest`` fast.
|
|
"""
|
|
|
|
import pandas as pd
|
|
import pytest
|
|
|
|
from .project import sieve_of_eratosthenes
|
|
|
|
DEFAULT_BOUND = "100"
|
|
|
|
|
|
def pytest_addoption(parser: pytest.Parser) -> None:
|
|
"""Register the two bounds that decide how much of each table is used."""
|
|
parser.addoption(
|
|
"--primes",
|
|
action="store",
|
|
default=DEFAULT_BOUND,
|
|
help="Upper bound for primes to test.",
|
|
)
|
|
parser.addoption(
|
|
"--composites",
|
|
action="store",
|
|
default=DEFAULT_BOUND,
|
|
help="Upper bound for composites to test.",
|
|
)
|
|
|
|
|
|
def pytest_configure(config: pytest.Config) -> None:
|
|
"""Stash the parsed bounds where pytest_generate_tests can reach them."""
|
|
pytest.primes = int(config.getoption("--primes"))
|
|
pytest.composites = int(config.getoption("--composites"))
|
|
|
|
|
|
def pytest_generate_tests(metafunc: pytest.Metafunc) -> None:
|
|
"""Parametrise each test over its half of the reference tables."""
|
|
df_prime = pd.read_csv("P-100000.csv", header=None)
|
|
df_prime = df_prime[df_prime.iloc[:, 1] < pytest.primes]
|
|
primes = set(df_prime.iloc[:, 1])
|
|
# C-100000.csv is "n=factorisation", so the number is the first column.
|
|
df_composite = pd.read_csv("C-100000.csv", header=None, delimiter="=")
|
|
df_composite = df_composite[df_composite.iloc[:, 0] < pytest.composites]
|
|
composites = set(df_composite.iloc[:, 0])
|
|
|
|
if metafunc.function.__name__ == "test_positives":
|
|
metafunc.parametrize("prime", primes)
|
|
metafunc.parametrize(
|
|
"primes_obtained",
|
|
[sieve_of_eratosthenes(max(primes) + 1)],
|
|
)
|
|
|
|
if metafunc.function.__name__ == "test_composites":
|
|
metafunc.parametrize("composite", composites)
|
|
metafunc.parametrize(
|
|
"primes_obtained",
|
|
[sieve_of_eratosthenes(max(composites) + 1)],
|
|
)
|