예제 #1
0
def test_compile_fail():
    src = 'answer\n'

    with pytest.raises(CompilationError) as err:
        Worker._compile(src)

    assert 'Traceback' in str(err)
예제 #2
0
def test_compile_wrong_type():
    src = 'run = 42\n'

    with pytest.raises(CompilationError) as err:
        Worker._compile(src)

    assert 'must be a function' in str(err)
예제 #3
0
def test_func_not_found():
    src = 'answer = 42\n'

    with pytest.raises(CompilationError) as err:
        Worker._compile(src)

    assert 'not found' in str(err)
예제 #4
0
def test_compile():
    src = 'def run(x): return int(x)\n'

    func, context = Worker._compile(src)

    assert context['run'] is func
    assert func('42') == 42
예제 #5
0
def test_compile_context():
    src = (
        'answer = 42\n'
        'def run(x):\n'
        '  pass\n'
    )

    func, context = Worker._compile(src)

    assert context['answer'] == 42
예제 #6
0
def test_compile_none():
    assert Worker._compile(None) ==  (None, None)