# HG changeset patch # User Paul Boddie # Date 1472576373 -7200 # Node ID 3dff1f10598f38384145bc7149361e5a08ab64f2 # Parent 5366b587e3facfb210dff22f937b8612e066c356 Added tests from PythonLight. diff -r 5366b587e3fa -r 3dff1f10598f tests/aliases.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/aliases.py Tue Aug 30 18:59:33 2016 +0200 @@ -0,0 +1,57 @@ +class C: + def m(self): + return 1 + +D = C # alias for C + +class E: + def m(self): + return 2 + +F = E # alias for E + +def f(): + c = C + d = D # C + cm = C.m + dm = D.m # C.m + + c = E + d = F # E + cm = E.m + dm = F.m # E.m + +Cm = C.m +Dm = D.m +Em = E.m +Fm = F.m + +def g(): + Cm = E.m + Dm = F.m # E.m + +def h(): + global Em, Fm + Em = C.m + Fm = D.m # C.m + +Ci = C() +Ei = E() + +def i(): + c = Ci + c = Ei + +def j(): + global Ei + Ei = C() + +L = [] +M = [1] + +def k(): + c = L + +def l(): + global M + M = [] diff -r 5366b587e3fa -r 3dff1f10598f tests/assign_sequence.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/assign_sequence.py Tue Aug 30 18:59:33 2016 +0200 @@ -0,0 +1,23 @@ +def f(): + l = [1, 2, 3] + x = l + a, b, c = l + d, e, f = [1, 2, 3] + +def g(x): + l = [1, 2, 3] + m = [4, l, 6] + if x: + n = l + else: + n = m + +l = [1, 2, 3] +x = l +a, b, c = l +d, e, f = [1, 2, 3] +m = [4, l, 6] +if x: + n = l +else: + n = m diff -r 5366b587e3fa -r 3dff1f10598f tests/attr_providers.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/attr_providers.py Tue Aug 30 18:59:33 2016 +0200 @@ -0,0 +1,25 @@ +class C: + def __init__(self): + self.a = 1 + + b = 2 + +class D: + def __init__(self): + self.a = 3 + self.b = 4 + +class E: + a = 5 + b = 6 + +def f(x): + return x.a, x.b + +c = C() +d = D() +e = E() + +result1 = f(c) # (1, 2) +result2 = f(d) # (3, 4) +result3 = f(e) # (5, 6) diff -r 5366b587e3fa -r 3dff1f10598f tests/chains/main.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/chains/main.py Tue Aug 30 18:59:33 2016 +0200 @@ -0,0 +1,10 @@ +import package.module + +C = package.module.Class +c = package +d = c +e = c.module +f = c.module.Class + +def t(): + x = c.module.Class diff -r 5366b587e3fa -r 3dff1f10598f tests/chains/package/module.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/chains/package/module.py Tue Aug 30 18:59:33 2016 +0200 @@ -0,0 +1,2 @@ +class Class: + pass diff -r 5366b587e3fa -r 3dff1f10598f tests/chains/package/unused.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/chains/package/unused.py Tue Aug 30 18:59:33 2016 +0200 @@ -0,0 +1,2 @@ +class Unused: + pass diff -r 5366b587e3fa -r 3dff1f10598f tests/consts.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/consts.py Tue Aug 30 18:59:33 2016 +0200 @@ -0,0 +1,12 @@ +def f(): + s = "test" + m = s.__len__ + n = "test".__len__ + +def g(): + l = [1] + m = l.__len__ + n = [1].__len__ + +f() +g() diff -r 5366b587e3fa -r 3dff1f10598f tests/contexts.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/contexts.py Tue Aug 30 18:59:33 2016 +0200 @@ -0,0 +1,33 @@ +class C: + l = [2] + s = "test" + def __init__(self, x): + self.x = x + self.y = 3 + self.z = "z" + +c = C([1]) +x = c.x +f = c.x.__len__ +result1 = f() + +y = c.l +g = c.l.__len__ +result2 = g() + +yy = C.l +gg = C.l.__len__ +result22 = gg() + +z = c.s +h = c.s.__len__ +result3 = h() + +zz = C.s +hh = C.s.__len__ +result33 = hh() + +a = c.y +b = c.z +i = c.z.__len__ +result4 = i() diff -r 5366b587e3fa -r 3dff1f10598f tests/dicts.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/dicts.py Tue Aug 30 18:59:33 2016 +0200 @@ -0,0 +1,10 @@ +def f(d): + return d.keys() + +def g(d): + for key, value in d.items(): + return value + +d = {"a" : 1, "b" : 2} +f(d) # ["a", "b"] +g(d) # either 1 or 2 diff -r 5366b587e3fa -r 3dff1f10598f tests/global_names.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/global_names.py Tue Aug 30 18:59:33 2016 +0200 @@ -0,0 +1,11 @@ +class C: + x = 3 + +def f(): + x = g.x + y = g + return y.x + +g = C +result = f() +assert result == 3 diff -r 5366b587e3fa -r 3dff1f10598f tests/inheritance_bad/A.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/inheritance_bad/A.py Tue Aug 30 18:59:33 2016 +0200 @@ -0,0 +1,4 @@ +from B import E + +class D(E): + d = 3 diff -r 5366b587e3fa -r 3dff1f10598f tests/inheritance_bad/B.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/inheritance_bad/B.py Tue Aug 30 18:59:33 2016 +0200 @@ -0,0 +1,4 @@ +from A import D + +class E(D): + e = 2 diff -r 5366b587e3fa -r 3dff1f10598f tests/inheritance_bad/main.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/inheritance_bad/main.py Tue Aug 30 18:59:33 2016 +0200 @@ -0,0 +1,1 @@ +import A diff -r 5366b587e3fa -r 3dff1f10598f tests/listcomp.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/listcomp.py Tue Aug 30 18:59:33 2016 +0200 @@ -0,0 +1,4 @@ +def f(l, y): + return [x for x in l if x > y] + +result = f([1, 2, 3], 2) diff -r 5366b587e3fa -r 3dff1f10598f tests/mutual_import/A.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/mutual_import/A.py Tue Aug 30 18:59:33 2016 +0200 @@ -0,0 +1,10 @@ +from B import C, g + +class D(C): + d = 3 + +def f(x): + return x + +def h(x): + return g(x) diff -r 5366b587e3fa -r 3dff1f10598f tests/mutual_import/B.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/mutual_import/B.py Tue Aug 30 18:59:33 2016 +0200 @@ -0,0 +1,10 @@ +from A import D, f + +class C: + c = 1 + +class E(D): + e = 2 + +def g(x): + return f(x) diff -r 5366b587e3fa -r 3dff1f10598f tests/mutual_import/main.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/mutual_import/main.py Tue Aug 30 18:59:33 2016 +0200 @@ -0,0 +1,3 @@ +import A + +A.h(A.C()) diff -r 5366b587e3fa -r 3dff1f10598f tests/nested.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/nested.py Tue Aug 30 18:59:33 2016 +0200 @@ -0,0 +1,11 @@ +a = 4 + +def f(x): + def g(y): + def h(z): + return x, y, z, a + return h + return g + +result = f(1)(2)(3) +assert result == (1, 2, 3, 4) diff -r 5366b587e3fa -r 3dff1f10598f tests/nested_bad.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/nested_bad.py Tue Aug 30 18:59:33 2016 +0200 @@ -0,0 +1,11 @@ +def f(x): + def g(y): + while 1: + def h(z): + return x, y, z, a + a = 4 # not available for h, available in Python + return h + return g + +result = f(1)(2)(3) +assert result == (1, 2, 3, 4) diff -r 5366b587e3fa -r 3dff1f10598f tests/nested_bad_conditional.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/nested_bad_conditional.py Tue Aug 30 18:59:33 2016 +0200 @@ -0,0 +1,10 @@ +a = 4 + +def f(x): + if not x: + def g(y): + return x, y, a + return g # UnboundLocalError: not defined if x is true + +result = f(1)(2) +assert result == (1, 2, 4) diff -r 5366b587e3fa -r 3dff1f10598f tests/nested_bad_python.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/nested_bad_python.py Tue Aug 30 18:59:33 2016 +0200 @@ -0,0 +1,13 @@ +a = 4 + +def f(x): + def g(): + def h(z): + return x, y, z, a + h(3) # NameError in Python + y = 2 # not available for h, detected during inspection + return h + return g + +result = f(1)()(3) +assert result == (1, 2, 3, 4) diff -r 5366b587e3fa -r 3dff1f10598f tests/nested_lambda.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/nested_lambda.py Tue Aug 30 18:59:33 2016 +0200 @@ -0,0 +1,8 @@ +a = 4 + +def f(x): + g = lambda y: lambda z: (x, y, z, a) + return g + +result = f(1)(2)(3) +assert result == (1, 2, 3, 4) diff -r 5366b587e3fa -r 3dff1f10598f tests/nested_mixed.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/nested_mixed.py Tue Aug 30 18:59:33 2016 +0200 @@ -0,0 +1,11 @@ +a = 4 + +def f(x): + def g(y): + def h(y, z): + return x, y, z, a # parameter y overrides outer scope + return h + return g + +result = f(1)(2)(5, 3) +assert result == (1, 5, 3, 4) diff -r 5366b587e3fa -r 3dff1f10598f tests/nested_mixed_names.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/nested_mixed_names.py Tue Aug 30 18:59:33 2016 +0200 @@ -0,0 +1,20 @@ +class C: + def c(self): + return 1 + +class D: + def d(self): + return 3 + +a = 4 + +def f(x): + x.c() + def g(y): # x introduced as default here + if y: + x = D() + return x.d(), y, a # UnboundLocalError in Python (if y is a false value) + return g + +result = f(C())(2) +assert result == (3, 2, 4) diff -r 5366b587e3fa -r 3dff1f10598f tests/nested_value_changed.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/nested_value_changed.py Tue Aug 30 18:59:33 2016 +0200 @@ -0,0 +1,13 @@ +a = 4 + +def f(x): + def g(): + y = 2 # used to initialise h + def h(z): + return x, y, z, a + y = 5 # Python uses this value directly from g in h + return h + return g + +result = f(1)()(3) +assert result == (1, 2, 3, 4) # (1, 5, 3, 4) in Python diff -r 5366b587e3fa -r 3dff1f10598f tests/operators.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/operators.py Tue Aug 30 18:59:33 2016 +0200 @@ -0,0 +1,7 @@ +import operator + +def f(a, op, b): + return op(a, b) + +f(1, operator.add, 2) +f(1, operator.sub, 2)