From 8c3858b01623f9527b57b13c44ff97c67bafb00b Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 19 Jan 2014 18:41:55 +0200 Subject: Move tests in basic/tests/ up one level preparating to multiple test dirs. --- tests/basics/0prelim.py | 4 ++ tests/basics/builtin-len1.py | 13 +++++ tests/basics/class-subclass-builtin.py | 6 +++ tests/basics/class1.py | 28 ++++++++++ tests/basics/class2.py | 17 ++++++ tests/basics/class3.py | 24 +++++++++ tests/basics/class_inherit1.py | 21 ++++++++ tests/basics/class_item.py | 13 +++++ tests/basics/class_number.py | 15 ++++++ tests/basics/class_store.py | 17 ++++++ tests/basics/closure1.py | 16 ++++++ tests/basics/closure2.py | 16 ++++++ tests/basics/comprehension1.py | 20 +++++++ tests/basics/containment.py | 23 ++++++++ tests/basics/dict1.py | 18 +++++++ tests/basics/dict2.py | 10 ++++ tests/basics/dict_clear.py | 6 +++ tests/basics/dict_copy.py | 5 ++ tests/basics/dict_fromkeys.py | 10 ++++ tests/basics/dict_get.py | 3 ++ tests/basics/dict_iterator.py | 3 ++ tests/basics/dict_pop.py | 12 +++++ tests/basics/dict_popitem.py | 11 ++++ tests/basics/dict_setdefault.py | 13 +++++ tests/basics/dict_update.py | 10 ++++ tests/basics/dict_views.py | 6 +++ tests/basics/enumerate.py | 6 +++ tests/basics/eval1.py | 13 +++++ tests/basics/exception1.py | 9 ++++ tests/basics/filter.py | 2 + tests/basics/float1.py | 3 ++ tests/basics/for1.py | 19 +++++++ tests/basics/fun1.py | 5 ++ tests/basics/fun2.py | 10 ++++ tests/basics/fun3.py | 6 +++ tests/basics/generator1.py | 22 ++++++++ tests/basics/generator2.py | 3 ++ tests/basics/import1a.py | 2 + tests/basics/import1b.py | 1 + tests/basics/int-small.py | 26 +++++++++ tests/basics/int1.py | 74 ++++++++++++++++++++++++++ tests/basics/is-isnot.py | 14 +++++ tests/basics/lambda1.py | 4 ++ tests/basics/list1.py | 18 +++++++ tests/basics/list_clear.py | 4 ++ tests/basics/list_compare.py | 50 +++++++++++++++++ tests/basics/list_copy.py | 7 +++ tests/basics/list_count.py | 6 +++ tests/basics/list_index.py | 24 +++++++++ tests/basics/list_insert.py | 9 ++++ tests/basics/list_mult.py | 4 ++ tests/basics/list_pop.py | 11 ++++ tests/basics/list_remove.py | 9 ++++ tests/basics/list_reverse.py | 5 ++ tests/basics/list_sort.py | 13 +++++ tests/basics/list_sum.py | 5 ++ tests/basics/map.py | 4 ++ tests/basics/run-tests | 48 ----------------- tests/basics/set1.py | 7 +++ tests/basics/set_add.py | 5 ++ tests/basics/set_binop.py | 30 +++++++++++ tests/basics/set_clear.py | 3 ++ tests/basics/set_copy.py | 8 +++ tests/basics/set_difference.py | 21 ++++++++ tests/basics/set_discard.py | 3 ++ tests/basics/set_intersection.py | 12 +++++ tests/basics/set_isdisjoint.py | 6 +++ tests/basics/set_isfooset.py | 5 ++ tests/basics/set_iter.py | 5 ++ tests/basics/set_pop.py | 9 ++++ tests/basics/set_remove.py | 9 ++++ tests/basics/set_symmetric_difference.py | 7 +++ tests/basics/set_union.py | 1 + tests/basics/set_update.py | 12 +++++ tests/basics/sorted.py | 2 + tests/basics/string-format.py | 8 +++ tests/basics/string-slice.py | 32 +++++++++++ tests/basics/string1.py | 19 +++++++ tests/basics/string_find.py | 11 ++++ tests/basics/tests/0prelim.py | 4 -- tests/basics/tests/builtin-len1.py | 13 ----- tests/basics/tests/class-subclass-builtin.py | 6 --- tests/basics/tests/class1.py | 28 ---------- tests/basics/tests/class2.py | 17 ------ tests/basics/tests/class3.py | 24 --------- tests/basics/tests/class_inherit1.py | 21 -------- tests/basics/tests/class_item.py | 13 ----- tests/basics/tests/class_number.py | 15 ------ tests/basics/tests/class_store.py | 17 ------ tests/basics/tests/closure1.py | 16 ------ tests/basics/tests/closure2.py | 16 ------ tests/basics/tests/comprehension1.py | 20 ------- tests/basics/tests/containment.py | 23 -------- tests/basics/tests/dict1.py | 18 ------- tests/basics/tests/dict2.py | 10 ---- tests/basics/tests/dict_clear.py | 6 --- tests/basics/tests/dict_copy.py | 5 -- tests/basics/tests/dict_fromkeys.py | 10 ---- tests/basics/tests/dict_get.py | 3 -- tests/basics/tests/dict_iterator.py | 3 -- tests/basics/tests/dict_pop.py | 12 ----- tests/basics/tests/dict_popitem.py | 11 ---- tests/basics/tests/dict_setdefault.py | 13 ----- tests/basics/tests/dict_update.py | 10 ---- tests/basics/tests/dict_views.py | 6 --- tests/basics/tests/enumerate.py | 6 --- tests/basics/tests/eval1.py | 13 ----- tests/basics/tests/exception1.py | 9 ---- tests/basics/tests/filter.py | 2 - tests/basics/tests/float1.py | 3 -- tests/basics/tests/for1.py | 19 ------- tests/basics/tests/fun1.py | 5 -- tests/basics/tests/fun2.py | 10 ---- tests/basics/tests/fun3.py | 6 --- tests/basics/tests/generator1.py | 22 -------- tests/basics/tests/generator2.py | 3 -- tests/basics/tests/import1a.py | 2 - tests/basics/tests/import1b.py | 1 - tests/basics/tests/int-small.py | 26 --------- tests/basics/tests/int1.py | 74 -------------------------- tests/basics/tests/is-isnot.py | 14 ----- tests/basics/tests/lambda1.py | 4 -- tests/basics/tests/list1.py | 18 ------- tests/basics/tests/list_clear.py | 4 -- tests/basics/tests/list_compare.py | 50 ----------------- tests/basics/tests/list_copy.py | 7 --- tests/basics/tests/list_count.py | 6 --- tests/basics/tests/list_index.py | 24 --------- tests/basics/tests/list_insert.py | 9 ---- tests/basics/tests/list_mult.py | 4 -- tests/basics/tests/list_pop.py | 11 ---- tests/basics/tests/list_remove.py | 9 ---- tests/basics/tests/list_reverse.py | 5 -- tests/basics/tests/list_sort.py | 13 ----- tests/basics/tests/list_sum.py | 5 -- tests/basics/tests/map.py | 4 -- tests/basics/tests/set1.py | 7 --- tests/basics/tests/set_add.py | 5 -- tests/basics/tests/set_binop.py | 30 ----------- tests/basics/tests/set_clear.py | 3 -- tests/basics/tests/set_copy.py | 8 --- tests/basics/tests/set_difference.py | 21 -------- tests/basics/tests/set_discard.py | 3 -- tests/basics/tests/set_intersection.py | 12 ----- tests/basics/tests/set_isdisjoint.py | 6 --- tests/basics/tests/set_isfooset.py | 5 -- tests/basics/tests/set_iter.py | 5 -- tests/basics/tests/set_pop.py | 9 ---- tests/basics/tests/set_remove.py | 9 ---- tests/basics/tests/set_symmetric_difference.py | 7 --- tests/basics/tests/set_union.py | 1 - tests/basics/tests/set_update.py | 12 ----- tests/basics/tests/sorted.py | 2 - tests/basics/tests/string-format.py | 8 --- tests/basics/tests/string-slice.py | 32 ----------- tests/basics/tests/string1.py | 19 ------- tests/basics/tests/string_find.py | 11 ---- tests/basics/tests/true-value.py | 27 ---------- tests/basics/tests/try1.py | 11 ---- tests/basics/tests/try2.py | 12 ----- tests/basics/tests/try3.py | 17 ------ tests/basics/tests/try4.py | 21 -------- tests/basics/tests/types1.py | 28 ---------- tests/basics/tests/while1.py | 12 ----- tests/basics/tests/zip.py | 2 - tests/basics/true-value.py | 27 ++++++++++ tests/basics/try1.py | 11 ++++ tests/basics/try2.py | 12 +++++ tests/basics/try3.py | 17 ++++++ tests/basics/try4.py | 21 ++++++++ tests/basics/types1.py | 28 ++++++++++ tests/basics/while1.py | 12 +++++ tests/basics/zip.py | 2 + tests/run-tests | 48 +++++++++++++++++ 174 files changed, 1121 insertions(+), 1121 deletions(-) create mode 100644 tests/basics/0prelim.py create mode 100644 tests/basics/builtin-len1.py create mode 100644 tests/basics/class-subclass-builtin.py create mode 100644 tests/basics/class1.py create mode 100644 tests/basics/class2.py create mode 100644 tests/basics/class3.py create mode 100644 tests/basics/class_inherit1.py create mode 100644 tests/basics/class_item.py create mode 100644 tests/basics/class_number.py create mode 100644 tests/basics/class_store.py create mode 100644 tests/basics/closure1.py create mode 100644 tests/basics/closure2.py create mode 100644 tests/basics/comprehension1.py create mode 100644 tests/basics/containment.py create mode 100644 tests/basics/dict1.py create mode 100644 tests/basics/dict2.py create mode 100644 tests/basics/dict_clear.py create mode 100644 tests/basics/dict_copy.py create mode 100644 tests/basics/dict_fromkeys.py create mode 100644 tests/basics/dict_get.py create mode 100644 tests/basics/dict_iterator.py create mode 100644 tests/basics/dict_pop.py create mode 100644 tests/basics/dict_popitem.py create mode 100644 tests/basics/dict_setdefault.py create mode 100644 tests/basics/dict_update.py create mode 100644 tests/basics/dict_views.py create mode 100644 tests/basics/enumerate.py create mode 100644 tests/basics/eval1.py create mode 100644 tests/basics/exception1.py create mode 100644 tests/basics/filter.py create mode 100644 tests/basics/float1.py create mode 100644 tests/basics/for1.py create mode 100644 tests/basics/fun1.py create mode 100644 tests/basics/fun2.py create mode 100644 tests/basics/fun3.py create mode 100644 tests/basics/generator1.py create mode 100644 tests/basics/generator2.py create mode 100644 tests/basics/import1a.py create mode 100644 tests/basics/import1b.py create mode 100644 tests/basics/int-small.py create mode 100644 tests/basics/int1.py create mode 100644 tests/basics/is-isnot.py create mode 100644 tests/basics/lambda1.py create mode 100644 tests/basics/list1.py create mode 100644 tests/basics/list_clear.py create mode 100644 tests/basics/list_compare.py create mode 100644 tests/basics/list_copy.py create mode 100644 tests/basics/list_count.py create mode 100644 tests/basics/list_index.py create mode 100644 tests/basics/list_insert.py create mode 100644 tests/basics/list_mult.py create mode 100644 tests/basics/list_pop.py create mode 100644 tests/basics/list_remove.py create mode 100644 tests/basics/list_reverse.py create mode 100644 tests/basics/list_sort.py create mode 100644 tests/basics/list_sum.py create mode 100644 tests/basics/map.py delete mode 100755 tests/basics/run-tests create mode 100644 tests/basics/set1.py create mode 100644 tests/basics/set_add.py create mode 100644 tests/basics/set_binop.py create mode 100644 tests/basics/set_clear.py create mode 100644 tests/basics/set_copy.py create mode 100644 tests/basics/set_difference.py create mode 100644 tests/basics/set_discard.py create mode 100644 tests/basics/set_intersection.py create mode 100644 tests/basics/set_isdisjoint.py create mode 100644 tests/basics/set_isfooset.py create mode 100644 tests/basics/set_iter.py create mode 100644 tests/basics/set_pop.py create mode 100644 tests/basics/set_remove.py create mode 100644 tests/basics/set_symmetric_difference.py create mode 100644 tests/basics/set_union.py create mode 100644 tests/basics/set_update.py create mode 100644 tests/basics/sorted.py create mode 100644 tests/basics/string-format.py create mode 100644 tests/basics/string-slice.py create mode 100644 tests/basics/string1.py create mode 100644 tests/basics/string_find.py delete mode 100644 tests/basics/tests/0prelim.py delete mode 100644 tests/basics/tests/builtin-len1.py delete mode 100644 tests/basics/tests/class-subclass-builtin.py delete mode 100644 tests/basics/tests/class1.py delete mode 100644 tests/basics/tests/class2.py delete mode 100644 tests/basics/tests/class3.py delete mode 100644 tests/basics/tests/class_inherit1.py delete mode 100644 tests/basics/tests/class_item.py delete mode 100644 tests/basics/tests/class_number.py delete mode 100644 tests/basics/tests/class_store.py delete mode 100644 tests/basics/tests/closure1.py delete mode 100644 tests/basics/tests/closure2.py delete mode 100644 tests/basics/tests/comprehension1.py delete mode 100644 tests/basics/tests/containment.py delete mode 100644 tests/basics/tests/dict1.py delete mode 100644 tests/basics/tests/dict2.py delete mode 100644 tests/basics/tests/dict_clear.py delete mode 100644 tests/basics/tests/dict_copy.py delete mode 100644 tests/basics/tests/dict_fromkeys.py delete mode 100644 tests/basics/tests/dict_get.py delete mode 100644 tests/basics/tests/dict_iterator.py delete mode 100644 tests/basics/tests/dict_pop.py delete mode 100644 tests/basics/tests/dict_popitem.py delete mode 100644 tests/basics/tests/dict_setdefault.py delete mode 100644 tests/basics/tests/dict_update.py delete mode 100644 tests/basics/tests/dict_views.py delete mode 100644 tests/basics/tests/enumerate.py delete mode 100644 tests/basics/tests/eval1.py delete mode 100644 tests/basics/tests/exception1.py delete mode 100644 tests/basics/tests/filter.py delete mode 100644 tests/basics/tests/float1.py delete mode 100644 tests/basics/tests/for1.py delete mode 100644 tests/basics/tests/fun1.py delete mode 100644 tests/basics/tests/fun2.py delete mode 100644 tests/basics/tests/fun3.py delete mode 100644 tests/basics/tests/generator1.py delete mode 100644 tests/basics/tests/generator2.py delete mode 100644 tests/basics/tests/import1a.py delete mode 100644 tests/basics/tests/import1b.py delete mode 100644 tests/basics/tests/int-small.py delete mode 100644 tests/basics/tests/int1.py delete mode 100644 tests/basics/tests/is-isnot.py delete mode 100644 tests/basics/tests/lambda1.py delete mode 100644 tests/basics/tests/list1.py delete mode 100644 tests/basics/tests/list_clear.py delete mode 100644 tests/basics/tests/list_compare.py delete mode 100644 tests/basics/tests/list_copy.py delete mode 100644 tests/basics/tests/list_count.py delete mode 100644 tests/basics/tests/list_index.py delete mode 100644 tests/basics/tests/list_insert.py delete mode 100644 tests/basics/tests/list_mult.py delete mode 100644 tests/basics/tests/list_pop.py delete mode 100644 tests/basics/tests/list_remove.py delete mode 100644 tests/basics/tests/list_reverse.py delete mode 100644 tests/basics/tests/list_sort.py delete mode 100644 tests/basics/tests/list_sum.py delete mode 100644 tests/basics/tests/map.py delete mode 100644 tests/basics/tests/set1.py delete mode 100644 tests/basics/tests/set_add.py delete mode 100644 tests/basics/tests/set_binop.py delete mode 100644 tests/basics/tests/set_clear.py delete mode 100644 tests/basics/tests/set_copy.py delete mode 100644 tests/basics/tests/set_difference.py delete mode 100644 tests/basics/tests/set_discard.py delete mode 100644 tests/basics/tests/set_intersection.py delete mode 100644 tests/basics/tests/set_isdisjoint.py delete mode 100644 tests/basics/tests/set_isfooset.py delete mode 100644 tests/basics/tests/set_iter.py delete mode 100644 tests/basics/tests/set_pop.py delete mode 100644 tests/basics/tests/set_remove.py delete mode 100644 tests/basics/tests/set_symmetric_difference.py delete mode 100644 tests/basics/tests/set_union.py delete mode 100644 tests/basics/tests/set_update.py delete mode 100644 tests/basics/tests/sorted.py delete mode 100644 tests/basics/tests/string-format.py delete mode 100644 tests/basics/tests/string-slice.py delete mode 100644 tests/basics/tests/string1.py delete mode 100644 tests/basics/tests/string_find.py delete mode 100644 tests/basics/tests/true-value.py delete mode 100644 tests/basics/tests/try1.py delete mode 100644 tests/basics/tests/try2.py delete mode 100644 tests/basics/tests/try3.py delete mode 100644 tests/basics/tests/try4.py delete mode 100644 tests/basics/tests/types1.py delete mode 100644 tests/basics/tests/while1.py delete mode 100644 tests/basics/tests/zip.py create mode 100644 tests/basics/true-value.py create mode 100644 tests/basics/try1.py create mode 100644 tests/basics/try2.py create mode 100644 tests/basics/try3.py create mode 100644 tests/basics/try4.py create mode 100644 tests/basics/types1.py create mode 100644 tests/basics/while1.py create mode 100644 tests/basics/zip.py create mode 100755 tests/run-tests (limited to 'tests') diff --git a/tests/basics/0prelim.py b/tests/basics/0prelim.py new file mode 100644 index 000000000..2da65dc27 --- /dev/null +++ b/tests/basics/0prelim.py @@ -0,0 +1,4 @@ +# all tests need print to work! make sure it does work + +print(1) +print('abc') diff --git a/tests/basics/builtin-len1.py b/tests/basics/builtin-len1.py new file mode 100644 index 000000000..6a082394c --- /dev/null +++ b/tests/basics/builtin-len1.py @@ -0,0 +1,13 @@ +# builtin len + +print(len(())) +print(len((1,))) +print(len((1, 2))) + +print(len([])) +x = [1, 2, 3] +print(len(x)) + +f = len +print(f({})) +print(f({1:2, 3:4})) diff --git a/tests/basics/class-subclass-builtin.py b/tests/basics/class-subclass-builtin.py new file mode 100644 index 000000000..7eb7d44b4 --- /dev/null +++ b/tests/basics/class-subclass-builtin.py @@ -0,0 +1,6 @@ +#class mylist(list): +# pass + +#l = mylist() +#l.append(1) +#print(l) diff --git a/tests/basics/class1.py b/tests/basics/class1.py new file mode 100644 index 000000000..bf5f08e64 --- /dev/null +++ b/tests/basics/class1.py @@ -0,0 +1,28 @@ +# basic class + +def go(): + class C: + def f(): + print(1) + + def g(self): + print(2) + + def set(self, value): + self.value = value + + def print(self): + print(self.value) + + C.f() + C() + C().g() + + o = C() + o.set(3) + o.print() + + C.set(o, 4) + C.print(o) + +go() diff --git a/tests/basics/class2.py b/tests/basics/class2.py new file mode 100644 index 000000000..64f1f62b9 --- /dev/null +++ b/tests/basics/class2.py @@ -0,0 +1,17 @@ +# class with __init__ + +class C1: + def __init__(self): + self.x = 1 + +c1 = C1() +print(type(c1) == C1) +print(c1.x) + +class C2: + def __init__(self, x): + self.x = x + +c2 = C2(4) +print(type(c2) == C2) +print(c2.x) diff --git a/tests/basics/class3.py b/tests/basics/class3.py new file mode 100644 index 000000000..3b4f0bb90 --- /dev/null +++ b/tests/basics/class3.py @@ -0,0 +1,24 @@ +# inheritance + +class A: + def a(): + print('A.a() called') + +class B(A): + pass + +print(type(A)) +print(type(B)) + +print(issubclass(A, A)) +print(issubclass(A, B)) +print(issubclass(B, A)) +print(issubclass(B, B)) + +print(isinstance(A(), A)) +print(isinstance(A(), B)) +print(isinstance(B(), A)) +print(isinstance(B(), B)) + +A.a() +B.a() diff --git a/tests/basics/class_inherit1.py b/tests/basics/class_inherit1.py new file mode 100644 index 000000000..9ca2d9f14 --- /dev/null +++ b/tests/basics/class_inherit1.py @@ -0,0 +1,21 @@ +class A: + def __init__(self, x): + print('A init', x) + self.x = x + + def f(self): + print(self.x, self.y) + +class B(A): + def __init__(self, x, y): + A.__init__(self, x) + print('B init', x, y) + self.y = y + + def g(self): + print(self.x, self.y) + +A(1) +b = B(1, 2) +b.f() +b.g() diff --git a/tests/basics/class_item.py b/tests/basics/class_item.py new file mode 100644 index 000000000..6061f2607 --- /dev/null +++ b/tests/basics/class_item.py @@ -0,0 +1,13 @@ +# test class with __getitem__ and __setitem__ methods + +class C: + def __getitem__(self, item): + print('get', item) + return 'item' + + def __setitem__(self, item, value): + print('set', item, value) + +c = C() +print(c[1]) +c[1] = 2 diff --git a/tests/basics/class_number.py b/tests/basics/class_number.py new file mode 100644 index 000000000..e1dbf4a26 --- /dev/null +++ b/tests/basics/class_number.py @@ -0,0 +1,15 @@ +# test class with __add__ and __sub__ methods + +class C: + def __init__(self, value): + self.value = value + + def __add__(self, rhs): + print(self.value, '+', rhs) + + def __sub__(self, rhs): + print(self.value, '-', rhs) + +c = C(0) +c + 1 +c - 2 diff --git a/tests/basics/class_store.py b/tests/basics/class_store.py new file mode 100644 index 000000000..658da451b --- /dev/null +++ b/tests/basics/class_store.py @@ -0,0 +1,17 @@ +# store to class vs instance + +class C: + pass + +c = C() +c.x = 1 +print(c.x) +C.x = 2 +C.y = 3 +print(c.x, c.y) +print(C.x, C.y) +print(C().x, C().y) +c = C() +print(c.x) +c.x = 4 +print(c.x) diff --git a/tests/basics/closure1.py b/tests/basics/closure1.py new file mode 100644 index 000000000..610cb7002 --- /dev/null +++ b/tests/basics/closure1.py @@ -0,0 +1,16 @@ +# closures + +def f(x): + y = 2 * x + def g(z): + return y + z + return g + +print(f(1)(1)) + +x = f(2) +y = f(3) +print(x(1), x(2), x(3)) +print(y(1), y(2), y(3)) +print(x(1), x(2), x(3)) +print(y(1), y(2), y(3)) diff --git a/tests/basics/closure2.py b/tests/basics/closure2.py new file mode 100644 index 000000000..e4e5154a9 --- /dev/null +++ b/tests/basics/closure2.py @@ -0,0 +1,16 @@ +# closures; closing over an argument + +def f(x): + y = 2 * x + def g(z): + return x + y + z + return g + +print(f(1)(1)) + +x = f(2) +y = f(3) +print(x(1), x(2), x(3)) +print(y(1), y(2), y(3)) +print(x(1), x(2), x(3)) +print(y(1), y(2), y(3)) diff --git a/tests/basics/comprehension1.py b/tests/basics/comprehension1.py new file mode 100644 index 000000000..7f541ee53 --- /dev/null +++ b/tests/basics/comprehension1.py @@ -0,0 +1,20 @@ +def f(): + # list comprehension + + print([a + 1 for a in range(5)]) + print([(a, b) for a in range(3) for b in range(2)]) + print([a * 2 for a in range(7) if a > 3]) + + print([a for a in [1, 3, 5]]) + print([a for a in [a for a in range(4)]]) + + # dict comprehension + + d = {a : 2 * a for a in range(5)} + print(d[0], d[1], d[2], d[3], d[4]) + + # set comprehension + + print({a for a in range(5)}) + +f() diff --git a/tests/basics/containment.py b/tests/basics/containment.py new file mode 100644 index 000000000..84d40b4e8 --- /dev/null +++ b/tests/basics/containment.py @@ -0,0 +1,23 @@ +for i in 1, 2: + for o in {1:2}, {1}, {1:2}.keys(): + print("{} in {}: {}".format(i, o, i in o)) + print("{} not in {}: {}".format(i, o, i not in o)) + +haystack = "supercalifragilistc" +for needle in (haystack[i:] for i in range(len(haystack))): + print(needle, "in", haystack, "::", needle in haystack) + print(needle, "not in", haystack, "::", needle not in haystack) + print(haystack, "in", needle, "::", haystack in needle) + print(haystack, "not in", needle, "::", haystack not in needle) +for needle in (haystack[:i+1] for i in range(len(haystack))): + print(needle, "in", haystack, "::", needle in haystack) + print(needle, "not in", haystack, "::", needle not in haystack) + print(haystack, "in", needle, "::", haystack in needle) + print(haystack, "not in", needle, "::", haystack not in needle) + +# until here, the tests would work without the 'second attempt' iteration thing. + +for i in 1, 2: + for o in [], [1], [1, 2]: + print("{} in {}: {}".format(i, o, i in o)) + print("{} not in {}: {}".format(i, o, i not in o)) diff --git a/tests/basics/dict1.py b/tests/basics/dict1.py new file mode 100644 index 000000000..1356cd428 --- /dev/null +++ b/tests/basics/dict1.py @@ -0,0 +1,18 @@ +# basic dictionary + +d = {} +print(d) +d[2] = 123 +print(d) +d = {1:2} +d[3] = 3 +print(d) +d[1] = 0 +print(d) +print(d[1]) + +x = 1 +while x < 1000: + d[x] = x + x += 1 +print(d[500]) diff --git a/tests/basics/dict2.py b/tests/basics/dict2.py new file mode 100644 index 000000000..1d5aae576 --- /dev/null +++ b/tests/basics/dict2.py @@ -0,0 +1,10 @@ +# using strings as keys in dict + +d = {'1': 1, '2': 2} +print(d['1'], d['2']) + +d['3'] = 3 +print(d['1'], d['2'], d['3']) + +d['2'] = 222 +print(d['1'], d['2'], d['3']) diff --git a/tests/basics/dict_clear.py b/tests/basics/dict_clear.py new file mode 100644 index 000000000..6be2778be --- /dev/null +++ b/tests/basics/dict_clear.py @@ -0,0 +1,6 @@ +d = {1: 2, 3: 4} +print(d) +d.clear() +print(d) +d[2] = 42 +print(d) diff --git a/tests/basics/dict_copy.py b/tests/basics/dict_copy.py new file mode 100644 index 000000000..c3eb7ffc1 --- /dev/null +++ b/tests/basics/dict_copy.py @@ -0,0 +1,5 @@ +a = {i: 2*i for i in range(1000)} +b = a.copy() +for i in range(1000): + print(i, b[i]) +print(len(b)) diff --git a/tests/basics/dict_fromkeys.py b/tests/basics/dict_fromkeys.py new file mode 100644 index 000000000..d03f6ae9d --- /dev/null +++ b/tests/basics/dict_fromkeys.py @@ -0,0 +1,10 @@ +d = dict.fromkeys([1, 2, 3, 4]) +l = list(d.keys()) +l.sort() +print(l) + +d = dict.fromkeys([1, 2, 3, 4], 42) +l = list(d.values()) +l.sort() +print(l) + diff --git a/tests/basics/dict_get.py b/tests/basics/dict_get.py new file mode 100644 index 000000000..fb43a45ea --- /dev/null +++ b/tests/basics/dict_get.py @@ -0,0 +1,3 @@ +for d in {}, {42:2}: + print(d.get(42)) + print(d.get(42,2)) diff --git a/tests/basics/dict_iterator.py b/tests/basics/dict_iterator.py new file mode 100644 index 000000000..f190e32ff --- /dev/null +++ b/tests/basics/dict_iterator.py @@ -0,0 +1,3 @@ +d = {1: 2, 3: 4} +for i in d: + print(i, d[i]) diff --git a/tests/basics/dict_pop.py b/tests/basics/dict_pop.py new file mode 100644 index 000000000..602560ce9 --- /dev/null +++ b/tests/basics/dict_pop.py @@ -0,0 +1,12 @@ +d = {1: 2, 3: 4} +print(d.pop(3), d) +print(d) +print(d.pop(1, 42), d) +print(d.pop(1, 42), d) +print(d.pop(1, None), d) +try: + print(d.pop(1), "!!!",) +except KeyError: + print("Raised KeyError") +else: + print("Did not rise KeyError!") diff --git a/tests/basics/dict_popitem.py b/tests/basics/dict_popitem.py new file mode 100644 index 000000000..184735cde --- /dev/null +++ b/tests/basics/dict_popitem.py @@ -0,0 +1,11 @@ +d={1:2,3:4} +print(d.popitem()) +print(d) +print(d.popitem()) +print(d) +try: + print(d.popitem(), "!!!",) +except KeyError: + print("Raised KeyError") +else: + print("Did not raise KeyError") diff --git a/tests/basics/dict_setdefault.py b/tests/basics/dict_setdefault.py new file mode 100644 index 000000000..57d0ba451 --- /dev/null +++ b/tests/basics/dict_setdefault.py @@ -0,0 +1,13 @@ +d = {} +print(d.setdefault(1)) +print(d.setdefault(1)) +print(d.setdefault(5, 42)) +print(d.setdefault(5, 1)) +print(d[1]) +print(d[5]) +d.pop(5) +print(d.setdefault(5, 1)) +print(d[1]) +print(d[5]) + + diff --git a/tests/basics/dict_update.py b/tests/basics/dict_update.py new file mode 100644 index 000000000..e7ae0bd96 --- /dev/null +++ b/tests/basics/dict_update.py @@ -0,0 +1,10 @@ +d = {1:2, 3:4} +print(d) +d.update(["ab"]) +print(d[1]) +print(d[3]) +print(d["a"]) +print(len(d)) +d.update([(1,4)]) +print(d[1]) +print(len(d)) diff --git a/tests/basics/dict_views.py b/tests/basics/dict_views.py new file mode 100644 index 000000000..fbf63fa0a --- /dev/null +++ b/tests/basics/dict_views.py @@ -0,0 +1,6 @@ +d = {1: 2} +for m in d.items, d.values, d.keys: + print(m()) + print(list(m())) + +# set operations still to come diff --git a/tests/basics/enumerate.py b/tests/basics/enumerate.py new file mode 100644 index 000000000..f2bdf4f32 --- /dev/null +++ b/tests/basics/enumerate.py @@ -0,0 +1,6 @@ +print(list(enumerate([]))) +print(list(enumerate([1, 2, 3]))) +print(list(enumerate([1, 2, 3], 5))) +print(list(enumerate([1, 2, 3], -5))) +print(list(enumerate(range(10000)))) + diff --git a/tests/basics/eval1.py b/tests/basics/eval1.py new file mode 100644 index 000000000..8b9d02e61 --- /dev/null +++ b/tests/basics/eval1.py @@ -0,0 +1,13 @@ +# builtin eval + +eval('1 + 2') +eval('1 + 2\n') +eval('1 + 2\n\n#comment\n') + +x = 4 +eval('x') + +eval('lambda x: x + 10')(-5) + +y = 6 +eval('lambda: y * 2')() diff --git a/tests/basics/exception1.py b/tests/basics/exception1.py new file mode 100644 index 000000000..71d5ad304 --- /dev/null +++ b/tests/basics/exception1.py @@ -0,0 +1,9 @@ +print(repr(IndexError())) +print(str(IndexError())) + +print(repr(IndexError("foo"))) +print(str(IndexError("foo"))) + +a = IndexError(1, "test", [100, 200]) +print(repr(a)) +print(str(a)) diff --git a/tests/basics/filter.py b/tests/basics/filter.py new file mode 100644 index 000000000..5883e3d00 --- /dev/null +++ b/tests/basics/filter.py @@ -0,0 +1,2 @@ +print(list(filter(lambda x: x & 1, range(-3, 4)))) +print(list(filter(None, range(-3, 4)))) diff --git a/tests/basics/float1.py b/tests/basics/float1.py new file mode 100644 index 000000000..200d95585 --- /dev/null +++ b/tests/basics/float1.py @@ -0,0 +1,3 @@ +# basic float +x = 1 / 2 +print(x) diff --git a/tests/basics/for1.py b/tests/basics/for1.py new file mode 100644 index 000000000..c6199416c --- /dev/null +++ b/tests/basics/for1.py @@ -0,0 +1,19 @@ +# basic for loop + +def f(): + for x in range(2): + for y in range(2): + for z in range(2): + print(x, y, z) + +f() + +# range with negative step +for i in range(3, -1, -1): + print(i) + +a = -1 +# range with non-constant step - we optimize constant steps, so this +# will be executed differently +for i in range(3, -1, a): + print(i) diff --git a/tests/basics/fun1.py b/tests/basics/fun1.py new file mode 100644 index 000000000..e12bdbe03 --- /dev/null +++ b/tests/basics/fun1.py @@ -0,0 +1,5 @@ +# calling a function + +def f(): + print(1) +f() diff --git a/tests/basics/fun2.py b/tests/basics/fun2.py new file mode 100644 index 000000000..a3c3e7bab --- /dev/null +++ b/tests/basics/fun2.py @@ -0,0 +1,10 @@ +# calling a function from a function + +def f(x): + print(x + 1) + +def g(x): + f(2 * x) + f(4 * x) + +g(3) diff --git a/tests/basics/fun3.py b/tests/basics/fun3.py new file mode 100644 index 000000000..f1458df82 --- /dev/null +++ b/tests/basics/fun3.py @@ -0,0 +1,6 @@ +# function with large number of arguments + +def fun(a, b, c, d, e, f, g): + return a + b + c * d + e * f * g + +print(fun(1, 2, 3, 4, 5, 6, 7)) diff --git a/tests/basics/generator1.py b/tests/basics/generator1.py new file mode 100644 index 000000000..d4028b0ce --- /dev/null +++ b/tests/basics/generator1.py @@ -0,0 +1,22 @@ +def f(x): + print('a') + y = x + print('b') + while y > 0: + print('c') + y -= 1 + print('d') + yield y + print('e') + print('f') + return None + +for val in f(3): + print(val) + +#gen = f(3) +#print(gen) +#print(gen.__next__()) +#print(gen.__next__()) +#print(gen.__next__()) +#print(gen.__next__()) diff --git a/tests/basics/generator2.py b/tests/basics/generator2.py new file mode 100644 index 000000000..0dfc98a2d --- /dev/null +++ b/tests/basics/generator2.py @@ -0,0 +1,3 @@ +gen = (i for i in range(10)) +for i in gen: + print(i) diff --git a/tests/basics/import1a.py b/tests/basics/import1a.py new file mode 100644 index 000000000..16b2d4d30 --- /dev/null +++ b/tests/basics/import1a.py @@ -0,0 +1,2 @@ +import import1b +print(import1b.var) diff --git a/tests/basics/import1b.py b/tests/basics/import1b.py new file mode 100644 index 000000000..80479088f --- /dev/null +++ b/tests/basics/import1b.py @@ -0,0 +1 @@ +var = 123 diff --git a/tests/basics/int-small.py b/tests/basics/int-small.py new file mode 100644 index 000000000..be338c4a4 --- /dev/null +++ b/tests/basics/int-small.py @@ -0,0 +1,26 @@ +# This test small int range for 32-bit machine + +a = 0x3fffff +print(a) +a *= 0x10 +print(a) +a *= 0x10 +print(a) +a += 0xff +print(a) +# This would overflow +#a += 1 + +a = -0x3fffff +print(a) +a *= 0x10 +print(a) +a *= 0x10 +print(a) +a -= 0xff +print(a) +# This still doesn't overflow +a -= 1 +print(a) +# This would overflow +#a -= 1 diff --git a/tests/basics/int1.py b/tests/basics/int1.py new file mode 100644 index 000000000..4ce0f9e70 --- /dev/null +++ b/tests/basics/int1.py @@ -0,0 +1,74 @@ +print(int(0)) +print(int(1)) +print(int(+1)) +print(int(-1)) + +print(int('0')) +print(int('+0')) +print(int('-0')) +print(int('1')) +print(int('+1')) +print(int('-1')) +print(int('01')) +print(int('9')) +print(int('10')) +print(int('+10')) +print(int('-10')) +print(int('12')) +print(int('-12')) +print(int('99')) +print(int('100')) +print(int('314')) +print(int(' 314')) +print(int('314 ')) +print(int(' \t\t 314 \t\t ')) +print(int(' 1 ')) +print(int(' -3 ')) + +print(int('0', 10)) +print(int('1', 10)) +print(int(' \t 1 \t ', 10)) +print(int('11', 10)) +print(int('11', 16)) +print(int('11', 8)) +print(int('11', 2)) +print(int('11', 36)) +print(int('0o123', 0)) +print(int('8388607')) +print(int('0x123', 16)) +print(int('0X123', 16)) +print(int('0o123', 8)) +print(int('0O123', 8)) +print(int('0123', 8)) +print(int('0b100', 2)) +print(int('0B100', 2)) +print(int('0100', 2)) +print(int(' \t 0o12', 8)) +print(int('0o12 \t ', 8)) + + +def test(value, base): + try: + print(int(value, base)) + except ValueError: + print('ValueError') + + +test('x', 0) +test('1x', 0) +test(' 1x', 0) +test(' 1' + chr(2) + ' ', 0) +test('', 0) +test(' ', 0) +test(' \t\t ', 0) +test("\u0200", 0) +test('0x', 16) +test('0x', 0) +test('0o', 8) +test('0o', 0) +test('0b', 2) +test('0b', 0) +test('0b2', 2) +test('0o8', 8) +test('0xg', 16) +test('1 1', 16) diff --git a/tests/basics/is-isnot.py b/tests/basics/is-isnot.py new file mode 100644 index 000000000..990190aa4 --- /dev/null +++ b/tests/basics/is-isnot.py @@ -0,0 +1,14 @@ +print(1 is 1) +print(1 is 2) +print(1 is not 1) +print(1 is not 2) + + +print([1, 2] is [1, 2]) +a = [1, 2] +b = a +print(b is a) + +# TODO: strings require special "is" handling, postponed +# until qstr refactor. +#print("a" is "a") diff --git a/tests/basics/lambda1.py b/tests/basics/lambda1.py new file mode 100644 index 000000000..06111d6a9 --- /dev/null +++ b/tests/basics/lambda1.py @@ -0,0 +1,4 @@ +# lambda + +f = lambda x, y: x + 3 * y +print(f(3, 5)) diff --git a/tests/basics/list1.py b/tests/basics/list1.py new file mode 100644 index 000000000..250a12b70 --- /dev/null +++ b/tests/basics/list1.py @@ -0,0 +1,18 @@ +# basic list functionality +x = [1, 2, 3 * 4] +print(x) +x[0] = 4 +print(x) +x[1] += -4 +print(x) +x.append(5) +print(x) +f = x.append +f(4) +print(x) + +x.extend([100, 200]) +print(x) + +x += [2, 1] +print(x) diff --git a/tests/basics/list_clear.py b/tests/basics/list_clear.py new file mode 100644 index 000000000..406d7e823 --- /dev/null +++ b/tests/basics/list_clear.py @@ -0,0 +1,4 @@ +# tests list.clear +x = [1, 2, 3, 4] +x.clear() +print(x) diff --git a/tests/basics/list_compare.py b/tests/basics/list_compare.py new file mode 100644 index 000000000..eea881424 --- /dev/null +++ b/tests/basics/list_compare.py @@ -0,0 +1,50 @@ +print([] == []) +print([] > []) +print([] < []) +print([] == [1]) +print([1] == []) +print([] > [1]) +print([1] > []) +print([] < [1]) +print([1] < []) +print([] >= [1]) +print([1] >= []) +print([] <= [1]) +print([1] <= []) + +print([1] == [1]) +print([1] != [1]) +print([1] == [2]) +print([1] == [1, 0]) + +print([1] > [1]) +print([1] > [2]) +print([2] > [1]) +print([1, 0] > [1]) +print([1, -1] > [1]) +print([1] > [1, 0]) +print([1] > [1, -1]) + +print([1] < [1]) +print([2] < [1]) +print([1] < [2]) +print([1] < [1, 0]) +print([1] < [1, -1]) +print([1, 0] < [1]) +print([1, -1] < [1]) + +print([1] >= [1]) +print([1] >= [2]) +print([2] >= [1]) +print([1, 0] >= [1]) +print([1, -1] >= [1]) +print([1] >= [1, 0]) +print([1] >= [1, -1]) + +print([1] <= [1]) +print([2] <= [1]) +print([1] <= [2]) +print([1] <= [1, 0]) +print([1] <= [1, -1]) +print([1, 0] <= [1]) +print([1, -1] <= [1]) diff --git a/tests/basics/list_copy.py b/tests/basics/list_copy.py new file mode 100644 index 000000000..bc450782e --- /dev/null +++ b/tests/basics/list_copy.py @@ -0,0 +1,7 @@ +# list copy tests +a = [1, 2, []] +b = a.copy() +a[-1].append(1) +a.append(4) +print(a) +print(b) diff --git a/tests/basics/list_count.py b/tests/basics/list_count.py new file mode 100644 index 000000000..db93b3a2f --- /dev/null +++ b/tests/basics/list_count.py @@ -0,0 +1,6 @@ +# list count tests +a = [1, 2, 3] +a = a + a + a +b = [0, 0, a, 0, a, 0] +print(a.count(2)) +print(b.count(a)) diff --git a/tests/basics/list_index.py b/tests/basics/list_index.py new file mode 100644 index 000000000..f28263fba --- /dev/null +++ b/tests/basics/list_index.py @@ -0,0 +1,24 @@ +a = [1, 2, 3] +print(a.index(1)) +print(a.index(2)) +print(a.index(3)) +print(a.index(3, 2)) +try: + print(a.index(3, 2, 2)) +except ValueError: + print("Raised ValueError") +else: + print("Did not raise ValueError") + +a = a + a +b = [0, 0, a] +print(a.index(2)) +print(b.index(a)) +print(a.index(2, 2)) + +try: + a.index(2, 2, 2) +except ValueError: + print("Raised ValueError") +else: + print("Did not raise ValueError") diff --git a/tests/basics/list_insert.py b/tests/basics/list_insert.py new file mode 100644 index 000000000..6db97cf5c --- /dev/null +++ b/tests/basics/list_insert.py @@ -0,0 +1,9 @@ +a = [1, 2, 3] +a.insert(1, 42) +print(a) +a.insert(-1, -1) +print(a) +a.insert(99, 99) +print(a) +a.insert(-99, -99) +print(a) diff --git a/tests/basics/list_mult.py b/tests/basics/list_mult.py new file mode 100644 index 000000000..ec65fbb3f --- /dev/null +++ b/tests/basics/list_mult.py @@ -0,0 +1,4 @@ +print([0] * 5) +a = [1, 2, 3] +c = a * 3 +print(c) diff --git a/tests/basics/list_pop.py b/tests/basics/list_pop.py new file mode 100644 index 000000000..bb2ccc6d6 --- /dev/null +++ b/tests/basics/list_pop.py @@ -0,0 +1,11 @@ +# list poppin' +a = [1, 2, 3] +print(a.pop()) +print(a.pop()) +print(a.pop()) +try: + print(a.pop()) +except IndexError: + print("IndexError raised") +else: + raise AssertionError("No IndexError raised") diff --git a/tests/basics/list_remove.py b/tests/basics/list_remove.py new file mode 100644 index 000000000..81b2b3d97 --- /dev/null +++ b/tests/basics/list_remove.py @@ -0,0 +1,9 @@ +a = [1, 2, 3] +print(a.remove(2)) +print(a) +try: + a.remove(2) +except ValueError: + print("Raised ValueError") +else: + raise AssertionError("Did not raise ValueError") diff --git a/tests/basics/list_reverse.py b/tests/basics/list_reverse.py new file mode 100644 index 000000000..38acf1fd6 --- /dev/null +++ b/tests/basics/list_reverse.py @@ -0,0 +1,5 @@ +a = [] +for i in range(100): + a.append(i) + a.reverse() +print(a) diff --git a/tests/basics/list_sort.py b/tests/basics/list_sort.py new file mode 100644 index 000000000..eff12b9c8 --- /dev/null +++ b/tests/basics/list_sort.py @@ -0,0 +1,13 @@ +l = [1, 3, 2, 5] +print(l) +l.sort() +print(l) +l.sort(key=lambda x: -x) +print(l) +l.sort(key=lambda x: -x, reverse=True) +print(l) +l.sort(reverse=True) +print(l) +l.sort(reverse=False) +print(l) + diff --git a/tests/basics/list_sum.py b/tests/basics/list_sum.py new file mode 100644 index 000000000..e46042b86 --- /dev/null +++ b/tests/basics/list_sum.py @@ -0,0 +1,5 @@ +# list addition +a = [1,2,3] +b = [4,5,6] +c = a + b +print(c) diff --git a/tests/basics/map.py b/tests/basics/map.py new file mode 100644 index 000000000..62dca44ed --- /dev/null +++ b/tests/basics/map.py @@ -0,0 +1,4 @@ +print(list(map(lambda x: x & 1, range(-3, 4)))) +print(list(map(abs, range(-3, 4)))) +print(list(map(set, [[i] for i in range(-3, 4)]))) +print(list(map(pow, range(4), range(4)))) diff --git a/tests/basics/run-tests b/tests/basics/run-tests deleted file mode 100755 index bc2969ae3..000000000 --- a/tests/basics/run-tests +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env bash - -RM="/bin/rm -f" -CPYTHON3=python3.3 -MP_PY=../../unix/py - -numtests=0 -numtestcases=0 -numpassed=0 -numfailed=0 -namefailed= - -for infile in tests/*.py -do - basename=`basename $infile .py` - outfile=${basename}.out - expfile=${basename}.exp - - $CPYTHON3 -B $infile > $expfile - $MP_PY $infile > $outfile - ((numtestcases = numtestcases + $(cat $expfile | wc -l))) - - diff --brief $expfile $outfile > /dev/null - - if [ $? -eq 0 ] - then - echo "pass $infile" - $RM $outfile - $RM $expfile - ((numpassed=numpassed + 1)) - else - echo "FAIL $infile" - ((numfailed=numfailed + 1)) - namefailed="$namefailed $basename" - fi - - ((numtests=numtests + 1)) -done - -echo "$numtests tests performed ($numtestcases individual testcases)" -echo "$numpassed tests passed" -if [[ $numfailed != 0 ]] -then - echo "$numfailed tests failed -$namefailed" - exit 1 -else - exit 0 -fi diff --git a/tests/basics/set1.py b/tests/basics/set1.py new file mode 100644 index 000000000..c54fbd837 --- /dev/null +++ b/tests/basics/set1.py @@ -0,0 +1,7 @@ +# basic sets + +s = {1} +print(s) + +s = {3, 4, 3, 1} +print(s) diff --git a/tests/basics/set_add.py b/tests/basics/set_add.py new file mode 100644 index 000000000..f2a372f30 --- /dev/null +++ b/tests/basics/set_add.py @@ -0,0 +1,5 @@ +s = {1, 2, 3, 4} +print(s.add(5)) +l = list(s) +l.sort() +print(l) diff --git a/tests/basics/set_binop.py b/tests/basics/set_binop.py new file mode 100644 index 000000000..d0d0b8027 --- /dev/null +++ b/tests/basics/set_binop.py @@ -0,0 +1,30 @@ +def r(s): + l = list(s) + l.sort() + return l +sets = [set(), {1}, {1, 2}, {1, 2, 3}, {2, 3}, {2, 3, 5}, {5}, {7}] +for s in sets: + for t in sets: + print(s, '|', t, '=', r(s | t)) + print(s, '^', t, '=', r(s ^ t)) + print(s, '&', t, '=', r(s & t)) + print(s, '-', t, '=', r(s - t)) + u = s.copy() + u |= t + print(s, "|=", t, '-->', r(u)) + u = s.copy() + u ^= t + print(s, "^=", t, '-->', r(u)) + u = s.copy() + u &= t + print(s, "&=", t, "-->", r(u)) + u = s.copy() + u -= t + print(s, "-=", t, "-->", r(u)) + + print(s, '==', t, '=', s == t) + print(s, '!=', t, '=', s != t) + print(s, '>', t, '=', s > t) + print(s, '>=', t, '=', s >= t) + print(s, '<', t, '=', s < t) + print(s, '<=', t, '=', s <= t) diff --git a/tests/basics/set_clear.py b/tests/basics/set_clear.py new file mode 100644 index 000000000..6fda93f0f --- /dev/null +++ b/tests/basics/set_clear.py @@ -0,0 +1,3 @@ +s = {1, 2, 3, 4} +print(s.clear()) +print(list(s)) diff --git a/tests/basics/set_copy.py b/tests/basics/set_copy.py new file mode 100644 index 000000000..2ea308b0d --- /dev/null +++ b/tests/basics/set_copy.py @@ -0,0 +1,8 @@ +s = {1, 2, 3, 4} +t = s.copy() +s.add(5) +t.add(7) +for i in s, t: + l = list(i) + l.sort() + print(l) diff --git a/tests/basics/set_difference.py b/tests/basics/set_difference.py new file mode 100644 index 000000000..26976116f --- /dev/null +++ b/tests/basics/set_difference.py @@ -0,0 +1,21 @@ +def report(s): + l = list(s) + l.sort() + print(l) + +l = [1, 2, 3, 4] +s = set(l) +outs = [s.difference(), + s.difference({1}), + s.difference({1}, [1, 2]), + s.difference({1}, {1, 2}, {2, 3})] +for out in outs: + report(out) + +s = set(l) +print(s.difference_update()) +report(s) +print(s.difference_update({1})) +report(s) +print(s.difference_update({1}, [2])) +report(s) diff --git a/tests/basics/set_discard.py b/tests/basics/set_discard.py new file mode 100644 index 000000000..baac26413 --- /dev/null +++ b/tests/basics/set_discard.py @@ -0,0 +1,3 @@ +s = {1, 2} +print(s.discard(1)) +print(list(s)) diff --git a/tests/basics/set_intersection.py b/tests/basics/set_intersection.py new file mode 100644 index 000000000..6f3dfc741 --- /dev/null +++ b/tests/basics/set_intersection.py @@ -0,0 +1,12 @@ +def report(s): + l = list(s) + l.sort() + print(l) + +s = {1, 2, 3, 4} +report(s) +report(s.intersection({1, 3})) +report(s.intersection([3, 4])) + +print(s.intersection_update([1])) +report(s) diff --git a/tests/basics/set_isdisjoint.py b/tests/basics/set_isdisjoint.py new file mode 100644 index 000000000..7fb7e769b --- /dev/null +++ b/tests/basics/set_isdisjoint.py @@ -0,0 +1,6 @@ +s = {1, 2, 3, 4} +print(s.isdisjoint({1})) +print(s.isdisjoint([2])) +print(s.isdisjoint([])) +print(s.isdisjoint({7,8,9,10})) +print(s.isdisjoint([7,8,9,1])) diff --git a/tests/basics/set_isfooset.py b/tests/basics/set_isfooset.py new file mode 100644 index 000000000..ce7952cd2 --- /dev/null +++ b/tests/basics/set_isfooset.py @@ -0,0 +1,5 @@ +sets = [set(), {1}, {1, 2, 3}, {3, 4, 5}, {5, 6, 7}] +for i in sets: + for j in sets: + print(i.issubset(j)) + print(i.issuperset(j)) diff --git a/tests/basics/set_iter.py b/tests/basics/set_iter.py new file mode 100644 index 000000000..296017730 --- /dev/null +++ b/tests/basics/set_iter.py @@ -0,0 +1,5 @@ +s = {1, 2, 3, 4} +l = list(s) +l.sort() +print(l) + diff --git a/tests/basics/set_pop.py b/tests/basics/set_pop.py new file mode 100644 index 000000000..0cd478ce2 --- /dev/null +++ b/tests/basics/set_pop.py @@ -0,0 +1,9 @@ +s = {1} +print(s.pop()) +try: + print(s.pop(), "!!!") +except KeyError: + pass +else: + print("Failed to raise KeyError") + diff --git a/tests/basics/set_remove.py b/tests/basics/set_remove.py new file mode 100644 index 000000000..208ab137f --- /dev/null +++ b/tests/basics/set_remove.py @@ -0,0 +1,9 @@ +s = {1} +print(s.remove(1)) +print(list(s)) +try: + print(s.remove(1), "!!!") +except KeyError: + pass +else: + print("failed to raise KeyError") diff --git a/tests/basics/set_symmetric_difference.py b/tests/basics/set_symmetric_difference.py new file mode 100644 index 000000000..acf298385 --- /dev/null +++ b/tests/basics/set_symmetric_difference.py @@ -0,0 +1,7 @@ +print({1,2}.symmetric_difference({2,3})) +print({1,2}.symmetric_difference([2,3])) +s = {1,2} +print(s.symmetric_difference_update({2,3})) +l = list(s) +l.sort() +print(l) diff --git a/tests/basics/set_union.py b/tests/basics/set_union.py new file mode 100644 index 000000000..2adcc972c --- /dev/null +++ b/tests/basics/set_union.py @@ -0,0 +1 @@ +print({1}.union({2})) diff --git a/tests/basics/set_update.py b/tests/basics/set_update.py new file mode 100644 index 000000000..78cd76356 --- /dev/null +++ b/tests/basics/set_update.py @@ -0,0 +1,12 @@ +def report(s): + l = list(s) + l.sort() + print(l) + +s = {1} +s.update() +report(s) +s.update([2]) +report(s) +s.update([1,3], [2,2,4]) +report(s) diff --git a/tests/basics/sorted.py b/tests/basics/sorted.py new file mode 100644 index 000000000..bbec31946 --- /dev/null +++ b/tests/basics/sorted.py @@ -0,0 +1,2 @@ +print(sorted(set(range(100)))) +print(sorted(set(range(100)), key=lambda x: x + 100*(x % 2))) diff --git a/tests/basics/string-format.py b/tests/basics/string-format.py new file mode 100644 index 000000000..ba51e0890 --- /dev/null +++ b/tests/basics/string-format.py @@ -0,0 +1,8 @@ +print("{}-{}".format(1, [4, 5])) +print("{0}-{1}".format(1, [4, 5])) +print("{:x}".format(1)) +print("{!r}".format(2)) +# TODO +#print("{1}-{0}".format(1, [4, 5])) +#print("{:x}".format(0x10)) +#print("{!r}".format("foo")) diff --git a/tests/basics/string-slice.py b/tests/basics/string-slice.py new file mode 100644 index 000000000..7538ae570 --- /dev/null +++ b/tests/basics/string-slice.py @@ -0,0 +1,32 @@ +print("123"[0:1]) + +print("123"[0:2]) + +print("123"[:1]) + +print("123"[1:]) + +# Idiom for copying sequence +print("123"[:]) + +print("123"[:-1]) + +# Weird cases +print("123"[0:0]) +print("123"[1:0]) +print("123"[1:1]) +print("123"[-1:-1]) +print("123"[-3:]) +print("123"[-3:3]) +print("123"[0:]) +print("123"[:0]) +print("123"[:-3]) +print("123"[:-4]) +# Range check testing, don't segfault, please ;-) +print("123"[:1000000]) +print("123"[1000000:]) +print("123"[:-1000000]) +print("123"[-1000000:]) +# No IndexError! +print(""[1:1]) +print(""[-1:-1]) diff --git a/tests/basics/string1.py b/tests/basics/string1.py new file mode 100644 index 000000000..3fecf799b --- /dev/null +++ b/tests/basics/string1.py @@ -0,0 +1,19 @@ +# basic strings + +x = 'abc' +print(x) + +x += 'def' +print(x) + +print('123' + "456") + +# iter +print(list('str')) + +print('123' + '789' == '123789') +print('a' + 'b' != 'a' + 'b ') + +# Not implemented so far +# print('1' + '2' > '2') +# print('1' + '2' < '2') diff --git a/tests/basics/string_find.py b/tests/basics/string_find.py new file mode 100644 index 000000000..90063228f --- /dev/null +++ b/tests/basics/string_find.py @@ -0,0 +1,11 @@ +print("hello world".find("ll")) +print("hello world".find("ll", None)) +print("hello world".find("ll", 1)) +print("hello world".find("ll", 1, None)) +print("hello world".find("ll", None, None)) +print("hello world".find("ll", 1, -1)) +print("hello world".find("ll", 1, 1)) +print("hello world".find("ll", 1, 2)) +print("hello world".find("ll", 1, 3)) +print("hello world".find("ll", 1, 4)) +print("hello world".find("ll", 1, 5)) diff --git a/tests/basics/tests/0prelim.py b/tests/basics/tests/0prelim.py deleted file mode 100644 index 2da65dc27..000000000 --- a/tests/basics/tests/0prelim.py +++ /dev/null @@ -1,4 +0,0 @@ -# all tests need print to work! make sure it does work - -print(1) -print('abc') diff --git a/tests/basics/tests/builtin-len1.py b/tests/basics/tests/builtin-len1.py deleted file mode 100644 index 6a082394c..000000000 --- a/tests/basics/tests/builtin-len1.py +++ /dev/null @@ -1,13 +0,0 @@ -# builtin len - -print(len(())) -print(len((1,))) -print(len((1, 2))) - -print(len([])) -x = [1, 2, 3] -print(len(x)) - -f = len -print(f({})) -print(f({1:2, 3:4})) diff --git a/tests/basics/tests/class-subclass-builtin.py b/tests/basics/tests/class-subclass-builtin.py deleted file mode 100644 index 7eb7d44b4..000000000 --- a/tests/basics/tests/class-subclass-builtin.py +++ /dev/null @@ -1,6 +0,0 @@ -#class mylist(list): -# pass - -#l = mylist() -#l.append(1) -#print(l) diff --git a/tests/basics/tests/class1.py b/tests/basics/tests/class1.py deleted file mode 100644 index bf5f08e64..000000000 --- a/tests/basics/tests/class1.py +++ /dev/null @@ -1,28 +0,0 @@ -# basic class - -def go(): - class C: - def f(): - print(1) - - def g(self): - print(2) - - def set(self, value): - self.value = value - - def print(self): - print(self.value) - - C.f() - C() - C().g() - - o = C() - o.set(3) - o.print() - - C.set(o, 4) - C.print(o) - -go() diff --git a/tests/basics/tests/class2.py b/tests/basics/tests/class2.py deleted file mode 100644 index 64f1f62b9..000000000 --- a/tests/basics/tests/class2.py +++ /dev/null @@ -1,17 +0,0 @@ -# class with __init__ - -class C1: - def __init__(self): - self.x = 1 - -c1 = C1() -print(type(c1) == C1) -print(c1.x) - -class C2: - def __init__(self, x): - self.x = x - -c2 = C2(4) -print(type(c2) == C2) -print(c2.x) diff --git a/tests/basics/tests/class3.py b/tests/basics/tests/class3.py deleted file mode 100644 index 3b4f0bb90..000000000 --- a/tests/basics/tests/class3.py +++ /dev/null @@ -1,24 +0,0 @@ -# inheritance - -class A: - def a(): - print('A.a() called') - -class B(A): - pass - -print(type(A)) -print(type(B)) - -print(issubclass(A, A)) -print(issubclass(A, B)) -print(issubclass(B, A)) -print(issubclass(B, B)) - -print(isinstance(A(), A)) -print(isinstance(A(), B)) -print(isinstance(B(), A)) -print(isinstance(B(), B)) - -A.a() -B.a() diff --git a/tests/basics/tests/class_inherit1.py b/tests/basics/tests/class_inherit1.py deleted file mode 100644 index 9ca2d9f14..000000000 --- a/tests/basics/tests/class_inherit1.py +++ /dev/null @@ -1,21 +0,0 @@ -class A: - def __init__(self, x): - print('A init', x) - self.x = x - - def f(self): - print(self.x, self.y) - -class B(A): - def __init__(self, x, y): - A.__init__(self, x) - print('B init', x, y) - self.y = y - - def g(self): - print(self.x, self.y) - -A(1) -b = B(1, 2) -b.f() -b.g() diff --git a/tests/basics/tests/class_item.py b/tests/basics/tests/class_item.py deleted file mode 100644 index 6061f2607..000000000 --- a/tests/basics/tests/class_item.py +++ /dev/null @@ -1,13 +0,0 @@ -# test class with __getitem__ and __setitem__ methods - -class C: - def __getitem__(self, item): - print('get', item) - return 'item' - - def __setitem__(self, item, value): - print('set', item, value) - -c = C() -print(c[1]) -c[1] = 2 diff --git a/tests/basics/tests/class_number.py b/tests/basics/tests/class_number.py deleted file mode 100644 index e1dbf4a26..000000000 --- a/tests/basics/tests/class_number.py +++ /dev/null @@ -1,15 +0,0 @@ -# test class with __add__ and __sub__ methods - -class C: - def __init__(self, value): - self.value = value - - def __add__(self, rhs): - print(self.value, '+', rhs) - - def __sub__(self, rhs): - print(self.value, '-', rhs) - -c = C(0) -c + 1 -c - 2 diff --git a/tests/basics/tests/class_store.py b/tests/basics/tests/class_store.py deleted file mode 100644 index 658da451b..000000000 --- a/tests/basics/tests/class_store.py +++ /dev/null @@ -1,17 +0,0 @@ -# store to class vs instance - -class C: - pass - -c = C() -c.x = 1 -print(c.x) -C.x = 2 -C.y = 3 -print(c.x, c.y) -print(C.x, C.y) -print(C().x, C().y) -c = C() -print(c.x) -c.x = 4 -print(c.x) diff --git a/tests/basics/tests/closure1.py b/tests/basics/tests/closure1.py deleted file mode 100644 index 610cb7002..000000000 --- a/tests/basics/tests/closure1.py +++ /dev/null @@ -1,16 +0,0 @@ -# closures - -def f(x): - y = 2 * x - def g(z): - return y + z - return g - -print(f(1)(1)) - -x = f(2) -y = f(3) -print(x(1), x(2), x(3)) -print(y(1), y(2), y(3)) -print(x(1), x(2), x(3)) -print(y(1), y(2), y(3)) diff --git a/tests/basics/tests/closure2.py b/tests/basics/tests/closure2.py deleted file mode 100644 index e4e5154a9..000000000 --- a/tests/basics/tests/closure2.py +++ /dev/null @@ -1,16 +0,0 @@ -# closures; closing over an argument - -def f(x): - y = 2 * x - def g(z): - return x + y + z - return g - -print(f(1)(1)) - -x = f(2) -y = f(3) -print(x(1), x(2), x(3)) -print(y(1), y(2), y(3)) -print(x(1), x(2), x(3)) -print(y(1), y(2), y(3)) diff --git a/tests/basics/tests/comprehension1.py b/tests/basics/tests/comprehension1.py deleted file mode 100644 index 7f541ee53..000000000 --- a/tests/basics/tests/comprehension1.py +++ /dev/null @@ -1,20 +0,0 @@ -def f(): - # list comprehension - - print([a + 1 for a in range(5)]) - print([(a, b) for a in range(3) for b in range(2)]) - print([a * 2 for a in range(7) if a > 3]) - - print([a for a in [1, 3, 5]]) - print([a for a in [a for a in range(4)]]) - - # dict comprehension - - d = {a : 2 * a for a in range(5)} - print(d[0], d[1], d[2], d[3], d[4]) - - # set comprehension - - print({a for a in range(5)}) - -f() diff --git a/tests/basics/tests/containment.py b/tests/basics/tests/containment.py deleted file mode 100644 index 84d40b4e8..000000000 --- a/tests/basics/tests/containment.py +++ /dev/null @@ -1,23 +0,0 @@ -for i in 1, 2: - for o in {1:2}, {1}, {1:2}.keys(): - print("{} in {}: {}".format(i, o, i in o)) - print("{} not in {}: {}".format(i, o, i not in o)) - -haystack = "supercalifragilistc" -for needle in (haystack[i:] for i in range(len(haystack))): - print(needle, "in", haystack, "::", needle in haystack) - print(needle, "not in", haystack, "::", needle not in haystack) - print(haystack, "in", needle, "::", haystack in needle) - print(haystack, "not in", needle, "::", haystack not in needle) -for needle in (haystack[:i+1] for i in range(len(haystack))): - print(needle, "in", haystack, "::", needle in haystack) - print(needle, "not in", haystack, "::", needle not in haystack) - print(haystack, "in", needle, "::", haystack in needle) - print(haystack, "not in", needle, "::", haystack not in needle) - -# until here, the tests would work without the 'second attempt' iteration thing. - -for i in 1, 2: - for o in [], [1], [1, 2]: - print("{} in {}: {}".format(i, o, i in o)) - print("{} not in {}: {}".format(i, o, i not in o)) diff --git a/tests/basics/tests/dict1.py b/tests/basics/tests/dict1.py deleted file mode 100644 index 1356cd428..000000000 --- a/tests/basics/tests/dict1.py +++ /dev/null @@ -1,18 +0,0 @@ -# basic dictionary - -d = {} -print(d) -d[2] = 123 -print(d) -d = {1:2} -d[3] = 3 -print(d) -d[1] = 0 -print(d) -print(d[1]) - -x = 1 -while x < 1000: - d[x] = x - x += 1 -print(d[500]) diff --git a/tests/basics/tests/dict2.py b/tests/basics/tests/dict2.py deleted file mode 100644 index 1d5aae576..000000000 --- a/tests/basics/tests/dict2.py +++ /dev/null @@ -1,10 +0,0 @@ -# using strings as keys in dict - -d = {'1': 1, '2': 2} -print(d['1'], d['2']) - -d['3'] = 3 -print(d['1'], d['2'], d['3']) - -d['2'] = 222 -print(d['1'], d['2'], d['3']) diff --git a/tests/basics/tests/dict_clear.py b/tests/basics/tests/dict_clear.py deleted file mode 100644 index 6be2778be..000000000 --- a/tests/basics/tests/dict_clear.py +++ /dev/null @@ -1,6 +0,0 @@ -d = {1: 2, 3: 4} -print(d) -d.clear() -print(d) -d[2] = 42 -print(d) diff --git a/tests/basics/tests/dict_copy.py b/tests/basics/tests/dict_copy.py deleted file mode 100644 index c3eb7ffc1..000000000 --- a/tests/basics/tests/dict_copy.py +++ /dev/null @@ -1,5 +0,0 @@ -a = {i: 2*i for i in range(1000)} -b = a.copy() -for i in range(1000): - print(i, b[i]) -print(len(b)) diff --git a/tests/basics/tests/dict_fromkeys.py b/tests/basics/tests/dict_fromkeys.py deleted file mode 100644 index d03f6ae9d..000000000 --- a/tests/basics/tests/dict_fromkeys.py +++ /dev/null @@ -1,10 +0,0 @@ -d = dict.fromkeys([1, 2, 3, 4]) -l = list(d.keys()) -l.sort() -print(l) - -d = dict.fromkeys([1, 2, 3, 4], 42) -l = list(d.values()) -l.sort() -print(l) - diff --git a/tests/basics/tests/dict_get.py b/tests/basics/tests/dict_get.py deleted file mode 100644 index fb43a45ea..000000000 --- a/tests/basics/tests/dict_get.py +++ /dev/null @@ -1,3 +0,0 @@ -for d in {}, {42:2}: - print(d.get(42)) - print(d.get(42,2)) diff --git a/tests/basics/tests/dict_iterator.py b/tests/basics/tests/dict_iterator.py deleted file mode 100644 index f190e32ff..000000000 --- a/tests/basics/tests/dict_iterator.py +++ /dev/null @@ -1,3 +0,0 @@ -d = {1: 2, 3: 4} -for i in d: - print(i, d[i]) diff --git a/tests/basics/tests/dict_pop.py b/tests/basics/tests/dict_pop.py deleted file mode 100644 index 602560ce9..000000000 --- a/tests/basics/tests/dict_pop.py +++ /dev/null @@ -1,12 +0,0 @@ -d = {1: 2, 3: 4} -print(d.pop(3), d) -print(d) -print(d.pop(1, 42), d) -print(d.pop(1, 42), d) -print(d.pop(1, None), d) -try: - print(d.pop(1), "!!!",) -except KeyError: - print("Raised KeyError") -else: - print("Did not rise KeyError!") diff --git a/tests/basics/tests/dict_popitem.py b/tests/basics/tests/dict_popitem.py deleted file mode 100644 index 184735cde..000000000 --- a/tests/basics/tests/dict_popitem.py +++ /dev/null @@ -1,11 +0,0 @@ -d={1:2,3:4} -print(d.popitem()) -print(d) -print(d.popitem()) -print(d) -try: - print(d.popitem(), "!!!",) -except KeyError: - print("Raised KeyError") -else: - print("Did not raise KeyError") diff --git a/tests/basics/tests/dict_setdefault.py b/tests/basics/tests/dict_setdefault.py deleted file mode 100644 index 57d0ba451..000000000 --- a/tests/basics/tests/dict_setdefault.py +++ /dev/null @@ -1,13 +0,0 @@ -d = {} -print(d.setdefault(1)) -print(d.setdefault(1)) -print(d.setdefault(5, 42)) -print(d.setdefault(5, 1)) -print(d[1]) -print(d[5]) -d.pop(5) -print(d.setdefault(5, 1)) -print(d[1]) -print(d[5]) - - diff --git a/tests/basics/tests/dict_update.py b/tests/basics/tests/dict_update.py deleted file mode 100644 index e7ae0bd96..000000000 --- a/tests/basics/tests/dict_update.py +++ /dev/null @@ -1,10 +0,0 @@ -d = {1:2, 3:4} -print(d) -d.update(["ab"]) -print(d[1]) -print(d[3]) -print(d["a"]) -print(len(d)) -d.update([(1,4)]) -print(d[1]) -print(len(d)) diff --git a/tests/basics/tests/dict_views.py b/tests/basics/tests/dict_views.py deleted file mode 100644 index fbf63fa0a..000000000 --- a/tests/basics/tests/dict_views.py +++ /dev/null @@ -1,6 +0,0 @@ -d = {1: 2} -for m in d.items, d.values, d.keys: - print(m()) - print(list(m())) - -# set operations still to come diff --git a/tests/basics/tests/enumerate.py b/tests/basics/tests/enumerate.py deleted file mode 100644 index f2bdf4f32..000000000 --- a/tests/basics/tests/enumerate.py +++ /dev/null @@ -1,6 +0,0 @@ -print(list(enumerate([]))) -print(list(enumerate([1, 2, 3]))) -print(list(enumerate([1, 2, 3], 5))) -print(list(enumerate([1, 2, 3], -5))) -print(list(enumerate(range(10000)))) - diff --git a/tests/basics/tests/eval1.py b/tests/basics/tests/eval1.py deleted file mode 100644 index 8b9d02e61..000000000 --- a/tests/basics/tests/eval1.py +++ /dev/null @@ -1,13 +0,0 @@ -# builtin eval - -eval('1 + 2') -eval('1 + 2\n') -eval('1 + 2\n\n#comment\n') - -x = 4 -eval('x') - -eval('lambda x: x + 10')(-5) - -y = 6 -eval('lambda: y * 2')() diff --git a/tests/basics/tests/exception1.py b/tests/basics/tests/exception1.py deleted file mode 100644 index 71d5ad304..000000000 --- a/tests/basics/tests/exception1.py +++ /dev/null @@ -1,9 +0,0 @@ -print(repr(IndexError())) -print(str(IndexError())) - -print(repr(IndexError("foo"))) -print(str(IndexError("foo"))) - -a = IndexError(1, "test", [100, 200]) -print(repr(a)) -print(str(a)) diff --git a/tests/basics/tests/filter.py b/tests/basics/tests/filter.py deleted file mode 100644 index 5883e3d00..000000000 --- a/tests/basics/tests/filter.py +++ /dev/null @@ -1,2 +0,0 @@ -print(list(filter(lambda x: x & 1, range(-3, 4)))) -print(list(filter(None, range(-3, 4)))) diff --git a/tests/basics/tests/float1.py b/tests/basics/tests/float1.py deleted file mode 100644 index 200d95585..000000000 --- a/tests/basics/tests/float1.py +++ /dev/null @@ -1,3 +0,0 @@ -# basic float -x = 1 / 2 -print(x) diff --git a/tests/basics/tests/for1.py b/tests/basics/tests/for1.py deleted file mode 100644 index c6199416c..000000000 --- a/tests/basics/tests/for1.py +++ /dev/null @@ -1,19 +0,0 @@ -# basic for loop - -def f(): - for x in range(2): - for y in range(2): - for z in range(2): - print(x, y, z) - -f() - -# range with negative step -for i in range(3, -1, -1): - print(i) - -a = -1 -# range with non-constant step - we optimize constant steps, so this -# will be executed differently -for i in range(3, -1, a): - print(i) diff --git a/tests/basics/tests/fun1.py b/tests/basics/tests/fun1.py deleted file mode 100644 index e12bdbe03..000000000 --- a/tests/basics/tests/fun1.py +++ /dev/null @@ -1,5 +0,0 @@ -# calling a function - -def f(): - print(1) -f() diff --git a/tests/basics/tests/fun2.py b/tests/basics/tests/fun2.py deleted file mode 100644 index a3c3e7bab..000000000 --- a/tests/basics/tests/fun2.py +++ /dev/null @@ -1,10 +0,0 @@ -# calling a function from a function - -def f(x): - print(x + 1) - -def g(x): - f(2 * x) - f(4 * x) - -g(3) diff --git a/tests/basics/tests/fun3.py b/tests/basics/tests/fun3.py deleted file mode 100644 index f1458df82..000000000 --- a/tests/basics/tests/fun3.py +++ /dev/null @@ -1,6 +0,0 @@ -# function with large number of arguments - -def fun(a, b, c, d, e, f, g): - return a + b + c * d + e * f * g - -print(fun(1, 2, 3, 4, 5, 6, 7)) diff --git a/tests/basics/tests/generator1.py b/tests/basics/tests/generator1.py deleted file mode 100644 index d4028b0ce..000000000 --- a/tests/basics/tests/generator1.py +++ /dev/null @@ -1,22 +0,0 @@ -def f(x): - print('a') - y = x - print('b') - while y > 0: - print('c') - y -= 1 - print('d') - yield y - print('e') - print('f') - return None - -for val in f(3): - print(val) - -#gen = f(3) -#print(gen) -#print(gen.__next__()) -#print(gen.__next__()) -#print(gen.__next__()) -#print(gen.__next__()) diff --git a/tests/basics/tests/generator2.py b/tests/basics/tests/generator2.py deleted file mode 100644 index 0dfc98a2d..000000000 --- a/tests/basics/tests/generator2.py +++ /dev/null @@ -1,3 +0,0 @@ -gen = (i for i in range(10)) -for i in gen: - print(i) diff --git a/tests/basics/tests/import1a.py b/tests/basics/tests/import1a.py deleted file mode 100644 index 16b2d4d30..000000000 --- a/tests/basics/tests/import1a.py +++ /dev/null @@ -1,2 +0,0 @@ -import import1b -print(import1b.var) diff --git a/tests/basics/tests/import1b.py b/tests/basics/tests/import1b.py deleted file mode 100644 index 80479088f..000000000 --- a/tests/basics/tests/import1b.py +++ /dev/null @@ -1 +0,0 @@ -var = 123 diff --git a/tests/basics/tests/int-small.py b/tests/basics/tests/int-small.py deleted file mode 100644 index be338c4a4..000000000 --- a/tests/basics/tests/int-small.py +++ /dev/null @@ -1,26 +0,0 @@ -# This test small int range for 32-bit machine - -a = 0x3fffff -print(a) -a *= 0x10 -print(a) -a *= 0x10 -print(a) -a += 0xff -print(a) -# This would overflow -#a += 1 - -a = -0x3fffff -print(a) -a *= 0x10 -print(a) -a *= 0x10 -print(a) -a -= 0xff -print(a) -# This still doesn't overflow -a -= 1 -print(a) -# This would overflow -#a -= 1 diff --git a/tests/basics/tests/int1.py b/tests/basics/tests/int1.py deleted file mode 100644 index 4ce0f9e70..000000000 --- a/tests/basics/tests/int1.py +++ /dev/null @@ -1,74 +0,0 @@ -print(int(0)) -print(int(1)) -print(int(+1)) -print(int(-1)) - -print(int('0')) -print(int('+0')) -print(int('-0')) -print(int('1')) -print(int('+1')) -print(int('-1')) -print(int('01')) -print(int('9')) -print(int('10')) -print(int('+10')) -print(int('-10')) -print(int('12')) -print(int('-12')) -print(int('99')) -print(int('100')) -print(int('314')) -print(int(' 314')) -print(int('314 ')) -print(int(' \t\t 314 \t\t ')) -print(int(' 1 ')) -print(int(' -3 ')) - -print(int('0', 10)) -print(int('1', 10)) -print(int(' \t 1 \t ', 10)) -print(int('11', 10)) -print(int('11', 16)) -print(int('11', 8)) -print(int('11', 2)) -print(int('11', 36)) -print(int('0o123', 0)) -print(int('8388607')) -print(int('0x123', 16)) -print(int('0X123', 16)) -print(int('0o123', 8)) -print(int('0O123', 8)) -print(int('0123', 8)) -print(int('0b100', 2)) -print(int('0B100', 2)) -print(int('0100', 2)) -print(int(' \t 0o12', 8)) -print(int('0o12 \t ', 8)) - - -def test(value, base): - try: - print(int(value, base)) - except ValueError: - print('ValueError') - - -test('x', 0) -test('1x', 0) -test(' 1x', 0) -test(' 1' + chr(2) + ' ', 0) -test('', 0) -test(' ', 0) -test(' \t\t ', 0) -test("\u0200", 0) -test('0x', 16) -test('0x', 0) -test('0o', 8) -test('0o', 0) -test('0b', 2) -test('0b', 0) -test('0b2', 2) -test('0o8', 8) -test('0xg', 16) -test('1 1', 16) diff --git a/tests/basics/tests/is-isnot.py b/tests/basics/tests/is-isnot.py deleted file mode 100644 index 990190aa4..000000000 --- a/tests/basics/tests/is-isnot.py +++ /dev/null @@ -1,14 +0,0 @@ -print(1 is 1) -print(1 is 2) -print(1 is not 1) -print(1 is not 2) - - -print([1, 2] is [1, 2]) -a = [1, 2] -b = a -print(b is a) - -# TODO: strings require special "is" handling, postponed -# until qstr refactor. -#print("a" is "a") diff --git a/tests/basics/tests/lambda1.py b/tests/basics/tests/lambda1.py deleted file mode 100644 index 06111d6a9..000000000 --- a/tests/basics/tests/lambda1.py +++ /dev/null @@ -1,4 +0,0 @@ -# lambda - -f = lambda x, y: x + 3 * y -print(f(3, 5)) diff --git a/tests/basics/tests/list1.py b/tests/basics/tests/list1.py deleted file mode 100644 index 250a12b70..000000000 --- a/tests/basics/tests/list1.py +++ /dev/null @@ -1,18 +0,0 @@ -# basic list functionality -x = [1, 2, 3 * 4] -print(x) -x[0] = 4 -print(x) -x[1] += -4 -print(x) -x.append(5) -print(x) -f = x.append -f(4) -print(x) - -x.extend([100, 200]) -print(x) - -x += [2, 1] -print(x) diff --git a/tests/basics/tests/list_clear.py b/tests/basics/tests/list_clear.py deleted file mode 100644 index 406d7e823..000000000 --- a/tests/basics/tests/list_clear.py +++ /dev/null @@ -1,4 +0,0 @@ -# tests list.clear -x = [1, 2, 3, 4] -x.clear() -print(x) diff --git a/tests/basics/tests/list_compare.py b/tests/basics/tests/list_compare.py deleted file mode 100644 index eea881424..000000000 --- a/tests/basics/tests/list_compare.py +++ /dev/null @@ -1,50 +0,0 @@ -print([] == []) -print([] > []) -print([] < []) -print([] == [1]) -print([1] == []) -print([] > [1]) -print([1] > []) -print([] < [1]) -print([1] < []) -print([] >= [1]) -print([1] >= []) -print([] <= [1]) -print([1] <= []) - -print([1] == [1]) -print([1] != [1]) -print([1] == [2]) -print([1] == [1, 0]) - -print([1] > [1]) -print([1] > [2]) -print([2] > [1]) -print([1, 0] > [1]) -print([1, -1] > [1]) -print([1] > [1, 0]) -print([1] > [1, -1]) - -print([1] < [1]) -print([2] < [1]) -print([1] < [2]) -print([1] < [1, 0]) -print([1] < [1, -1]) -print([1, 0] < [1]) -print([1, -1] < [1]) - -print([1] >= [1]) -print([1] >= [2]) -print([2] >= [1]) -print([1, 0] >= [1]) -print([1, -1] >= [1]) -print([1] >= [1, 0]) -print([1] >= [1, -1]) - -print([1] <= [1]) -print([2] <= [1]) -print([1] <= [2]) -print([1] <= [1, 0]) -print([1] <= [1, -1]) -print([1, 0] <= [1]) -print([1, -1] <= [1]) diff --git a/tests/basics/tests/list_copy.py b/tests/basics/tests/list_copy.py deleted file mode 100644 index bc450782e..000000000 --- a/tests/basics/tests/list_copy.py +++ /dev/null @@ -1,7 +0,0 @@ -# list copy tests -a = [1, 2, []] -b = a.copy() -a[-1].append(1) -a.append(4) -print(a) -print(b) diff --git a/tests/basics/tests/list_count.py b/tests/basics/tests/list_count.py deleted file mode 100644 index db93b3a2f..000000000 --- a/tests/basics/tests/list_count.py +++ /dev/null @@ -1,6 +0,0 @@ -# list count tests -a = [1, 2, 3] -a = a + a + a -b = [0, 0, a, 0, a, 0] -print(a.count(2)) -print(b.count(a)) diff --git a/tests/basics/tests/list_index.py b/tests/basics/tests/list_index.py deleted file mode 100644 index f28263fba..000000000 --- a/tests/basics/tests/list_index.py +++ /dev/null @@ -1,24 +0,0 @@ -a = [1, 2, 3] -print(a.index(1)) -print(a.index(2)) -print(a.index(3)) -print(a.index(3, 2)) -try: - print(a.index(3, 2, 2)) -except ValueError: - print("Raised ValueError") -else: - print("Did not raise ValueError") - -a = a + a -b = [0, 0, a] -print(a.index(2)) -print(b.index(a)) -print(a.index(2, 2)) - -try: - a.index(2, 2, 2) -except ValueError: - print("Raised ValueError") -else: - print("Did not raise ValueError") diff --git a/tests/basics/tests/list_insert.py b/tests/basics/tests/list_insert.py deleted file mode 100644 index 6db97cf5c..000000000 --- a/tests/basics/tests/list_insert.py +++ /dev/null @@ -1,9 +0,0 @@ -a = [1, 2, 3] -a.insert(1, 42) -print(a) -a.insert(-1, -1) -print(a) -a.insert(99, 99) -print(a) -a.insert(-99, -99) -print(a) diff --git a/tests/basics/tests/list_mult.py b/tests/basics/tests/list_mult.py deleted file mode 100644 index ec65fbb3f..000000000 --- a/tests/basics/tests/list_mult.py +++ /dev/null @@ -1,4 +0,0 @@ -print([0] * 5) -a = [1, 2, 3] -c = a * 3 -print(c) diff --git a/tests/basics/tests/list_pop.py b/tests/basics/tests/list_pop.py deleted file mode 100644 index bb2ccc6d6..000000000 --- a/tests/basics/tests/list_pop.py +++ /dev/null @@ -1,11 +0,0 @@ -# list poppin' -a = [1, 2, 3] -print(a.pop()) -print(a.pop()) -print(a.pop()) -try: - print(a.pop()) -except IndexError: - print("IndexError raised") -else: - raise AssertionError("No IndexError raised") diff --git a/tests/basics/tests/list_remove.py b/tests/basics/tests/list_remove.py deleted file mode 100644 index 81b2b3d97..000000000 --- a/tests/basics/tests/list_remove.py +++ /dev/null @@ -1,9 +0,0 @@ -a = [1, 2, 3] -print(a.remove(2)) -print(a) -try: - a.remove(2) -except ValueError: - print("Raised ValueError") -else: - raise AssertionError("Did not raise ValueError") diff --git a/tests/basics/tests/list_reverse.py b/tests/basics/tests/list_reverse.py deleted file mode 100644 index 38acf1fd6..000000000 --- a/tests/basics/tests/list_reverse.py +++ /dev/null @@ -1,5 +0,0 @@ -a = [] -for i in range(100): - a.append(i) - a.reverse() -print(a) diff --git a/tests/basics/tests/list_sort.py b/tests/basics/tests/list_sort.py deleted file mode 100644 index eff12b9c8..000000000 --- a/tests/basics/tests/list_sort.py +++ /dev/null @@ -1,13 +0,0 @@ -l = [1, 3, 2, 5] -print(l) -l.sort() -print(l) -l.sort(key=lambda x: -x) -print(l) -l.sort(key=lambda x: -x, reverse=True) -print(l) -l.sort(reverse=True) -print(l) -l.sort(reverse=False) -print(l) - diff --git a/tests/basics/tests/list_sum.py b/tests/basics/tests/list_sum.py deleted file mode 100644 index e46042b86..000000000 --- a/tests/basics/tests/list_sum.py +++ /dev/null @@ -1,5 +0,0 @@ -# list addition -a = [1,2,3] -b = [4,5,6] -c = a + b -print(c) diff --git a/tests/basics/tests/map.py b/tests/basics/tests/map.py deleted file mode 100644 index 62dca44ed..000000000 --- a/tests/basics/tests/map.py +++ /dev/null @@ -1,4 +0,0 @@ -print(list(map(lambda x: x & 1, range(-3, 4)))) -print(list(map(abs, range(-3, 4)))) -print(list(map(set, [[i] for i in range(-3, 4)]))) -print(list(map(pow, range(4), range(4)))) diff --git a/tests/basics/tests/set1.py b/tests/basics/tests/set1.py deleted file mode 100644 index c54fbd837..000000000 --- a/tests/basics/tests/set1.py +++ /dev/null @@ -1,7 +0,0 @@ -# basic sets - -s = {1} -print(s) - -s = {3, 4, 3, 1} -print(s) diff --git a/tests/basics/tests/set_add.py b/tests/basics/tests/set_add.py deleted file mode 100644 index f2a372f30..000000000 --- a/tests/basics/tests/set_add.py +++ /dev/null @@ -1,5 +0,0 @@ -s = {1, 2, 3, 4} -print(s.add(5)) -l = list(s) -l.sort() -print(l) diff --git a/tests/basics/tests/set_binop.py b/tests/basics/tests/set_binop.py deleted file mode 100644 index d0d0b8027..000000000 --- a/tests/basics/tests/set_binop.py +++ /dev/null @@ -1,30 +0,0 @@ -def r(s): - l = list(s) - l.sort() - return l -sets = [set(), {1}, {1, 2}, {1, 2, 3}, {2, 3}, {2, 3, 5}, {5}, {7}] -for s in sets: - for t in sets: - print(s, '|', t, '=', r(s | t)) - print(s, '^', t, '=', r(s ^ t)) - print(s, '&', t, '=', r(s & t)) - print(s, '-', t, '=', r(s - t)) - u = s.copy() - u |= t - print(s, "|=", t, '-->', r(u)) - u = s.copy() - u ^= t - print(s, "^=", t, '-->', r(u)) - u = s.copy() - u &= t - print(s, "&=", t, "-->", r(u)) - u = s.copy() - u -= t - print(s, "-=", t, "-->", r(u)) - - print(s, '==', t, '=', s == t) - print(s, '!=', t, '=', s != t) - print(s, '>', t, '=', s > t) - print(s, '>=', t, '=', s >= t) - print(s, '<', t, '=', s < t) - print(s, '<=', t, '=', s <= t) diff --git a/tests/basics/tests/set_clear.py b/tests/basics/tests/set_clear.py deleted file mode 100644 index 6fda93f0f..000000000 --- a/tests/basics/tests/set_clear.py +++ /dev/null @@ -1,3 +0,0 @@ -s = {1, 2, 3, 4} -print(s.clear()) -print(list(s)) diff --git a/tests/basics/tests/set_copy.py b/tests/basics/tests/set_copy.py deleted file mode 100644 index 2ea308b0d..000000000 --- a/tests/basics/tests/set_copy.py +++ /dev/null @@ -1,8 +0,0 @@ -s = {1, 2, 3, 4} -t = s.copy() -s.add(5) -t.add(7) -for i in s, t: - l = list(i) - l.sort() - print(l) diff --git a/tests/basics/tests/set_difference.py b/tests/basics/tests/set_difference.py deleted file mode 100644 index 26976116f..000000000 --- a/tests/basics/tests/set_difference.py +++ /dev/null @@ -1,21 +0,0 @@ -def report(s): - l = list(s) - l.sort() - print(l) - -l = [1, 2, 3, 4] -s = set(l) -outs = [s.difference(), - s.difference({1}), - s.difference({1}, [1, 2]), - s.difference({1}, {1, 2}, {2, 3})] -for out in outs: - report(out) - -s = set(l) -print(s.difference_update()) -report(s) -print(s.difference_update({1})) -report(s) -print(s.difference_update({1}, [2])) -report(s) diff --git a/tests/basics/tests/set_discard.py b/tests/basics/tests/set_discard.py deleted file mode 100644 index baac26413..000000000 --- a/tests/basics/tests/set_discard.py +++ /dev/null @@ -1,3 +0,0 @@ -s = {1, 2} -print(s.discard(1)) -print(list(s)) diff --git a/tests/basics/tests/set_intersection.py b/tests/basics/tests/set_intersection.py deleted file mode 100644 index 6f3dfc741..000000000 --- a/tests/basics/tests/set_intersection.py +++ /dev/null @@ -1,12 +0,0 @@ -def report(s): - l = list(s) - l.sort() - print(l) - -s = {1, 2, 3, 4} -report(s) -report(s.intersection({1, 3})) -report(s.intersection([3, 4])) - -print(s.intersection_update([1])) -report(s) diff --git a/tests/basics/tests/set_isdisjoint.py b/tests/basics/tests/set_isdisjoint.py deleted file mode 100644 index 7fb7e769b..000000000 --- a/tests/basics/tests/set_isdisjoint.py +++ /dev/null @@ -1,6 +0,0 @@ -s = {1, 2, 3, 4} -print(s.isdisjoint({1})) -print(s.isdisjoint([2])) -print(s.isdisjoint([])) -print(s.isdisjoint({7,8,9,10})) -print(s.isdisjoint([7,8,9,1])) diff --git a/tests/basics/tests/set_isfooset.py b/tests/basics/tests/set_isfooset.py deleted file mode 100644 index ce7952cd2..000000000 --- a/tests/basics/tests/set_isfooset.py +++ /dev/null @@ -1,5 +0,0 @@ -sets = [set(), {1}, {1, 2, 3}, {3, 4, 5}, {5, 6, 7}] -for i in sets: - for j in sets: - print(i.issubset(j)) - print(i.issuperset(j)) diff --git a/tests/basics/tests/set_iter.py b/tests/basics/tests/set_iter.py deleted file mode 100644 index 296017730..000000000 --- a/tests/basics/tests/set_iter.py +++ /dev/null @@ -1,5 +0,0 @@ -s = {1, 2, 3, 4} -l = list(s) -l.sort() -print(l) - diff --git a/tests/basics/tests/set_pop.py b/tests/basics/tests/set_pop.py deleted file mode 100644 index 0cd478ce2..000000000 --- a/tests/basics/tests/set_pop.py +++ /dev/null @@ -1,9 +0,0 @@ -s = {1} -print(s.pop()) -try: - print(s.pop(), "!!!") -except KeyError: - pass -else: - print("Failed to raise KeyError") - diff --git a/tests/basics/tests/set_remove.py b/tests/basics/tests/set_remove.py deleted file mode 100644 index 208ab137f..000000000 --- a/tests/basics/tests/set_remove.py +++ /dev/null @@ -1,9 +0,0 @@ -s = {1} -print(s.remove(1)) -print(list(s)) -try: - print(s.remove(1), "!!!") -except KeyError: - pass -else: - print("failed to raise KeyError") diff --git a/tests/basics/tests/set_symmetric_difference.py b/tests/basics/tests/set_symmetric_difference.py deleted file mode 100644 index acf298385..000000000 --- a/tests/basics/tests/set_symmetric_difference.py +++ /dev/null @@ -1,7 +0,0 @@ -print({1,2}.symmetric_difference({2,3})) -print({1,2}.symmetric_difference([2,3])) -s = {1,2} -print(s.symmetric_difference_update({2,3})) -l = list(s) -l.sort() -print(l) diff --git a/tests/basics/tests/set_union.py b/tests/basics/tests/set_union.py deleted file mode 100644 index 2adcc972c..000000000 --- a/tests/basics/tests/set_union.py +++ /dev/null @@ -1 +0,0 @@ -print({1}.union({2})) diff --git a/tests/basics/tests/set_update.py b/tests/basics/tests/set_update.py deleted file mode 100644 index 78cd76356..000000000 --- a/tests/basics/tests/set_update.py +++ /dev/null @@ -1,12 +0,0 @@ -def report(s): - l = list(s) - l.sort() - print(l) - -s = {1} -s.update() -report(s) -s.update([2]) -report(s) -s.update([1,3], [2,2,4]) -report(s) diff --git a/tests/basics/tests/sorted.py b/tests/basics/tests/sorted.py deleted file mode 100644 index bbec31946..000000000 --- a/tests/basics/tests/sorted.py +++ /dev/null @@ -1,2 +0,0 @@ -print(sorted(set(range(100)))) -print(sorted(set(range(100)), key=lambda x: x + 100*(x % 2))) diff --git a/tests/basics/tests/string-format.py b/tests/basics/tests/string-format.py deleted file mode 100644 index ba51e0890..000000000 --- a/tests/basics/tests/string-format.py +++ /dev/null @@ -1,8 +0,0 @@ -print("{}-{}".format(1, [4, 5])) -print("{0}-{1}".format(1, [4, 5])) -print("{:x}".format(1)) -print("{!r}".format(2)) -# TODO -#print("{1}-{0}".format(1, [4, 5])) -#print("{:x}".format(0x10)) -#print("{!r}".format("foo")) diff --git a/tests/basics/tests/string-slice.py b/tests/basics/tests/string-slice.py deleted file mode 100644 index 7538ae570..000000000 --- a/tests/basics/tests/string-slice.py +++ /dev/null @@ -1,32 +0,0 @@ -print("123"[0:1]) - -print("123"[0:2]) - -print("123"[:1]) - -print("123"[1:]) - -# Idiom for copying sequence -print("123"[:]) - -print("123"[:-1]) - -# Weird cases -print("123"[0:0]) -print("123"[1:0]) -print("123"[1:1]) -print("123"[-1:-1]) -print("123"[-3:]) -print("123"[-3:3]) -print("123"[0:]) -print("123"[:0]) -print("123"[:-3]) -print("123"[:-4]) -# Range check testing, don't segfault, please ;-) -print("123"[:1000000]) -print("123"[1000000:]) -print("123"[:-1000000]) -print("123"[-1000000:]) -# No IndexError! -print(""[1:1]) -print(""[-1:-1]) diff --git a/tests/basics/tests/string1.py b/tests/basics/tests/string1.py deleted file mode 100644 index 3fecf799b..000000000 --- a/tests/basics/tests/string1.py +++ /dev/null @@ -1,19 +0,0 @@ -# basic strings - -x = 'abc' -print(x) - -x += 'def' -print(x) - -print('123' + "456") - -# iter -print(list('str')) - -print('123' + '789' == '123789') -print('a' + 'b' != 'a' + 'b ') - -# Not implemented so far -# print('1' + '2' > '2') -# print('1' + '2' < '2') diff --git a/tests/basics/tests/string_find.py b/tests/basics/tests/string_find.py deleted file mode 100644 index 90063228f..000000000 --- a/tests/basics/tests/string_find.py +++ /dev/null @@ -1,11 +0,0 @@ -print("hello world".find("ll")) -print("hello world".find("ll", None)) -print("hello world".find("ll", 1)) -print("hello world".find("ll", 1, None)) -print("hello world".find("ll", None, None)) -print("hello world".find("ll", 1, -1)) -print("hello world".find("ll", 1, 1)) -print("hello world".find("ll", 1, 2)) -print("hello world".find("ll", 1, 3)) -print("hello world".find("ll", 1, 4)) -print("hello world".find("ll", 1, 5)) diff --git a/tests/basics/tests/true-value.py b/tests/basics/tests/true-value.py deleted file mode 100644 index 6ba410ddc..000000000 --- a/tests/basics/tests/true-value.py +++ /dev/null @@ -1,27 +0,0 @@ -# Test true-ish value handling - -if not False: - print("False") - -if not 0: - print("0") - -if not "": - print("Empty string") -if "foo": - print("Non-empty string") - -if not (): - print("Empty tuple") -if ("",): - print("Non-empty tuple") - -if not []: - print("Empty list") -if [0]: - print("Non-empty list") - -if not {}: - print("Empty dict") -if {0:0}: - print("Non-empty dict") diff --git a/tests/basics/tests/try1.py b/tests/basics/tests/try1.py deleted file mode 100644 index 56d307504..000000000 --- a/tests/basics/tests/try1.py +++ /dev/null @@ -1,11 +0,0 @@ -# basic exceptions -x = 1 -try: - x.a() -except: - print(x) - -try: - raise IndexError -except IndexError: - print("caught") diff --git a/tests/basics/tests/try2.py b/tests/basics/tests/try2.py deleted file mode 100644 index 1cca9e039..000000000 --- a/tests/basics/tests/try2.py +++ /dev/null @@ -1,12 +0,0 @@ -# nested try's - -try: - print("try 1") - try: - print("try 2") - foo() - except: - print("except 2") - bar() -except: - print("except 1") diff --git a/tests/basics/tests/try3.py b/tests/basics/tests/try3.py deleted file mode 100644 index 31bacd3b3..000000000 --- a/tests/basics/tests/try3.py +++ /dev/null @@ -1,17 +0,0 @@ -# nested exceptions - -def f(): - try: - foo() - except: - print("except 1") - try: - baz() - except: - print("except 2") - bar() - -try: - f() -except: - print("f except") diff --git a/tests/basics/tests/try4.py b/tests/basics/tests/try4.py deleted file mode 100644 index 4d324c187..000000000 --- a/tests/basics/tests/try4.py +++ /dev/null @@ -1,21 +0,0 @@ -# triple nested exceptions - -def f(): - try: - foo() - except: - print("except 1") - try: - bar() - except: - print("except 2") - try: - baz() - except: - print("except 3") - bak() - -try: - f() -except: - print("f except") diff --git a/tests/basics/tests/types1.py b/tests/basics/tests/types1.py deleted file mode 100644 index 850b31b08..000000000 --- a/tests/basics/tests/types1.py +++ /dev/null @@ -1,28 +0,0 @@ -# basic types - -print(bool) -print(int) -print(float) -print(complex) -print(tuple) -print(list) -print(set) -print(dict) - -print(type(bool()) == bool) -print(type(int()) == int) -print(type(float()) == float) -print(type(complex()) == complex) -print(type(tuple()) == tuple) -print(type(list()) == list) -print(type(set()) == set) -print(type(dict()) == dict) - -print(type(False) == bool) -print(type(0) == int) -print(type(0.0) == float) -print(type(1j) == complex) -print(type(()) == tuple) -print(type([]) == list) -print(type({None}) == set) -print(type({}) == dict) diff --git a/tests/basics/tests/while1.py b/tests/basics/tests/while1.py deleted file mode 100644 index a9bb5d279..000000000 --- a/tests/basics/tests/while1.py +++ /dev/null @@ -1,12 +0,0 @@ -# basic while loop - -x = 0 -while x < 2: - y = 0 - while y < 2: - z = 0 - while z < 2: - z = z + 1 - print(x, y, z) - y = y + 1 - x = x + 1 diff --git a/tests/basics/tests/zip.py b/tests/basics/tests/zip.py deleted file mode 100644 index c0109094f..000000000 --- a/tests/basics/tests/zip.py +++ /dev/null @@ -1,2 +0,0 @@ -print(list(zip())) -print(list(zip([1], {2,3}))) diff --git a/tests/basics/true-value.py b/tests/basics/true-value.py new file mode 100644 index 000000000..6ba410ddc --- /dev/null +++ b/tests/basics/true-value.py @@ -0,0 +1,27 @@ +# Test true-ish value handling + +if not False: + print("False") + +if not 0: + print("0") + +if not "": + print("Empty string") +if "foo": + print("Non-empty string") + +if not (): + print("Empty tuple") +if ("",): + print("Non-empty tuple") + +if not []: + print("Empty list") +if [0]: + print("Non-empty list") + +if not {}: + print("Empty dict") +if {0:0}: + print("Non-empty dict") diff --git a/tests/basics/try1.py b/tests/basics/try1.py new file mode 100644 index 000000000..56d307504 --- /dev/null +++ b/tests/basics/try1.py @@ -0,0 +1,11 @@ +# basic exceptions +x = 1 +try: + x.a() +except: + print(x) + +try: + raise IndexError +except IndexError: + print("caught") diff --git a/tests/basics/try2.py b/tests/basics/try2.py new file mode 100644 index 000000000..1cca9e039 --- /dev/null +++ b/tests/basics/try2.py @@ -0,0 +1,12 @@ +# nested try's + +try: + print("try 1") + try: + print("try 2") + foo() + except: + print("except 2") + bar() +except: + print("except 1") diff --git a/tests/basics/try3.py b/tests/basics/try3.py new file mode 100644 index 000000000..31bacd3b3 --- /dev/null +++ b/tests/basics/try3.py @@ -0,0 +1,17 @@ +# nested exceptions + +def f(): + try: + foo() + except: + print("except 1") + try: + baz() + except: + print("except 2") + bar() + +try: + f() +except: + print("f except") diff --git a/tests/basics/try4.py b/tests/basics/try4.py new file mode 100644 index 000000000..4d324c187 --- /dev/null +++ b/tests/basics/try4.py @@ -0,0 +1,21 @@ +# triple nested exceptions + +def f(): + try: + foo() + except: + print("except 1") + try: + bar() + except: + print("except 2") + try: + baz() + except: + print("except 3") + bak() + +try: + f() +except: + print("f except") diff --git a/tests/basics/types1.py b/tests/basics/types1.py new file mode 100644 index 000000000..850b31b08 --- /dev/null +++ b/tests/basics/types1.py @@ -0,0 +1,28 @@ +# basic types + +print(bool) +print(int) +print(float) +print(complex) +print(tuple) +print(list) +print(set) +print(dict) + +print(type(bool()) == bool) +print(type(int()) == int) +print(type(float()) == float) +print(type(complex()) == complex) +print(type(tuple()) == tuple) +print(type(list()) == list) +print(type(set()) == set) +print(type(dict()) == dict) + +print(type(False) == bool) +print(type(0) == int) +print(type(0.0) == float) +print(type(1j) == complex) +print(type(()) == tuple) +print(type([]) == list) +print(type({None}) == set) +print(type({}) == dict) diff --git a/tests/basics/while1.py b/tests/basics/while1.py new file mode 100644 index 000000000..a9bb5d279 --- /dev/null +++ b/tests/basics/while1.py @@ -0,0 +1,12 @@ +# basic while loop + +x = 0 +while x < 2: + y = 0 + while y < 2: + z = 0 + while z < 2: + z = z + 1 + print(x, y, z) + y = y + 1 + x = x + 1 diff --git a/tests/basics/zip.py b/tests/basics/zip.py new file mode 100644 index 000000000..c0109094f --- /dev/null +++ b/tests/basics/zip.py @@ -0,0 +1,2 @@ +print(list(zip())) +print(list(zip([1], {2,3}))) diff --git a/tests/run-tests b/tests/run-tests new file mode 100755 index 000000000..7ab128133 --- /dev/null +++ b/tests/run-tests @@ -0,0 +1,48 @@ +#!/usr/bin/env bash + +RM="/bin/rm -f" +CPYTHON3=python3.3 +MP_PY=../unix/py + +numtests=0 +numtestcases=0 +numpassed=0 +numfailed=0 +namefailed= + +for infile in basics/*.py +do + basename=`basename $infile .py` + outfile=${basename}.out + expfile=${basename}.exp + + $CPYTHON3 -B $infile > $expfile + $MP_PY $infile > $outfile + ((numtestcases = numtestcases + $(cat $expfile | wc -l))) + + diff --brief $expfile $outfile > /dev/null + + if [ $? -eq 0 ] + then + echo "pass $infile" + $RM $outfile + $RM $expfile + ((numpassed=numpassed + 1)) + else + echo "FAIL $infile" + ((numfailed=numfailed + 1)) + namefailed="$namefailed $basename" + fi + + ((numtests=numtests + 1)) +done + +echo "$numtests tests performed ($numtestcases individual testcases)" +echo "$numpassed tests passed" +if [[ $numfailed != 0 ]] +then + echo "$numfailed tests failed -$namefailed" + exit 1 +else + exit 0 +fi -- cgit v1.2.3 From 9954b4b99d9119ea55b1c204b12bad1e7b45589b Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 19 Jan 2014 18:46:21 +0200 Subject: Add directory for I/O tests with basic test for file methods. --- tests/io/data/file1 | 3 +++ tests/io/file1.py | 4 ++++ tests/run-tests | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 tests/io/data/file1 create mode 100644 tests/io/file1.py (limited to 'tests') diff --git a/tests/io/data/file1 b/tests/io/data/file1 new file mode 100644 index 000000000..e08206337 --- /dev/null +++ b/tests/io/data/file1 @@ -0,0 +1,3 @@ +longer line1 +line2 +line3 diff --git a/tests/io/file1.py b/tests/io/file1.py new file mode 100644 index 000000000..8552f535b --- /dev/null +++ b/tests/io/file1.py @@ -0,0 +1,4 @@ +f = open("io/data/file1") +print(f.read(5)) +print(f.readline()) +print(f.read()) diff --git a/tests/run-tests b/tests/run-tests index 7ab128133..318920b5e 100755 --- a/tests/run-tests +++ b/tests/run-tests @@ -10,7 +10,7 @@ numpassed=0 numfailed=0 namefailed= -for infile in basics/*.py +for infile in basics/*.py io/*.py do basename=`basename $infile .py` outfile=${basename}.out -- cgit v1.2.3 From db796ef84d1737edc4ee44f1b53ff0c1fddb349c Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 19 Jan 2014 18:51:59 +0200 Subject: Add README for tests/. --- tests/README | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 tests/README (limited to 'tests') diff --git a/tests/README b/tests/README new file mode 100644 index 000000000..ef0070571 --- /dev/null +++ b/tests/README @@ -0,0 +1,4 @@ +This directory contains tests for various functionality areas of MicroPython. +To run all stable tests, run "run-tests" script in this directory. Note +that bytecode tests are not yet stable and should be run separately in +"bytecode" subdirectory. -- cgit v1.2.3