API Reference¶
API documentation for the ejudge module.
-
ejudge.
run
(source, inputs, lang=None, *, timeout=None, raises=False, path=None, sandbox=True)[source]¶ Run program with the given list of inputs and returns the corresponding
iospec.IoSpec
instance with the results.Parameters: - source (str or file) – The source code for the test program
- inputs (sequence) – A sequence of input strings. If input is a sequence of sequences, this function will perform multiple test cases. It can also be a IoSpec or a TestCase instance which are used to extract the necessary input strings.
- lang (str) – The name for the source code language. See
ejudge.graders.io.grade()
for more details. - timeout (float) – A time limit for the entire run (in seconds). If this attribute is not given, the program will run without any timeout. This can be potentially dangerous if the input program has an infinite loop.
- sandbox (bool) – Controls if code is run in sandboxed mode or not. Sandbox protection is the default behavior on supported platforms.
- raises (bool) – If True, raise a BuildError if the build process fails. The default behavior is to return a IoSpec instance with a single ErrorTestCase with a type string of ‘error-build’.
- path (str) – The absolute file path for the input string or file object.
Returns: A
iospec.IoSpec
structure. Ifinputs
is a sequence of strings, the resulting tree will have a single test case.
-
ejudge.
grade
(source, iospec, lang=None, *, fast=True, path=None, raises=False, sandbox=False, timeout=None)[source]¶ Grade the string of source code by comparing the results of all inputs and outputs in the given template structure.
Parameters: - source (str or file object) – The source string for the code or a file object
- iospec (IOSpec parse tree) – The expected template for correct answers.
- lang (str) – Programming language for the given source code. Users can implement plugins to support additional languages or to override the default behavior or accepted languages.
- sandbox (bool) – If True, code will run in a sandboxed environment as the nobody user. It is necessary to have your system properly configured in order to do this.
- timeout (float) – Maximum time (in seconds) for the complete test to run.
Specific languages may support additional keyword arguments. The most common ones are shown bellow
- namespace (python, dict)
- The global namespace used to run a python script.
Returns: A ejudge.Feedback
instance.
Supported Languages¶
Value | Description |
---|---|
python | For Python 3.x code. Default runner. |
python2 | Executes in a separate Python 2 interpreter. |
tcc | Compile C code with the tiny C compiler |
clang | Compile C code with clang |
gcc, c | Compile C code with gcc |