def test_compile_fail(): src = 'answer\n' with pytest.raises(CompilationError) as err: Worker._compile(src) assert 'Traceback' in str(err)
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)
def test_func_not_found(): src = 'answer = 42\n' with pytest.raises(CompilationError) as err: Worker._compile(src) assert 'not found' in str(err)
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
def test_compile_context(): src = ( 'answer = 42\n' 'def run(x):\n' ' pass\n' ) func, context = Worker._compile(src) assert context['answer'] == 42
def test_compile_none(): assert Worker._compile(None) == (None, None)