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)
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
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)"),
def test_int_binary_vl(iop2, ival2): l, r = ival2 e = iop2(MConst(l), r) assert e.evaluate() == iop2(l, r)
def test_float_unary(fop1, fval1): e = fop1(MConst(fval1)) assert isinstance(e, Macro) assert e.evaluate() == fop1(fval1)
def test_int_unary(iop1, ival1): e = iop1(MConst(ival1)) assert isinstance(e, Macro) assert e.evaluate() == iop1(ival1)
def test_float_binary_vlr(fop2, fval2): l, r = fval2 e = fop2(MConst(l), MConst(r)) assert e.evaluate() == fop2(l, r)
def test_int_binary_vr(iop2, ival2): l, r = ival2 e = iop2(l, MConst(r)) assert e.evaluate() == iop2(l, r)
def test_str_method_join(): s = ', ' l = ['a', ' b ', 'cde', '12'] e = MConst(s) em = e.join(l) assert s.join(l) == em.evaluate()
def test_str_binary_vlr(sop2, sval2): l, r = sval2 e = sop2(MConst(l), MConst(r)) assert e.evaluate() == sop2(l, r)
def test_str_unary(sop1, sval1): e = sop1(MConst(sval1)) assert isinstance(e, Macro) assert e.evaluate() == sop1(sval1)
def test_bool_binary_vlr(bop2, bval2): l, r = bval2 e = bop2(MConst(l), MConst(r)) assert e.evaluate() == bop2(l, r)
def test_bool_unary(bop1, bval1): e = bop1(MConst(bval1)) assert isinstance(e, Macro) assert e.evaluate() == bop1(bval1)