def test_MConst():
    data = ("a", MConst(2), MConst(2) * 3)
    cdata = MConst(data)
    value = cdata.evaluate()
    print(cdata, value)
    assert value == ("a", 2, 6)
    assert isinstance(value[0], str)
    assert isinstance(value[1], int)
    assert isinstance(value[2], int)
Beispiel #2
0
def test_str_method0(smethod0, sval1):
    vm = getattr(sval1, smethod0)
    e = MConst(sval1)
    em = getattr(e, smethod0)
    assert vm is not em
    emv = em().evaluate()
    assert vm() == emv
Beispiel #3
0
Param = collections.namedtuple('Param', ('de', 'expression', 'globals_d'))


def myfun1(a, b, c):
    return a + b // c


def myfun2(a, b, c):
    return a - b + c


y_20 = 20
y_10 = 10

MYFUN = MName("myfun")
X = MConst(10)
Y = MName('y')
Z = MConst(4)

Param = collections.namedtuple('Param', ('globals_d', 'expression'))
_data = [
    Param(globals_d={
        'myfun': myfun1,
        'y': y_20
    },
          expression="myfun(10, c=4, b=y)"),
    Param(globals_d={
        'myfun': myfun2,
        'y': y_20
    },
          expression="myfun(10, c=4, b=y)"),
Beispiel #4
0
def test_int_binary_vl(iop2, ival2):
    l, r = ival2
    e = iop2(MConst(l), r)
    assert e.evaluate() == iop2(l, r)
Beispiel #5
0
def test_float_unary(fop1, fval1):
    e = fop1(MConst(fval1))
    assert isinstance(e, Macro)
    assert e.evaluate() == fop1(fval1)
Beispiel #6
0
def test_int_unary(iop1, ival1):
    e = iop1(MConst(ival1))
    assert isinstance(e, Macro)
    assert e.evaluate() == iop1(ival1)
Beispiel #7
0
def test_float_binary_vlr(fop2, fval2):
    l, r = fval2
    e = fop2(MConst(l), MConst(r))
    assert e.evaluate() == fop2(l, r)
Beispiel #8
0
def test_int_binary_vr(iop2, ival2):
    l, r = ival2
    e = iop2(l, MConst(r))
    assert e.evaluate() == iop2(l, r)
Beispiel #9
0
def test_str_method_join():
    s = ', '
    l = ['a', ' b ', 'cde', '12']
    e = MConst(s)
    em = e.join(l)
    assert s.join(l) == em.evaluate()
Beispiel #10
0
def test_str_binary_vlr(sop2, sval2):
    l, r = sval2
    e = sop2(MConst(l), MConst(r))
    assert e.evaluate() == sop2(l, r)
Beispiel #11
0
def test_str_unary(sop1, sval1):
    e = sop1(MConst(sval1))
    assert isinstance(e, Macro)
    assert e.evaluate() == sop1(sval1)
Beispiel #12
0
def test_str_method_join():
    s = ', '
    l = ['a', ' b ', 'cde', '12']
    e = MConst(s)
    em = e.join(l)
    assert s.join(l) == em.evaluate()
Beispiel #13
0
def test_bool_binary_vlr(bop2, bval2):
    l, r = bval2
    e = bop2(MConst(l), MConst(r))
    assert e.evaluate() == bop2(l, r)
Beispiel #14
0
def test_bool_unary(bop1, bval1):
    e = bop1(MConst(bval1))
    assert isinstance(e, Macro)
    assert e.evaluate() == bop1(bval1)