예제 #1
0
파일: calc_test.py 프로젝트: item4/yui
def test_generator_exp():
    e = Evaluator()
    e.symbol_table["r"] = [1, 2, 3]
    err = "Defining new generator expression is not allowed"
    with pytest.raises(BadSyntax, match=err):
        e.run("x = (i ** 2 for i in r)")
    assert "x" not in e.symbol_table
예제 #2
0
파일: calc_test.py 프로젝트: iCodeIN/yui
def test_generator_exp():
    e = Evaluator()
    e.symbol_table['r'] = [1, 2, 3]
    err = 'Defining new generator expression is not allowed'
    with pytest.raises(BadSyntax, match=err):
        e.run('x = (i ** 2 for i in r)')
    assert 'x' not in e.symbol_table
예제 #3
0
파일: calc_test.py 프로젝트: item4/yui
def test_annassign():
    e = Evaluator()

    err = "You can not use annotation syntax"
    with pytest.raises(BadSyntax, match=err):
        e.run("a: int = 10")

    assert "a" not in e.symbol_table
예제 #4
0
파일: calc_test.py 프로젝트: iCodeIN/yui
def test_annassign():
    e = Evaluator()

    err = 'You can not use annotation syntax'
    with pytest.raises(BadSyntax, match=err):
        e.run('a: int = 10')

    assert 'a' not in e.symbol_table
예제 #5
0
파일: calc_test.py 프로젝트: iCodeIN/yui
def test_with():
    e = Evaluator()
    err = 'You can not use `with` syntax'
    with pytest.raises(BadSyntax, match=err):
        e.run('''
with some:
    x = 1
''')
    assert 'x' not in e.symbol_table
예제 #6
0
파일: calc_test.py 프로젝트: iCodeIN/yui
def test_slice():
    e = Evaluator()
    e.symbol_table['obj'] = GetItemSpy()
    e.run('obj[10:20:3]')
    s = e.symbol_table['obj'].queue.pop()
    assert isinstance(s, slice)
    assert s.start == 10
    assert s.stop == 20
    assert s.step == 3
예제 #7
0
파일: calc_test.py 프로젝트: iCodeIN/yui
def test_classdef():
    e = Evaluator()
    err = 'Defining new class via def syntax is not allowed'
    with pytest.raises(BadSyntax, match=err):
        e.run('''
class ABCD:
    pass

''')
    assert 'ABCD' not in e.symbol_table
예제 #8
0
파일: calc_test.py 프로젝트: iCodeIN/yui
def test_functiondef():
    e = Evaluator()
    err = 'Defining new function via def syntax is not allowed'
    with pytest.raises(BadSyntax, match=err):
        e.run('''
def abc():
    pass

''')
    assert 'abc' not in e.symbol_table
예제 #9
0
파일: calc_test.py 프로젝트: iCodeIN/yui
def test_asyncwith():
    e = Evaluator()
    e.symbol_table['r'] = 0
    err = 'You can not use `async with` syntax'
    with pytest.raises(BadSyntax, match=err):
        e.run('''
async with x():
    r += 100

''')
    assert e.symbol_table['r'] == 0
예제 #10
0
파일: calc_test.py 프로젝트: iCodeIN/yui
def test_asyncfor():
    e = Evaluator()
    e.symbol_table['r'] = 0
    err = 'You can not use `async for` loop syntax'
    with pytest.raises(BadSyntax, match=err):
        e.run('''
async for x in [1, 2, 3, 4]:
    r += x

''')
    assert e.symbol_table['r'] == 0
예제 #11
0
파일: calc_test.py 프로젝트: item4/yui
def test_with():
    e = Evaluator()
    err = "You can not use `with` syntax"
    with pytest.raises(BadSyntax, match=err):
        e.run(
            """
with some:
    x = 1
"""
        )
    assert "x" not in e.symbol_table
예제 #12
0
파일: calc_test.py 프로젝트: iCodeIN/yui
def test_expr():
    e = Evaluator()
    assert e.run('True') is True
    assert e.run('False') is False
    assert e.run('None') is None
    assert e.run('123') == 123
    assert e.run('"abc"') == 'abc'
    assert e.run('[1, 2, 3]') == [1, 2, 3]
    assert e.run('(1, 2, 3, 3)') == (1, 2, 3, 3)
    assert e.run('{1, 2, 3, 3}') == {1, 2, 3}
    assert e.run('{1: 111, 2: 222}') == {1: 111, 2: 222}
예제 #13
0
파일: calc_test.py 프로젝트: iCodeIN/yui
def test_try():
    e = Evaluator()
    err = 'You can not use `try` syntax'
    with pytest.raises(BadSyntax, match=err):
        e.run('''
try:
    x = 1
except:
    pass
''')
    assert 'x' not in e.symbol_table
예제 #14
0
파일: calc_test.py 프로젝트: item4/yui
def test_expr():
    e = Evaluator()
    assert e.run("True") is True
    assert e.run("False") is False
    assert e.run("None") is None
    assert e.run("123") == 123
    assert e.run('"abc"') == "abc"
    assert e.run("[1, 2, 3]") == [1, 2, 3]
    assert e.run("(1, 2, 3, 3)") == (1, 2, 3, 3)
    assert e.run("{1, 2, 3, 3}") == {1, 2, 3}
    assert e.run("{1: 111, 2: 222}") == {1: 111, 2: 222}
예제 #15
0
파일: calc_test.py 프로젝트: item4/yui
def test_classdef():
    e = Evaluator()
    err = "Defining new class via def syntax is not allowed"
    with pytest.raises(BadSyntax, match=err):
        e.run(
            """
class ABCD:
    pass

"""
        )
    assert "ABCD" not in e.symbol_table
예제 #16
0
파일: calc_test.py 프로젝트: item4/yui
def test_functiondef():
    e = Evaluator()
    err = "Defining new function via def syntax is not allowed"
    with pytest.raises(BadSyntax, match=err):
        e.run(
            """
def abc():
    pass

"""
        )
    assert "abc" not in e.symbol_table
예제 #17
0
파일: calc_test.py 프로젝트: item4/yui
def test_asyncwith():
    e = Evaluator()
    e.symbol_table["r"] = 0
    err = "You can not use `async with` syntax"
    with pytest.raises(BadSyntax, match=err):
        e.run(
            """
async with x():
    r += 100

"""
        )
    assert e.symbol_table["r"] == 0
예제 #18
0
파일: calc_test.py 프로젝트: u1-liquid/yui
def test_extslice():
    e = Evaluator()
    e.symbol_table['obj'] = GetItemSpy()
    e.run('obj[1,2:3,4]')
    es = e.symbol_table['obj'].queue.pop()
    assert isinstance(es, tuple)
    assert len(es) == 3
    assert es[0] == 1
    assert isinstance(es[1], slice)
    assert es[1].start == 2
    assert es[1].stop == 3
    assert es[1].step is None
    assert es[2] == 4
예제 #19
0
파일: calc_test.py 프로젝트: item4/yui
def test_try():
    e = Evaluator()
    err = "You can not use `try` syntax"
    with pytest.raises(BadSyntax, match=err):
        e.run(
            """
try:
    x = 1
except:
    pass
"""
        )
    assert "x" not in e.symbol_table
예제 #20
0
파일: calc_test.py 프로젝트: item4/yui
def test_asyncfor():
    e = Evaluator()
    e.symbol_table["r"] = 0
    err = "You can not use `async for` loop syntax"
    with pytest.raises(BadSyntax, match=err):
        e.run(
            """
async for x in [1, 2, 3, 4]:
    r += x

"""
        )
    assert e.symbol_table["r"] == 0
예제 #21
0
파일: calc_test.py 프로젝트: item4/yui
def test_if():
    e = Evaluator()
    e.symbol_table["a"] = 1
    e.run(
        """
if a == 1:
    a = 2
    b = 3
"""
    )
    assert e.symbol_table["a"] == 2
    assert e.symbol_table["b"] == 3

    e.run(
        """
if a == 1:
    a = 2
    b = 3
    z = 1
else:
    a = 3
    b = 4
    c = 5
"""
    )
    assert e.symbol_table["a"] == 3
    assert e.symbol_table["b"] == 4
    assert e.symbol_table["c"] == 5
    assert "z" not in e.symbol_table

    e.run(
        """
if a == 1:
    a = 2
    b = 3
    z = 1
elif a == 3:
    d = 4
    e = 5
    f = 6
else:
    a = 3
    b = 4
    c = 5
    y = 7
"""
    )
    assert e.symbol_table["a"] == 3
    assert e.symbol_table["b"] == 4
    assert e.symbol_table["c"] == 5
    assert e.symbol_table["d"] == 4
    assert e.symbol_table["e"] == 5
    assert e.symbol_table["f"] == 6
    assert "y" not in e.symbol_table
    assert "z" not in e.symbol_table
예제 #22
0
파일: calc_test.py 프로젝트: iCodeIN/yui
def test_listcomp():
    e = Evaluator()
    assert e.run('[x ** 2 for x in [1, 2, 3]]') == [1, 4, 9]
    assert 'x' not in e.symbol_table
    assert e.run('[x ** 2 + y for x in [1, 2, 3] for y in [10, 20, 30]]') == ([
        x**2 + y for x in [1, 2, 3] for y in [10, 20, 30]
    ])
    assert 'x' not in e.symbol_table
    assert 'y' not in e.symbol_table
    assert e.run('[y ** 2 for x in [1, 2, 3] for y in [x+1, x+3, x+5]]') == ([
        y**2 for x in [1, 2, 3] for y in [x + 1, x + 3, x + 5]
    ])
    assert 'x' not in e.symbol_table
    assert 'y' not in e.symbol_table
예제 #23
0
파일: calc_test.py 프로젝트: item4/yui
def test_setcomp():
    e = Evaluator()
    assert e.run("{x ** 2 for x in [1, 2, 3, 3]}") == {1, 4, 9}
    assert "x" not in e.symbol_table
    assert e.run("{x ** 2 + y for x in [1, 2, 3] for y in [10, 20, 30]}") == (
        {x**2 + y for x in [1, 2, 3] for y in [10, 20, 30]}
    )
    assert "x" not in e.symbol_table
    assert "y" not in e.symbol_table
    assert e.run("{y ** 2 for x in [1, 2, 3] for y in [x+1, x+3, x+5]}") == (
        {y**2 for x in [1, 2, 3] for y in [x + 1, x + 3, x + 5]}
    )
    assert "x" not in e.symbol_table
    assert "y" not in e.symbol_table
예제 #24
0
def test_assign():
    e = Evaluator()
    e.run('a = 1 + 2')
    assert e.symbol_table['a'] == 3
    e.run('x, y = 10, 20')
    assert e.symbol_table['x'] == 10
    assert e.symbol_table['y'] == 20

    e.symbol_table['dt'] = datetime.now()
    err = 'This assign method is not allowed'
    with pytest.raises(BadSyntax, match=err):
        e.run('dt.year = 2000')
예제 #25
0
파일: calc_test.py 프로젝트: item4/yui
def test_dictcomp():
    e = Evaluator()
    assert e.run("{k+1: v**2 for k, v in {1: 1, 2: 11, 3: 111}.items()}") == {
        2: 1,
        3: 121,
        4: 12321,
    }
    assert "k" not in e.symbol_table
    assert "v" not in e.symbol_table
    e.run("a = {k+1: v**2 for k, v in {1: 1, 2: 11, 3: 111}.items()}")
    assert e.symbol_table["a"] == {
        2: 1,
        3: 121,
        4: 12321,
    }
    assert "k" not in e.symbol_table
    assert "v" not in e.symbol_table
예제 #26
0
파일: calc_test.py 프로젝트: iCodeIN/yui
def test_dictcomp():
    e = Evaluator()
    assert e.run('{k+1: v**2 for k, v in {1: 1, 2: 11, 3: 111}.items()}') == {
        2: 1,
        3: 121,
        4: 12321,
    }
    assert 'k' not in e.symbol_table
    assert 'v' not in e.symbol_table
    e.run('a = {k+1: v**2 for k, v in {1: 1, 2: 11, 3: 111}.items()}')
    assert e.symbol_table['a'] == {
        2: 1,
        3: 121,
        4: 12321,
    }
    assert 'k' not in e.symbol_table
    assert 'v' not in e.symbol_table
예제 #27
0
파일: calc_test.py 프로젝트: iCodeIN/yui
def test_if():
    e = Evaluator()
    e.symbol_table['a'] = 1
    e.run('''
if a == 1:
    a = 2
    b = 3
''')
    assert e.symbol_table['a'] == 2
    assert e.symbol_table['b'] == 3

    e.run('''
if a == 1:
    a = 2
    b = 3
    z = 1
else:
    a = 3
    b = 4
    c = 5
''')
    assert e.symbol_table['a'] == 3
    assert e.symbol_table['b'] == 4
    assert e.symbol_table['c'] == 5
    assert 'z' not in e.symbol_table

    e.run('''
if a == 1:
    a = 2
    b = 3
    z = 1
elif a == 3:
    d = 4
    e = 5
    f = 6
else:
    a = 3
    b = 4
    c = 5
    y = 7
''')
    assert e.symbol_table['a'] == 3
    assert e.symbol_table['b'] == 4
    assert e.symbol_table['c'] == 5
    assert e.symbol_table['d'] == 4
    assert e.symbol_table['e'] == 5
    assert e.symbol_table['f'] == 6
    assert 'y' not in e.symbol_table
    assert 'z' not in e.symbol_table
예제 #28
0
파일: calc_test.py 프로젝트: u1-liquid/yui
def test_index():
    e = Evaluator()
    e.symbol_table['obj'] = GetItemSpy()
    e.run('obj[10]')
    index = e.symbol_table['obj'].queue.pop()
    assert index == 10
    e.run('obj["asdf"]')
    index = e.symbol_table['obj'].queue.pop()
    assert index == 'asdf'
예제 #29
0
파일: calc_test.py 프로젝트: iCodeIN/yui
def test_assert():
    e = Evaluator()
    err = 'You can not use assertion syntax'
    with pytest.raises(BadSyntax, match=err):
        e.run('assert True')

    with pytest.raises(BadSyntax, match=err):
        e.run('assert False')
예제 #30
0
파일: calc_test.py 프로젝트: item4/yui
def test_assert():
    e = Evaluator()
    err = "You can not use assertion syntax"
    with pytest.raises(BadSyntax, match=err):
        e.run("assert True")

    with pytest.raises(BadSyntax, match=err):
        e.run("assert False")