Beispiel #1
0
def test_hello_wrong():
    correct = ioparse('hello world!')
    wrong = ioparse('hi world!')
    fb = feedback.feedback(wrong[0], correct[0])
    txt = fb.as_text()
    html = fb.as_html()
    tex = fb.as_latex()
    message = 'Wrong Answer'
    assert fb.grade == 0
    assert message in txt
    assert message in html
    assert message in tex
Beispiel #2
0
def grade(source, iospec, lang=None, *,
          fast=True, path=None, raises=False, sandbox=False, timeout=None,
          compare_streams=False):
    """
    Grade the string of source code by comparing the results of all inputs and
    outputs in the given template structure.


    Args:
        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.

            +-----------+------------------------------------------------------+
            | 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                              |
            +-----------+------------------------------------------------------+

        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.

    Returns:
        A :class:`ejudge.Feedback` instance.
    """

    if isinstance(iospec, str):
        iospec = ioparse(iospec)
    kwargs = locals()
    kwargs['inputs'] = kwargs.pop('iospec')
    result = run(**kwargs)
    return get_feedback(result, iospec, stream=compare_streams)
Beispiel #3
0
def tree_ok():
    return ioparse('foo: <bar>\n' 'hi bar!')
Beispiel #4
0
def tree_presentation():
    return ioparse('Foo:<bar>\n' 'Hi Bar!')
Beispiel #5
0
def tree_wrong():
    return ioparse('foo: <bar>\n' 'bar')
Beispiel #6
0
def tree_ok():
    return ioparse(
        'foo: <bar>\n'
        'hi bar!'
    )
Beispiel #7
0
def tree_presentation():
    return ioparse(
        'foo:<bar>\n'
        'hi bar!'
    )
Beispiel #8
0
def tree_wrong():
    return ioparse(
        'foo: <bar>\n'
        'bar'
    )
Beispiel #9
0
def tree_presentation():
    return ioparse(
        'Foo:<bar>\n'
        'Hi Bar!'
    )