Exemplo n.º 1
0
def test_normal_code_import():
    foo = import_code(
        "foo",
        "def say_bar():\n    return 'bar'",
    )
    assert foo.__name__ == "foo"
    assert foo.say_bar() == "bar"
Exemplo n.º 2
0
def test_import_function(test_hello_code):
    hello = import_code("hello", test_hello_code)
    assert hello.say_hello() == "hello"
Exemplo n.º 3
0
def test_import_name(test_hello_code):
    hello = import_code("hello", test_hello_code)
    assert hello.__name__ == "hello"
Exemplo n.º 4
0
def test_import(test_hello_code):
    import_code("hello", test_hello_code)
Exemplo n.º 5
0
def test_invalid_code_import():
    with pytest.raises(SyntaxError):
        import_code("foo", "this is not a piece of python code")
Exemplo n.º 6
0
def test_invalid_module_name():
    with pytest.raises(ValueError):
        import_code("foo bar", "")