Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ej_test_gen-0.3.0.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ej_test_gen-0.3.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

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

Hashes for ej_test_gen-0.3.0.tar.gz
Algorithm Hash digest
SHA256 c445093c654c92bd92b04afe55e6184ba179d039fe26072d784204ebadb5b222
MD5 6820508a5d1ae22e2b3c37651f2ef9e4
BLAKE2b-256 90245d3294baf0e008887a8c514a6c120409c3689d4040b95cc7ce3d21df679f

See more details on using hashes here.

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

Hashes for ej_test_gen-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 47463c62ada911fe60f70321cb857f55543484e0564fe82994386f944813d3ad
MD5 bb9facfc16256ed5665c07549c3f8e76
BLAKE2b-256 598d6e951b68cd95f7602b5aac4c9dd0b14f464f749d24ef28e002a14b0e350f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page