Create tests for ejudge and co
Project description
Create tests for ejudge using solution
Install
pip install git+https://github.com/ShashkovS/ej_test_gen.git --user --upgrade
Example:
# sol.py
n = int(input())
fct = 1
for i in range(2, n + 1):
fct *= i
print(fct)
# test_creator.py
from ej_test_gen import TestRunner, random
runner = TestRunner(solution="sol.py", tests_dir="tests")
# runner = TestRunner(solution="sol.cpp", tests_dir="tests", use_WSL=True)
runner.test("""3""")
runner.test("""5""")
for tests_in_group, group_max in [(2, 10), (5, 50)]:
for __ in range(tests_in_group):
n = random.randint(0, group_max)
test = f'{n}'
runner.test(test)
> python test_creator.py
001: 3 --> 6¶ Done! 0.27c
002: 2 --> 2¶ Done! 0.25c
003: 3 --> 6¶ Done! 0.26c
004: 31 --> 8222838654177922817725562880000000¶ Done! 0.25c
005: 10 --> 3628800¶ Done! 0.26c
006: 15 --> 1307674368000¶ Done! 0.26c
007: 41 --> 3345252661316380710817006205344075166515 Done! 0.27c
008: 15 --> 1307674368000¶ Done! 0.27c
TestRunner resolves relative solution and tests_dir paths from the
directory of the script where TestRunner is created. This means sol.py and
test_creator.py can live in the same directory, and generated tests will be
written to tests/ next to them even if you run the script from another
directory:
python path/to/test_creator.py
Pass working_dir explicitly when you want a different base directory. For
example, working_dir="." keeps the old behavior where relative paths are
resolved from the process current working directory.
Solution errors
Use on_error to choose what happens when the solution exits with a non-zero
return code or writes to stderr:
# default: stop generation and raise RuntimeError
runner = TestRunner(solution="sol.py", tests_dir="tests")
# ignore: skip failed tests and keep generating the next ones
runner = TestRunner(solution="sol.py", tests_dir="tests", on_error="ignore")
# output: write stderr/traceback to the answer file
runner = TestRunner(solution="sol.py", tests_dir="tests", on_error="output")
Old names are still accepted for compatibility: on_error="raise" means
on_error="default", and on_error="skip" means on_error="ignore".
License
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ej_test_gen-0.3.0.tar.gz.
File metadata
- Download URL: ej_test_gen-0.3.0.tar.gz
- Upload date:
- Size: 12.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c445093c654c92bd92b04afe55e6184ba179d039fe26072d784204ebadb5b222
|
|
| MD5 |
6820508a5d1ae22e2b3c37651f2ef9e4
|
|
| BLAKE2b-256 |
90245d3294baf0e008887a8c514a6c120409c3689d4040b95cc7ce3d21df679f
|
File details
Details for the file ej_test_gen-0.3.0-py3-none-any.whl.
File metadata
- Download URL: ej_test_gen-0.3.0-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47463c62ada911fe60f70321cb857f55543484e0564fe82994386f944813d3ad
|
|
| MD5 |
bb9facfc16256ed5665c07549c3f8e76
|
|
| BLAKE2b-256 |
598d6e951b68cd95f7602b5aac4c9dd0b14f464f749d24ef28e002a14b0e350f
|