From 539681fffd96082ca3b5d18643d4f08f65c47170 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sat, 5 Jul 2014 06:14:29 +0100 Subject: tests: Rename test scripts, changing - to _ for consistency. From now on, all new tests must use underscore. Addresses issue #727. --- tests/basics/builtin-bin.py | 12 ---- tests/basics/builtin-callable.py | 5 -- tests/basics/builtin-hex.py | 12 ---- tests/basics/builtin-len1.py | 13 ---- tests/basics/builtin-minmax.py | 15 ---- tests/basics/builtin-oct.py | 12 ---- tests/basics/builtin_bin.py | 12 ++++ tests/basics/builtin_callable.py | 5 ++ tests/basics/builtin_hex.py | 12 ++++ tests/basics/builtin_len1.py | 13 ++++ tests/basics/builtin_minmax.py | 15 ++++ tests/basics/builtin_oct.py | 12 ++++ tests/basics/class-contains.py | 23 ------ tests/basics/class-emptybases.py | 2 - tests/basics/class-getattr.py | 16 ----- tests/basics/class-staticclassmethod.py | 25 ------- tests/basics/class-subclass-builtin.py | 6 -- tests/basics/class-super.py | 16 ----- tests/basics/class_contains.py | 23 ++++++ tests/basics/class_emptybases.py | 2 + tests/basics/class_getattr.py | 16 +++++ tests/basics/class_staticclassmethod.py | 25 +++++++ tests/basics/class_subclass_builtin.py | 6 ++ tests/basics/class_super.py | 16 +++++ tests/basics/closure-defargs.py | 11 --- tests/basics/closure_defargs.py | 11 +++ tests/basics/compare-multi.py | 4 -- tests/basics/compare_multi.py | 4 ++ tests/basics/del-attr.py | 32 --------- tests/basics/del-deref.py | 22 ------ tests/basics/del-local.py | 25 ------- tests/basics/del-name.py | 18 ----- tests/basics/del-subscr.py | 13 ---- tests/basics/del_attr.py | 32 +++++++++ tests/basics/del_deref.py | 22 ++++++ tests/basics/del_local.py | 25 +++++++ tests/basics/del_name.py | 18 +++++ tests/basics/del_subscr.py | 13 ++++ tests/basics/dict-del.py | 21 ------ tests/basics/dict-from-iter.py | 14 ---- tests/basics/dict-intern.py | 15 ---- tests/basics/dict_del.py | 21 ++++++ tests/basics/dict_from_iter.py | 14 ++++ tests/basics/dict_intern.py | 15 ++++ tests/basics/fun-annotations.py | 4 -- tests/basics/fun-calldblstar.py | 17 ----- tests/basics/fun-callstar.py | 33 --------- tests/basics/fun-callstardblstar.py | 17 ----- tests/basics/fun-defargs.py | 20 ------ tests/basics/fun-defargs2.py | 19 ----- tests/basics/fun-kwargs.py | 35 --------- tests/basics/fun-kwonly.py | 59 --------------- tests/basics/fun-kwonlydef.py | 36 ---------- tests/basics/fun-kwvarargs.py | 19 ----- tests/basics/fun-varargs.py | 41 ----------- tests/basics/fun_annotations.py | 4 ++ tests/basics/fun_calldblstar.py | 17 +++++ tests/basics/fun_callstar.py | 33 +++++++++ tests/basics/fun_callstardblstar.py | 17 +++++ tests/basics/fun_defargs.py | 20 ++++++ tests/basics/fun_defargs2.py | 19 +++++ tests/basics/fun_kwargs.py | 35 +++++++++ tests/basics/fun_kwonly.py | 59 +++++++++++++++ tests/basics/fun_kwonlydef.py | 36 ++++++++++ tests/basics/fun_kwvarargs.py | 19 +++++ tests/basics/fun_varargs.py | 41 +++++++++++ tests/basics/gen-yield-from-close.py | 87 ---------------------- tests/basics/gen-yield-from-ducktype.py | 44 ------------ tests/basics/gen-yield-from-exc.py | 13 ---- tests/basics/gen-yield-from-iter.py | 8 --- tests/basics/gen-yield-from-send.py | 14 ---- tests/basics/gen-yield-from-throw.py | 19 ----- tests/basics/gen-yield-from.py | 42 ----------- tests/basics/gen_yield_from.py | 42 +++++++++++ tests/basics/gen_yield_from_close.py | 87 ++++++++++++++++++++++ tests/basics/gen_yield_from_ducktype.py | 44 ++++++++++++ tests/basics/gen_yield_from_exc.py | 13 ++++ tests/basics/gen_yield_from_iter.py | 8 +++ tests/basics/gen_yield_from_send.py | 14 ++++ tests/basics/gen_yield_from_throw.py | 19 +++++ tests/basics/generator-args.py | 17 ----- tests/basics/generator-closure.py | 26 ------- tests/basics/generator-exc.py | 53 -------------- tests/basics/generator-return.py | 10 --- tests/basics/generator_args.py | 17 +++++ tests/basics/generator_closure.py | 26 +++++++ tests/basics/generator_exc.py | 53 ++++++++++++++ tests/basics/generator_return.py | 10 +++ tests/basics/globals-del.py | 27 ------- tests/basics/globals_del.py | 27 +++++++ tests/basics/int-big-and.py | 24 ------- tests/basics/int-big-lshift.py | 17 ----- tests/basics/int-big-mod.py | 10 --- tests/basics/int-big-mul.py | 8 --- tests/basics/int-bytes.py | 6 -- tests/basics/int-divzero.py | 4 -- tests/basics/int-long.py | 54 -------------- tests/basics/int-mpz.py | 57 --------------- tests/basics/int-small.py | 50 ------------- tests/basics/int_big_and.py | 24 +++++++ tests/basics/int_big_lshift.py | 17 +++++ tests/basics/int_big_mod.py | 10 +++ tests/basics/int_big_mul.py | 8 +++ tests/basics/int_bytes.py | 6 ++ tests/basics/int_divzero.py | 4 ++ tests/basics/int_long.py | 54 ++++++++++++++ tests/basics/int_mpz.py | 57 +++++++++++++++ tests/basics/int_small.py | 50 +++++++++++++ tests/basics/is-isnot.py | 14 ---- tests/basics/is_isnot.py | 14 ++++ tests/basics/iter-of-iter.py | 8 --- tests/basics/iter_of_iter.py | 8 +++ tests/basics/seq-unpack.py | 36 ---------- tests/basics/seq_unpack.py | 36 ++++++++++ tests/basics/string-compare.py | 50 ------------- tests/basics/string-escape.py | 11 --- tests/basics/string-format-modulo.py | 86 ---------------------- tests/basics/string-format.py | 120 ------------------------------- tests/basics/string-join.py | 24 ------- tests/basics/string-repr.py | 4 -- tests/basics/string-slice.py | 35 --------- tests/basics/string_compare.py | 50 +++++++++++++ tests/basics/string_escape.py | 11 +++ tests/basics/string_format.py | 120 +++++++++++++++++++++++++++++++ tests/basics/string_format_modulo.py | 86 ++++++++++++++++++++++ tests/basics/string_join.py | 24 +++++++ tests/basics/string_repr.py | 4 ++ tests/basics/string_slice.py | 35 +++++++++ tests/basics/subclass-native1.py | 31 -------- tests/basics/subclass-native2-list.py | 26 ------- tests/basics/subclass-native2-tuple.py | 21 ------ tests/basics/subclass-native3.py | 22 ------ tests/basics/subclass-native4.py | 9 --- tests/basics/subclass-native5.py | 12 ---- tests/basics/subclass_native1.py | 31 ++++++++ tests/basics/subclass_native2_list.py | 26 +++++++ tests/basics/subclass_native2_tuple.py | 21 ++++++ tests/basics/subclass_native3.py | 22 ++++++ tests/basics/subclass_native4.py | 9 +++ tests/basics/subclass_native5.py | 12 ++++ tests/basics/true-value.py | 30 -------- tests/basics/true_value.py | 30 ++++++++ tests/basics/try-as-var.py | 10 --- tests/basics/try-finally-loops.py | 35 --------- tests/basics/try-finally-return.py | 23 ------ tests/basics/try-finally1.py | 71 ------------------ tests/basics/try-reraise.py | 19 ----- tests/basics/try-reraise2.py | 32 --------- tests/basics/try_as_var.py | 10 +++ tests/basics/try_finally1.py | 71 ++++++++++++++++++ tests/basics/try_finally_loops.py | 35 +++++++++ tests/basics/try_finally_return.py | 23 ++++++ tests/basics/try_reraise.py | 19 +++++ tests/basics/try_reraise2.py | 32 +++++++++ tests/basics/with-break.py | 14 ---- tests/basics/with-continue.py | 14 ---- tests/basics/with-return.py | 14 ---- tests/basics/with_break.py | 14 ++++ tests/basics/with_continue.py | 14 ++++ tests/basics/with_return.py | 14 ++++ tests/float/builtin-float-minmax.py | 26 ------- tests/float/builtin_float_minmax.py | 26 +++++++ tests/float/int-divzero.py | 4 -- tests/float/int_divzero.py | 4 ++ tests/float/list-index.py | 8 --- tests/float/list_index.py | 8 +++ tests/float/math-fun-bool.py | 17 ----- tests/float/math-fun.py | 51 ------------- tests/float/math_fun.py | 51 +++++++++++++ tests/float/math_fun_bool.py | 17 +++++ tests/float/string-format-modulo.py | 19 ----- tests/float/string-format.py | 123 -------------------------------- tests/float/string_format.py | 123 ++++++++++++++++++++++++++++++++ tests/float/string_format_modulo.py | 19 +++++ tests/float/true-value.py | 7 -- tests/float/true_value.py | 7 ++ tests/import/import-pkg1.py | 11 --- tests/import/import-pkg2.py | 18 ----- tests/import/import-pkg3.py | 6 -- tests/import/import-pkg4.py | 2 - tests/import/import-pkg5.py | 6 -- tests/import/import_pkg1.py | 11 +++ tests/import/import_pkg2.py | 18 +++++ tests/import/import_pkg3.py | 6 ++ tests/import/import_pkg4.py | 2 + tests/import/import_pkg5.py | 6 ++ tests/import/try-module.py | 15 ---- tests/import/try_module.py | 15 ++++ tests/io/file-iter.py | 3 - tests/io/file-stdio.py | 4 -- tests/io/file-with.py | 21 ------ tests/io/file_iter.py | 3 + tests/io/file_stdio.py | 4 ++ tests/io/file_with.py | 21 ++++++ tests/misc/rge-sm.py | 114 ----------------------------- tests/misc/rge_sm.py | 114 +++++++++++++++++++++++++++++ 196 files changed, 2448 insertions(+), 2448 deletions(-) delete mode 100644 tests/basics/builtin-bin.py delete mode 100644 tests/basics/builtin-callable.py delete mode 100644 tests/basics/builtin-hex.py delete mode 100644 tests/basics/builtin-len1.py delete mode 100644 tests/basics/builtin-minmax.py delete mode 100644 tests/basics/builtin-oct.py create mode 100644 tests/basics/builtin_bin.py create mode 100644 tests/basics/builtin_callable.py create mode 100644 tests/basics/builtin_hex.py create mode 100644 tests/basics/builtin_len1.py create mode 100644 tests/basics/builtin_minmax.py create mode 100644 tests/basics/builtin_oct.py delete mode 100644 tests/basics/class-contains.py delete mode 100644 tests/basics/class-emptybases.py delete mode 100644 tests/basics/class-getattr.py delete mode 100644 tests/basics/class-staticclassmethod.py delete mode 100644 tests/basics/class-subclass-builtin.py delete mode 100644 tests/basics/class-super.py create mode 100644 tests/basics/class_contains.py create mode 100644 tests/basics/class_emptybases.py create mode 100644 tests/basics/class_getattr.py create mode 100644 tests/basics/class_staticclassmethod.py create mode 100644 tests/basics/class_subclass_builtin.py create mode 100644 tests/basics/class_super.py delete mode 100644 tests/basics/closure-defargs.py create mode 100644 tests/basics/closure_defargs.py delete mode 100644 tests/basics/compare-multi.py create mode 100644 tests/basics/compare_multi.py delete mode 100644 tests/basics/del-attr.py delete mode 100644 tests/basics/del-deref.py delete mode 100644 tests/basics/del-local.py delete mode 100644 tests/basics/del-name.py delete mode 100644 tests/basics/del-subscr.py create mode 100644 tests/basics/del_attr.py create mode 100644 tests/basics/del_deref.py create mode 100644 tests/basics/del_local.py create mode 100644 tests/basics/del_name.py create mode 100644 tests/basics/del_subscr.py delete mode 100644 tests/basics/dict-del.py delete mode 100644 tests/basics/dict-from-iter.py delete mode 100644 tests/basics/dict-intern.py create mode 100644 tests/basics/dict_del.py create mode 100644 tests/basics/dict_from_iter.py create mode 100644 tests/basics/dict_intern.py delete mode 100644 tests/basics/fun-annotations.py delete mode 100644 tests/basics/fun-calldblstar.py delete mode 100644 tests/basics/fun-callstar.py delete mode 100644 tests/basics/fun-callstardblstar.py delete mode 100644 tests/basics/fun-defargs.py delete mode 100644 tests/basics/fun-defargs2.py delete mode 100644 tests/basics/fun-kwargs.py delete mode 100644 tests/basics/fun-kwonly.py delete mode 100644 tests/basics/fun-kwonlydef.py delete mode 100644 tests/basics/fun-kwvarargs.py delete mode 100644 tests/basics/fun-varargs.py create mode 100644 tests/basics/fun_annotations.py create mode 100644 tests/basics/fun_calldblstar.py create mode 100644 tests/basics/fun_callstar.py create mode 100644 tests/basics/fun_callstardblstar.py create mode 100644 tests/basics/fun_defargs.py create mode 100644 tests/basics/fun_defargs2.py create mode 100644 tests/basics/fun_kwargs.py create mode 100644 tests/basics/fun_kwonly.py create mode 100644 tests/basics/fun_kwonlydef.py create mode 100644 tests/basics/fun_kwvarargs.py create mode 100644 tests/basics/fun_varargs.py delete mode 100644 tests/basics/gen-yield-from-close.py delete mode 100644 tests/basics/gen-yield-from-ducktype.py delete mode 100644 tests/basics/gen-yield-from-exc.py delete mode 100644 tests/basics/gen-yield-from-iter.py delete mode 100644 tests/basics/gen-yield-from-send.py delete mode 100644 tests/basics/gen-yield-from-throw.py delete mode 100644 tests/basics/gen-yield-from.py create mode 100644 tests/basics/gen_yield_from.py create mode 100644 tests/basics/gen_yield_from_close.py create mode 100644 tests/basics/gen_yield_from_ducktype.py create mode 100644 tests/basics/gen_yield_from_exc.py create mode 100644 tests/basics/gen_yield_from_iter.py create mode 100644 tests/basics/gen_yield_from_send.py create mode 100644 tests/basics/gen_yield_from_throw.py delete mode 100644 tests/basics/generator-args.py delete mode 100644 tests/basics/generator-closure.py delete mode 100644 tests/basics/generator-exc.py delete mode 100644 tests/basics/generator-return.py create mode 100644 tests/basics/generator_args.py create mode 100644 tests/basics/generator_closure.py create mode 100644 tests/basics/generator_exc.py create mode 100644 tests/basics/generator_return.py delete mode 100644 tests/basics/globals-del.py create mode 100644 tests/basics/globals_del.py delete mode 100644 tests/basics/int-big-and.py delete mode 100644 tests/basics/int-big-lshift.py delete mode 100644 tests/basics/int-big-mod.py delete mode 100644 tests/basics/int-big-mul.py delete mode 100644 tests/basics/int-bytes.py delete mode 100644 tests/basics/int-divzero.py delete mode 100644 tests/basics/int-long.py delete mode 100644 tests/basics/int-mpz.py delete mode 100644 tests/basics/int-small.py create mode 100644 tests/basics/int_big_and.py create mode 100644 tests/basics/int_big_lshift.py create mode 100644 tests/basics/int_big_mod.py create mode 100644 tests/basics/int_big_mul.py create mode 100644 tests/basics/int_bytes.py create mode 100644 tests/basics/int_divzero.py create mode 100644 tests/basics/int_long.py create mode 100644 tests/basics/int_mpz.py create mode 100644 tests/basics/int_small.py delete mode 100644 tests/basics/is-isnot.py create mode 100644 tests/basics/is_isnot.py delete mode 100644 tests/basics/iter-of-iter.py create mode 100644 tests/basics/iter_of_iter.py delete mode 100644 tests/basics/seq-unpack.py create mode 100644 tests/basics/seq_unpack.py delete mode 100644 tests/basics/string-compare.py delete mode 100644 tests/basics/string-escape.py delete mode 100644 tests/basics/string-format-modulo.py delete mode 100644 tests/basics/string-format.py delete mode 100644 tests/basics/string-join.py delete mode 100644 tests/basics/string-repr.py delete mode 100644 tests/basics/string-slice.py create mode 100644 tests/basics/string_compare.py create mode 100644 tests/basics/string_escape.py create mode 100644 tests/basics/string_format.py create mode 100644 tests/basics/string_format_modulo.py create mode 100644 tests/basics/string_join.py create mode 100644 tests/basics/string_repr.py create mode 100644 tests/basics/string_slice.py delete mode 100644 tests/basics/subclass-native1.py delete mode 100644 tests/basics/subclass-native2-list.py delete mode 100644 tests/basics/subclass-native2-tuple.py delete mode 100644 tests/basics/subclass-native3.py delete mode 100644 tests/basics/subclass-native4.py delete mode 100644 tests/basics/subclass-native5.py create mode 100644 tests/basics/subclass_native1.py create mode 100644 tests/basics/subclass_native2_list.py create mode 100644 tests/basics/subclass_native2_tuple.py create mode 100644 tests/basics/subclass_native3.py create mode 100644 tests/basics/subclass_native4.py create mode 100644 tests/basics/subclass_native5.py delete mode 100644 tests/basics/true-value.py create mode 100644 tests/basics/true_value.py delete mode 100644 tests/basics/try-as-var.py delete mode 100644 tests/basics/try-finally-loops.py delete mode 100644 tests/basics/try-finally-return.py delete mode 100644 tests/basics/try-finally1.py delete mode 100644 tests/basics/try-reraise.py delete mode 100644 tests/basics/try-reraise2.py create mode 100644 tests/basics/try_as_var.py create mode 100644 tests/basics/try_finally1.py create mode 100644 tests/basics/try_finally_loops.py create mode 100644 tests/basics/try_finally_return.py create mode 100644 tests/basics/try_reraise.py create mode 100644 tests/basics/try_reraise2.py delete mode 100644 tests/basics/with-break.py delete mode 100644 tests/basics/with-continue.py delete mode 100644 tests/basics/with-return.py create mode 100644 tests/basics/with_break.py create mode 100644 tests/basics/with_continue.py create mode 100644 tests/basics/with_return.py delete mode 100644 tests/float/builtin-float-minmax.py create mode 100644 tests/float/builtin_float_minmax.py delete mode 100644 tests/float/int-divzero.py create mode 100644 tests/float/int_divzero.py delete mode 100644 tests/float/list-index.py create mode 100644 tests/float/list_index.py delete mode 100644 tests/float/math-fun-bool.py delete mode 100644 tests/float/math-fun.py create mode 100644 tests/float/math_fun.py create mode 100644 tests/float/math_fun_bool.py delete mode 100644 tests/float/string-format-modulo.py delete mode 100644 tests/float/string-format.py create mode 100644 tests/float/string_format.py create mode 100644 tests/float/string_format_modulo.py delete mode 100644 tests/float/true-value.py create mode 100644 tests/float/true_value.py delete mode 100644 tests/import/import-pkg1.py delete mode 100644 tests/import/import-pkg2.py delete mode 100644 tests/import/import-pkg3.py delete mode 100644 tests/import/import-pkg4.py delete mode 100644 tests/import/import-pkg5.py create mode 100644 tests/import/import_pkg1.py create mode 100644 tests/import/import_pkg2.py create mode 100644 tests/import/import_pkg3.py create mode 100644 tests/import/import_pkg4.py create mode 100644 tests/import/import_pkg5.py delete mode 100644 tests/import/try-module.py create mode 100644 tests/import/try_module.py delete mode 100644 tests/io/file-iter.py delete mode 100644 tests/io/file-stdio.py delete mode 100644 tests/io/file-with.py create mode 100644 tests/io/file_iter.py create mode 100644 tests/io/file_stdio.py create mode 100644 tests/io/file_with.py delete mode 100644 tests/misc/rge-sm.py create mode 100644 tests/misc/rge_sm.py diff --git a/tests/basics/builtin-bin.py b/tests/basics/builtin-bin.py deleted file mode 100644 index f6b6079de..000000000 --- a/tests/basics/builtin-bin.py +++ /dev/null @@ -1,12 +0,0 @@ -# test builtin bin function - -print(bin(1)) -print(bin(-1)) -print(bin(15)) -print(bin(-15)) - -print(bin(12345)) -print(bin(0b10101)) - -print(bin(12345678901234567890)) -print(bin(0b10101010101010101010)) diff --git a/tests/basics/builtin-callable.py b/tests/basics/builtin-callable.py deleted file mode 100644 index caddb885c..000000000 --- a/tests/basics/builtin-callable.py +++ /dev/null @@ -1,5 +0,0 @@ -import sys -print(callable(1)) -print(callable("dfsd")) -print(callable(callable)) -print(callable(sys)) diff --git a/tests/basics/builtin-hex.py b/tests/basics/builtin-hex.py deleted file mode 100644 index 7d1c98a7a..000000000 --- a/tests/basics/builtin-hex.py +++ /dev/null @@ -1,12 +0,0 @@ -# test builtin hex function - -print(hex(1)) -print(hex(-1)) -print(hex(15)) -print(hex(-15)) - -print(hex(12345)) -print(hex(0x12345)) - -print(hex(12345678901234567890)) -print(hex(0x12345678901234567890)) diff --git a/tests/basics/builtin-len1.py b/tests/basics/builtin-len1.py deleted file mode 100644 index 6a082394c..000000000 --- a/tests/basics/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/builtin-minmax.py b/tests/basics/builtin-minmax.py deleted file mode 100644 index 8ee4bbca7..000000000 --- a/tests/basics/builtin-minmax.py +++ /dev/null @@ -1,15 +0,0 @@ -# test builtin min and max functions - -print(min(0,1)) -print(min(1,0)) -print(min(0,-1)) -print(min(-1,0)) - -print(max(0,1)) -print(max(1,0)) -print(max(0,-1)) -print(max(-1,0)) - -print(min([1,2,4,0,-1,2])) -print(max([1,2,4,0,-1,2])) - diff --git a/tests/basics/builtin-oct.py b/tests/basics/builtin-oct.py deleted file mode 100644 index d8ba8e434..000000000 --- a/tests/basics/builtin-oct.py +++ /dev/null @@ -1,12 +0,0 @@ -# test builtin oct function - -print(oct(1)) -print(oct(-1)) -print(oct(15)) -print(oct(-15)) - -print(oct(12345)) -print(oct(0o12345)) - -print(oct(12345678901234567890)) -print(oct(0o12345670123456701234)) diff --git a/tests/basics/builtin_bin.py b/tests/basics/builtin_bin.py new file mode 100644 index 000000000..f6b6079de --- /dev/null +++ b/tests/basics/builtin_bin.py @@ -0,0 +1,12 @@ +# test builtin bin function + +print(bin(1)) +print(bin(-1)) +print(bin(15)) +print(bin(-15)) + +print(bin(12345)) +print(bin(0b10101)) + +print(bin(12345678901234567890)) +print(bin(0b10101010101010101010)) diff --git a/tests/basics/builtin_callable.py b/tests/basics/builtin_callable.py new file mode 100644 index 000000000..caddb885c --- /dev/null +++ b/tests/basics/builtin_callable.py @@ -0,0 +1,5 @@ +import sys +print(callable(1)) +print(callable("dfsd")) +print(callable(callable)) +print(callable(sys)) diff --git a/tests/basics/builtin_hex.py b/tests/basics/builtin_hex.py new file mode 100644 index 000000000..7d1c98a7a --- /dev/null +++ b/tests/basics/builtin_hex.py @@ -0,0 +1,12 @@ +# test builtin hex function + +print(hex(1)) +print(hex(-1)) +print(hex(15)) +print(hex(-15)) + +print(hex(12345)) +print(hex(0x12345)) + +print(hex(12345678901234567890)) +print(hex(0x12345678901234567890)) 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/builtin_minmax.py b/tests/basics/builtin_minmax.py new file mode 100644 index 000000000..8ee4bbca7 --- /dev/null +++ b/tests/basics/builtin_minmax.py @@ -0,0 +1,15 @@ +# test builtin min and max functions + +print(min(0,1)) +print(min(1,0)) +print(min(0,-1)) +print(min(-1,0)) + +print(max(0,1)) +print(max(1,0)) +print(max(0,-1)) +print(max(-1,0)) + +print(min([1,2,4,0,-1,2])) +print(max([1,2,4,0,-1,2])) + diff --git a/tests/basics/builtin_oct.py b/tests/basics/builtin_oct.py new file mode 100644 index 000000000..d8ba8e434 --- /dev/null +++ b/tests/basics/builtin_oct.py @@ -0,0 +1,12 @@ +# test builtin oct function + +print(oct(1)) +print(oct(-1)) +print(oct(15)) +print(oct(-15)) + +print(oct(12345)) +print(oct(0o12345)) + +print(oct(12345678901234567890)) +print(oct(0o12345670123456701234)) diff --git a/tests/basics/class-contains.py b/tests/basics/class-contains.py deleted file mode 100644 index b6dd3661c..000000000 --- a/tests/basics/class-contains.py +++ /dev/null @@ -1,23 +0,0 @@ -# A contains everything -class A: - def __contains__(self, key): - return True - -a = A() -print(True in a) -print(1 in a) -print(() in a) - -# B contains given things -class B: - def __init__(self, items): - self.items = items - def __contains__(self, key): - return key in self.items - -b = B([]) -print(1 in b) -b = B([1, 2]) -print(1 in b) -print(2 in b) -print(3 in b) diff --git a/tests/basics/class-emptybases.py b/tests/basics/class-emptybases.py deleted file mode 100644 index 6d792453e..000000000 --- a/tests/basics/class-emptybases.py +++ /dev/null @@ -1,2 +0,0 @@ -class A(): - pass diff --git a/tests/basics/class-getattr.py b/tests/basics/class-getattr.py deleted file mode 100644 index 1f875ce53..000000000 --- a/tests/basics/class-getattr.py +++ /dev/null @@ -1,16 +0,0 @@ -# test that __getattr__, __getattrribute__ and instance members don't override builtins -class C: - def __init__(self): - self.__add__ = lambda: print('member __add__') - def __add__(self, x): - print('__add__') - def __getattr__(self, attr): - print('__getattr__', attr) - return None - def __getattrribute__(self, attr): - print('__getattrribute__', attr) - return None - -c = C() -c.__add__ -c + 1 # should call __add__ diff --git a/tests/basics/class-staticclassmethod.py b/tests/basics/class-staticclassmethod.py deleted file mode 100644 index 1cb59d5c7..000000000 --- a/tests/basics/class-staticclassmethod.py +++ /dev/null @@ -1,25 +0,0 @@ -# test static and class methods - -class C: - @staticmethod - def f(rhs): - print('f', rhs) - @classmethod - def g(self, rhs): - print('g', rhs) - - # builtin wrapped in staticmethod - @staticmethod - def __sub__(rhs): - print('sub', rhs) - # builtin wrapped in classmethod - @classmethod - def __add__(self, rhs): - print('add', rhs) - -c = C() - -c.f(0) -c.g(0) -c - 1 -c + 2 diff --git a/tests/basics/class-subclass-builtin.py b/tests/basics/class-subclass-builtin.py deleted file mode 100644 index 7eb7d44b4..000000000 --- a/tests/basics/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/class-super.py b/tests/basics/class-super.py deleted file mode 100644 index 0f2852a47..000000000 --- a/tests/basics/class-super.py +++ /dev/null @@ -1,16 +0,0 @@ -class Base: - - def __init__(self): - self.a = 1 - - def meth(self): - print("in Base meth", self.a) - -class Sub(Base): - - def meth(self): - print("in Sub meth") - return super().meth() - -a = Sub() -a.meth() diff --git a/tests/basics/class_contains.py b/tests/basics/class_contains.py new file mode 100644 index 000000000..b6dd3661c --- /dev/null +++ b/tests/basics/class_contains.py @@ -0,0 +1,23 @@ +# A contains everything +class A: + def __contains__(self, key): + return True + +a = A() +print(True in a) +print(1 in a) +print(() in a) + +# B contains given things +class B: + def __init__(self, items): + self.items = items + def __contains__(self, key): + return key in self.items + +b = B([]) +print(1 in b) +b = B([1, 2]) +print(1 in b) +print(2 in b) +print(3 in b) diff --git a/tests/basics/class_emptybases.py b/tests/basics/class_emptybases.py new file mode 100644 index 000000000..6d792453e --- /dev/null +++ b/tests/basics/class_emptybases.py @@ -0,0 +1,2 @@ +class A(): + pass diff --git a/tests/basics/class_getattr.py b/tests/basics/class_getattr.py new file mode 100644 index 000000000..1f875ce53 --- /dev/null +++ b/tests/basics/class_getattr.py @@ -0,0 +1,16 @@ +# test that __getattr__, __getattrribute__ and instance members don't override builtins +class C: + def __init__(self): + self.__add__ = lambda: print('member __add__') + def __add__(self, x): + print('__add__') + def __getattr__(self, attr): + print('__getattr__', attr) + return None + def __getattrribute__(self, attr): + print('__getattrribute__', attr) + return None + +c = C() +c.__add__ +c + 1 # should call __add__ diff --git a/tests/basics/class_staticclassmethod.py b/tests/basics/class_staticclassmethod.py new file mode 100644 index 000000000..1cb59d5c7 --- /dev/null +++ b/tests/basics/class_staticclassmethod.py @@ -0,0 +1,25 @@ +# test static and class methods + +class C: + @staticmethod + def f(rhs): + print('f', rhs) + @classmethod + def g(self, rhs): + print('g', rhs) + + # builtin wrapped in staticmethod + @staticmethod + def __sub__(rhs): + print('sub', rhs) + # builtin wrapped in classmethod + @classmethod + def __add__(self, rhs): + print('add', rhs) + +c = C() + +c.f(0) +c.g(0) +c - 1 +c + 2 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/class_super.py b/tests/basics/class_super.py new file mode 100644 index 000000000..0f2852a47 --- /dev/null +++ b/tests/basics/class_super.py @@ -0,0 +1,16 @@ +class Base: + + def __init__(self): + self.a = 1 + + def meth(self): + print("in Base meth", self.a) + +class Sub(Base): + + def meth(self): + print("in Sub meth") + return super().meth() + +a = Sub() +a.meth() diff --git a/tests/basics/closure-defargs.py b/tests/basics/closure-defargs.py deleted file mode 100644 index 96b109265..000000000 --- a/tests/basics/closure-defargs.py +++ /dev/null @@ -1,11 +0,0 @@ -# test closure with default args - -def f(): - a = 1 - def bar(b = 10, c = 20): - print(a + b + c) - bar() - bar(2) - bar(2, 3) - -print(f()) diff --git a/tests/basics/closure_defargs.py b/tests/basics/closure_defargs.py new file mode 100644 index 000000000..96b109265 --- /dev/null +++ b/tests/basics/closure_defargs.py @@ -0,0 +1,11 @@ +# test closure with default args + +def f(): + a = 1 + def bar(b = 10, c = 20): + print(a + b + c) + bar() + bar(2) + bar(2, 3) + +print(f()) diff --git a/tests/basics/compare-multi.py b/tests/basics/compare-multi.py deleted file mode 100644 index 1abd18067..000000000 --- a/tests/basics/compare-multi.py +++ /dev/null @@ -1,4 +0,0 @@ -print(1 < 2 < 3) -print(1 < 2 < 3 < 4) -print(1 > 2 < 3) -print(1 < 2 > 3) diff --git a/tests/basics/compare_multi.py b/tests/basics/compare_multi.py new file mode 100644 index 000000000..1abd18067 --- /dev/null +++ b/tests/basics/compare_multi.py @@ -0,0 +1,4 @@ +print(1 < 2 < 3) +print(1 < 2 < 3 < 4) +print(1 > 2 < 3) +print(1 < 2 > 3) diff --git a/tests/basics/del-attr.py b/tests/basics/del-attr.py deleted file mode 100644 index bec7afb84..000000000 --- a/tests/basics/del-attr.py +++ /dev/null @@ -1,32 +0,0 @@ -class C: - def f(): - pass - -# del a class attribute - -del C.f -try: - print(C.x) -except AttributeError: - print("AttributeError") -try: - del C.f -except AttributeError: - print("AttributeError") - -# del an instance attribute - -c = C() - -c.x = 1 -print(c.x) - -del c.x -try: - print(c.x) -except AttributeError: - print("AttributeError") -try: - del c.x -except AttributeError: - print("AttributeError") diff --git a/tests/basics/del-deref.py b/tests/basics/del-deref.py deleted file mode 100644 index 1e7c0e41f..000000000 --- a/tests/basics/del-deref.py +++ /dev/null @@ -1,22 +0,0 @@ -def f(): - x = 1 - y = 2 - def g(): - nonlocal x - print(y) - try: - print(x) - except NameError: - print("NameError") - def h(): - nonlocal x - print(y) - try: - del x - except NameError: - print("NameError") - print(x, y) - del x - g() - h() -f() diff --git a/tests/basics/del-local.py b/tests/basics/del-local.py deleted file mode 100644 index 05aa98b42..000000000 --- a/tests/basics/del-local.py +++ /dev/null @@ -1,25 +0,0 @@ -# delete local then try to reference it -def f(): - x = 1 - y = 2 - print(x, y) - del x - print(y) - try: - print(x) - except NameError: - print("NameError"); -f() - -# delete local then try to delete it again -def g(): - x = 3 - y = 4 - print(x, y) - del x - print(y) - try: - del x - except NameError: - print("NameError"); -g() diff --git a/tests/basics/del-name.py b/tests/basics/del-name.py deleted file mode 100644 index f75a2f5dc..000000000 --- a/tests/basics/del-name.py +++ /dev/null @@ -1,18 +0,0 @@ -# del global - -x = 1 -print(x) -del x -try: - print(x) -except NameError: - print("NameError") -try: - del x -except: # NameError: - # FIXME uPy returns KeyError for this - print("NameError") - -class C: - def f(): - pass diff --git a/tests/basics/del-subscr.py b/tests/basics/del-subscr.py deleted file mode 100644 index 67910c623..000000000 --- a/tests/basics/del-subscr.py +++ /dev/null @@ -1,13 +0,0 @@ -l = [1, 2, 3] -print(l) -del l[0] -print(l) -del l[-1] -print(l) - -d = {1:2, 3:4, 5:6} -del d[1] -del d[3] -print(d) -del d[5] -print(d) diff --git a/tests/basics/del_attr.py b/tests/basics/del_attr.py new file mode 100644 index 000000000..bec7afb84 --- /dev/null +++ b/tests/basics/del_attr.py @@ -0,0 +1,32 @@ +class C: + def f(): + pass + +# del a class attribute + +del C.f +try: + print(C.x) +except AttributeError: + print("AttributeError") +try: + del C.f +except AttributeError: + print("AttributeError") + +# del an instance attribute + +c = C() + +c.x = 1 +print(c.x) + +del c.x +try: + print(c.x) +except AttributeError: + print("AttributeError") +try: + del c.x +except AttributeError: + print("AttributeError") diff --git a/tests/basics/del_deref.py b/tests/basics/del_deref.py new file mode 100644 index 000000000..1e7c0e41f --- /dev/null +++ b/tests/basics/del_deref.py @@ -0,0 +1,22 @@ +def f(): + x = 1 + y = 2 + def g(): + nonlocal x + print(y) + try: + print(x) + except NameError: + print("NameError") + def h(): + nonlocal x + print(y) + try: + del x + except NameError: + print("NameError") + print(x, y) + del x + g() + h() +f() diff --git a/tests/basics/del_local.py b/tests/basics/del_local.py new file mode 100644 index 000000000..05aa98b42 --- /dev/null +++ b/tests/basics/del_local.py @@ -0,0 +1,25 @@ +# delete local then try to reference it +def f(): + x = 1 + y = 2 + print(x, y) + del x + print(y) + try: + print(x) + except NameError: + print("NameError"); +f() + +# delete local then try to delete it again +def g(): + x = 3 + y = 4 + print(x, y) + del x + print(y) + try: + del x + except NameError: + print("NameError"); +g() diff --git a/tests/basics/del_name.py b/tests/basics/del_name.py new file mode 100644 index 000000000..f75a2f5dc --- /dev/null +++ b/tests/basics/del_name.py @@ -0,0 +1,18 @@ +# del global + +x = 1 +print(x) +del x +try: + print(x) +except NameError: + print("NameError") +try: + del x +except: # NameError: + # FIXME uPy returns KeyError for this + print("NameError") + +class C: + def f(): + pass diff --git a/tests/basics/del_subscr.py b/tests/basics/del_subscr.py new file mode 100644 index 000000000..67910c623 --- /dev/null +++ b/tests/basics/del_subscr.py @@ -0,0 +1,13 @@ +l = [1, 2, 3] +print(l) +del l[0] +print(l) +del l[-1] +print(l) + +d = {1:2, 3:4, 5:6} +del d[1] +del d[3] +print(d) +del d[5] +print(d) diff --git a/tests/basics/dict-del.py b/tests/basics/dict-del.py deleted file mode 100644 index d908fea42..000000000 --- a/tests/basics/dict-del.py +++ /dev/null @@ -1,21 +0,0 @@ -for n in range(20): - print('testing dict with {} items'.format(n)) - for i in range(n): - # create dict - d = dict() - for j in range(n): - d[str(j)] = j - print(len(d)) - - # delete an item - del d[str(i)] - print(len(d)) - - # check items - for j in range(n): - if str(j) in d: - if j == i: - print(j, 'in d, but it should not be') - else: - if j != i: - print(j, 'not in d, but it should be') diff --git a/tests/basics/dict-from-iter.py b/tests/basics/dict-from-iter.py deleted file mode 100644 index dc76801ff..000000000 --- a/tests/basics/dict-from-iter.py +++ /dev/null @@ -1,14 +0,0 @@ -print(dict([(1, "foo")])) -d = dict([("foo", "foo2"), ("bar", "baz")]) -print(sorted(d.keys())) -print(sorted(d.values())) - -try: - dict(((1,),)) -except ValueError: - print("ValueError") - -try: - dict(((1, 2, 3),)) -except ValueError: - print("ValueError") diff --git a/tests/basics/dict-intern.py b/tests/basics/dict-intern.py deleted file mode 100644 index 93efb2da8..000000000 --- a/tests/basics/dict-intern.py +++ /dev/null @@ -1,15 +0,0 @@ -# check that interned strings are compared against non-interned strings - -di = {"key1": "value"} - -# lookup interned string -k = "key1" -print(k in di) - -# lookup non-interned string -k2 = "key" + "1" -print(k == k2) -print(k2 in di) - -# lookup non-interned string -print("".join(['k', 'e', 'y', '1']) in di) diff --git a/tests/basics/dict_del.py b/tests/basics/dict_del.py new file mode 100644 index 000000000..d908fea42 --- /dev/null +++ b/tests/basics/dict_del.py @@ -0,0 +1,21 @@ +for n in range(20): + print('testing dict with {} items'.format(n)) + for i in range(n): + # create dict + d = dict() + for j in range(n): + d[str(j)] = j + print(len(d)) + + # delete an item + del d[str(i)] + print(len(d)) + + # check items + for j in range(n): + if str(j) in d: + if j == i: + print(j, 'in d, but it should not be') + else: + if j != i: + print(j, 'not in d, but it should be') diff --git a/tests/basics/dict_from_iter.py b/tests/basics/dict_from_iter.py new file mode 100644 index 000000000..dc76801ff --- /dev/null +++ b/tests/basics/dict_from_iter.py @@ -0,0 +1,14 @@ +print(dict([(1, "foo")])) +d = dict([("foo", "foo2"), ("bar", "baz")]) +print(sorted(d.keys())) +print(sorted(d.values())) + +try: + dict(((1,),)) +except ValueError: + print("ValueError") + +try: + dict(((1, 2, 3),)) +except ValueError: + print("ValueError") diff --git a/tests/basics/dict_intern.py b/tests/basics/dict_intern.py new file mode 100644 index 000000000..93efb2da8 --- /dev/null +++ b/tests/basics/dict_intern.py @@ -0,0 +1,15 @@ +# check that interned strings are compared against non-interned strings + +di = {"key1": "value"} + +# lookup interned string +k = "key1" +print(k in di) + +# lookup non-interned string +k2 = "key" + "1" +print(k == k2) +print(k2 in di) + +# lookup non-interned string +print("".join(['k', 'e', 'y', '1']) in di) diff --git a/tests/basics/fun-annotations.py b/tests/basics/fun-annotations.py deleted file mode 100644 index 85f808ab5..000000000 --- a/tests/basics/fun-annotations.py +++ /dev/null @@ -1,4 +0,0 @@ -def foo(x: int, y: list) -> dict: - return {x: y} - -print(foo(1, [2, 3])) diff --git a/tests/basics/fun-calldblstar.py b/tests/basics/fun-calldblstar.py deleted file mode 100644 index aae9828cf..000000000 --- a/tests/basics/fun-calldblstar.py +++ /dev/null @@ -1,17 +0,0 @@ -# test calling a function with keywords given by **dict - -def f(a, b): - print(a, b) - -f(1, **{'b':2}) -f(1, **{'b':val for val in range(1)}) - -# test calling a method with keywords given by **dict - -class A: - def f(self, a, b): - print(a, b) - -a = A() -a.f(1, **{'b':2}) -a.f(1, **{'b':val for val in range(1)}) diff --git a/tests/basics/fun-callstar.py b/tests/basics/fun-callstar.py deleted file mode 100644 index 255563b26..000000000 --- a/tests/basics/fun-callstar.py +++ /dev/null @@ -1,33 +0,0 @@ -# function calls with *pos - -def foo(a, b, c): - print(a, b, c) - -foo(*(1, 2, 3)) -foo(1, *(2, 3)) -foo(1, 2, *(3,)) -foo(1, 2, 3, *()) - -# Another sequence type -foo(1, 2, *[100]) - -# Iterator -foo(*range(3)) - -# method calls with *pos - -class A: - def foo(self, a, b, c): - print(a, b, c) - -a = A() -a.foo(*(1, 2, 3)) -a.foo(1, *(2, 3)) -a.foo(1, 2, *(3,)) -a.foo(1, 2, 3, *()) - -# Another sequence type -a.foo(1, 2, *[100]) - -# Iterator -a.foo(*range(3)) diff --git a/tests/basics/fun-callstardblstar.py b/tests/basics/fun-callstardblstar.py deleted file mode 100644 index f2fd29107..000000000 --- a/tests/basics/fun-callstardblstar.py +++ /dev/null @@ -1,17 +0,0 @@ -# test calling a function with *tuple and **dict - -def f(a, b, c, d): - print(a, b, c, d) - -f(*(1, 2), **{'c':3, 'd':4}) -f(*(1, 2), **{['c', 'd'][i]:(3 + i) for i in range(2)}) - -# test calling a method with *tuple and **dict - -class A: - def f(self, a, b, c, d): - print(a, b, c, d) - -a = A() -a.f(*(1, 2), **{'c':3, 'd':4}) -a.f(*(1, 2), **{['c', 'd'][i]:(3 + i) for i in range(2)}) diff --git a/tests/basics/fun-defargs.py b/tests/basics/fun-defargs.py deleted file mode 100644 index ed25f5739..000000000 --- a/tests/basics/fun-defargs.py +++ /dev/null @@ -1,20 +0,0 @@ -def fun1(val=5): - print(val) - -fun1() -fun1(10) - -def fun2(p1, p2=100, p3="foo"): - print(p1, p2, p3) - -fun2(1) -fun2(1, None) -fun2(0, "bar", 200) -try: - fun2() -except TypeError: - print("TypeError") -try: - fun2(1, 2, 3, 4) -except TypeError: - print("TypeError") diff --git a/tests/basics/fun-defargs2.py b/tests/basics/fun-defargs2.py deleted file mode 100644 index 8b72ed8b1..000000000 --- a/tests/basics/fun-defargs2.py +++ /dev/null @@ -1,19 +0,0 @@ -# overriding default arguments - -def foo(a, b=3): - print(a, b) - -# override with positional -foo(1, 333) - -# override with keyword -foo(1, b=333) - -# override with keyword -foo(a=2, b=333) - -def foo2(a=1, b=2): - print(a, b) - -# default and keyword -foo2(b='two') diff --git a/tests/basics/fun-kwargs.py b/tests/basics/fun-kwargs.py deleted file mode 100644 index 9f4f2b7d3..000000000 --- a/tests/basics/fun-kwargs.py +++ /dev/null @@ -1,35 +0,0 @@ -def f1(a): - print(a) - -f1(123) -f1(a=123) -try: - f1(b=123) -except TypeError: - print("TypeError") - -def f2(a, b): - print(a, b) - -f2(1, 2) -f2(a=3, b=4) -f2(b=5, a=6) -f2(7, b=8) -try: - f2(9, a=10) -except TypeError: - print("TypeError") - -def f3(a, b, *args): - print(a, b, args) - - -f3(1, b=3) -try: - f3(1, a=3) -except TypeError: - print("TypeError") -try: - f3(1, 2, 3, 4, a=5) -except TypeError: - print("TypeError") diff --git a/tests/basics/fun-kwonly.py b/tests/basics/fun-kwonly.py deleted file mode 100644 index bdff3a821..000000000 --- a/tests/basics/fun-kwonly.py +++ /dev/null @@ -1,59 +0,0 @@ -# to test keyword-only arguments - -# simplest case -def f(*, a): - print(a) - -f(a=1) - -# with 2 keyword-only args -def f(*, a, b): - print(a, b) - -f(a=1, b=2) -f(b=1, a=2) - -# positional followed by bare star -def f(a, *, b, c): - print(a, b, c) - -f(1, b=3, c=4) -f(1, c=3, b=4) -f(1, **{'b':'3', 'c':4}) - -try: - f(1) -except TypeError: - print("TypeError") - -try: - f(1, b=2) -except TypeError: - print("TypeError") - -try: - f(1, c=2) -except TypeError: - print("TypeError") - -# with **kw -def f(a, *, b, **kw): - print(a, b, kw) - -f(1, b=2) -f(1, b=2, c=3) - -# with named star -def f(*a, b, c): - print(a, b, c) - -f(b=1, c=2) -f(c=1, b=2) - -# with positional and named star -def f(a, *b, c): - print(a, b, c) - -f(1, c=2) -f(1, 2, c=3) -f(a=1, c=3) diff --git a/tests/basics/fun-kwonlydef.py b/tests/basics/fun-kwonlydef.py deleted file mode 100644 index 56a08ee81..000000000 --- a/tests/basics/fun-kwonlydef.py +++ /dev/null @@ -1,36 +0,0 @@ -# test function args, keyword only with default value - -# a single arg with a default -def f1(*, a=1): - print(a) -f1() -f1(a=2) - -# 1 arg default, 1 not -def f2(*, a=1, b): - print(a, b) -f2(b=2) -f2(a=2, b=3) - -# 1 positional, 1 arg default, 1 not -def f3(a, *, b=2, c): - print(a, b, c) -f3(1, c=3) -f3(1, b=3, c=4) -f3(1, **{'c':3}) -f3(1, **{'b':'3', 'c':4}) - -# many args, not all with defaults -def f4(*, a=1, b, c=3, d, e=5, f): - print(a, b, c, d, e, f) -f4(b=2, d=4, f=6) -f4(a=11, b=2, d=4, f=6) -f4(a=11, b=2, c=33, d=4, e=55, f=6) -f4(f=6, e=55, d=4, c=33, b=2, a=11) - -# positional with default, then keyword only -def f5(a, b=4, *c, d=8): - print(a, b, c, d) -f5(1) -f5(1, d=9) -f5(1, b=44, d=9) diff --git a/tests/basics/fun-kwvarargs.py b/tests/basics/fun-kwvarargs.py deleted file mode 100644 index 6350d20d6..000000000 --- a/tests/basics/fun-kwvarargs.py +++ /dev/null @@ -1,19 +0,0 @@ -def f1(**kwargs): - print(kwargs) - -f1() -f1(a=1) - -def f2(a, **kwargs): - print(a, kwargs) - -f2(1) -f2(1, b=2) - -def f3(a, *vargs, **kwargs): - print(a, vargs, kwargs) - -f3(1) -f3(1, 2) -f3(1, b=2) -f3(1, 2, b=3) diff --git a/tests/basics/fun-varargs.py b/tests/basics/fun-varargs.py deleted file mode 100644 index ff29c33f7..000000000 --- a/tests/basics/fun-varargs.py +++ /dev/null @@ -1,41 +0,0 @@ -# function with just varargs -def f1(*args): - print(args) - -f1() -f1(1) -f1(1, 2) - -# function with 1 arg, then varargs -def f2(a, *args): - print(a, args) - -f2(1) -f2(1, 2) -f2(1, 2, 3) - -# function with 2 args, then varargs -def f3(a, b, *args): - print(a, b, args) - -f3(1, 2) -f3(1, 2, 3) -f3(1, 2, 3, 4) - -# function with 1 default arg, then varargs -def f4(a=0, *args): - print(a, args) - -f4() -f4(1) -f4(1, 2) -f4(1, 2, 3) - -# function with 1 arg, 1 default arg, then varargs -def f5(a, b=0, *args): - print(a, b, args) - -f5(1) -f5(1, 2) -f5(1, 2, 3) -f5(1, 2, 3, 4) diff --git a/tests/basics/fun_annotations.py b/tests/basics/fun_annotations.py new file mode 100644 index 000000000..85f808ab5 --- /dev/null +++ b/tests/basics/fun_annotations.py @@ -0,0 +1,4 @@ +def foo(x: int, y: list) -> dict: + return {x: y} + +print(foo(1, [2, 3])) diff --git a/tests/basics/fun_calldblstar.py b/tests/basics/fun_calldblstar.py new file mode 100644 index 000000000..aae9828cf --- /dev/null +++ b/tests/basics/fun_calldblstar.py @@ -0,0 +1,17 @@ +# test calling a function with keywords given by **dict + +def f(a, b): + print(a, b) + +f(1, **{'b':2}) +f(1, **{'b':val for val in range(1)}) + +# test calling a method with keywords given by **dict + +class A: + def f(self, a, b): + print(a, b) + +a = A() +a.f(1, **{'b':2}) +a.f(1, **{'b':val for val in range(1)}) diff --git a/tests/basics/fun_callstar.py b/tests/basics/fun_callstar.py new file mode 100644 index 000000000..255563b26 --- /dev/null +++ b/tests/basics/fun_callstar.py @@ -0,0 +1,33 @@ +# function calls with *pos + +def foo(a, b, c): + print(a, b, c) + +foo(*(1, 2, 3)) +foo(1, *(2, 3)) +foo(1, 2, *(3,)) +foo(1, 2, 3, *()) + +# Another sequence type +foo(1, 2, *[100]) + +# Iterator +foo(*range(3)) + +# method calls with *pos + +class A: + def foo(self, a, b, c): + print(a, b, c) + +a = A() +a.foo(*(1, 2, 3)) +a.foo(1, *(2, 3)) +a.foo(1, 2, *(3,)) +a.foo(1, 2, 3, *()) + +# Another sequence type +a.foo(1, 2, *[100]) + +# Iterator +a.foo(*range(3)) diff --git a/tests/basics/fun_callstardblstar.py b/tests/basics/fun_callstardblstar.py new file mode 100644 index 000000000..f2fd29107 --- /dev/null +++ b/tests/basics/fun_callstardblstar.py @@ -0,0 +1,17 @@ +# test calling a function with *tuple and **dict + +def f(a, b, c, d): + print(a, b, c, d) + +f(*(1, 2), **{'c':3, 'd':4}) +f(*(1, 2), **{['c', 'd'][i]:(3 + i) for i in range(2)}) + +# test calling a method with *tuple and **dict + +class A: + def f(self, a, b, c, d): + print(a, b, c, d) + +a = A() +a.f(*(1, 2), **{'c':3, 'd':4}) +a.f(*(1, 2), **{['c', 'd'][i]:(3 + i) for i in range(2)}) diff --git a/tests/basics/fun_defargs.py b/tests/basics/fun_defargs.py new file mode 100644 index 000000000..ed25f5739 --- /dev/null +++ b/tests/basics/fun_defargs.py @@ -0,0 +1,20 @@ +def fun1(val=5): + print(val) + +fun1() +fun1(10) + +def fun2(p1, p2=100, p3="foo"): + print(p1, p2, p3) + +fun2(1) +fun2(1, None) +fun2(0, "bar", 200) +try: + fun2() +except TypeError: + print("TypeError") +try: + fun2(1, 2, 3, 4) +except TypeError: + print("TypeError") diff --git a/tests/basics/fun_defargs2.py b/tests/basics/fun_defargs2.py new file mode 100644 index 000000000..8b72ed8b1 --- /dev/null +++ b/tests/basics/fun_defargs2.py @@ -0,0 +1,19 @@ +# overriding default arguments + +def foo(a, b=3): + print(a, b) + +# override with positional +foo(1, 333) + +# override with keyword +foo(1, b=333) + +# override with keyword +foo(a=2, b=333) + +def foo2(a=1, b=2): + print(a, b) + +# default and keyword +foo2(b='two') diff --git a/tests/basics/fun_kwargs.py b/tests/basics/fun_kwargs.py new file mode 100644 index 000000000..9f4f2b7d3 --- /dev/null +++ b/tests/basics/fun_kwargs.py @@ -0,0 +1,35 @@ +def f1(a): + print(a) + +f1(123) +f1(a=123) +try: + f1(b=123) +except TypeError: + print("TypeError") + +def f2(a, b): + print(a, b) + +f2(1, 2) +f2(a=3, b=4) +f2(b=5, a=6) +f2(7, b=8) +try: + f2(9, a=10) +except TypeError: + print("TypeError") + +def f3(a, b, *args): + print(a, b, args) + + +f3(1, b=3) +try: + f3(1, a=3) +except TypeError: + print("TypeError") +try: + f3(1, 2, 3, 4, a=5) +except TypeError: + print("TypeError") diff --git a/tests/basics/fun_kwonly.py b/tests/basics/fun_kwonly.py new file mode 100644 index 000000000..bdff3a821 --- /dev/null +++ b/tests/basics/fun_kwonly.py @@ -0,0 +1,59 @@ +# to test keyword-only arguments + +# simplest case +def f(*, a): + print(a) + +f(a=1) + +# with 2 keyword-only args +def f(*, a, b): + print(a, b) + +f(a=1, b=2) +f(b=1, a=2) + +# positional followed by bare star +def f(a, *, b, c): + print(a, b, c) + +f(1, b=3, c=4) +f(1, c=3, b=4) +f(1, **{'b':'3', 'c':4}) + +try: + f(1) +except TypeError: + print("TypeError") + +try: + f(1, b=2) +except TypeError: + print("TypeError") + +try: + f(1, c=2) +except TypeError: + print("TypeError") + +# with **kw +def f(a, *, b, **kw): + print(a, b, kw) + +f(1, b=2) +f(1, b=2, c=3) + +# with named star +def f(*a, b, c): + print(a, b, c) + +f(b=1, c=2) +f(c=1, b=2) + +# with positional and named star +def f(a, *b, c): + print(a, b, c) + +f(1, c=2) +f(1, 2, c=3) +f(a=1, c=3) diff --git a/tests/basics/fun_kwonlydef.py b/tests/basics/fun_kwonlydef.py new file mode 100644 index 000000000..56a08ee81 --- /dev/null +++ b/tests/basics/fun_kwonlydef.py @@ -0,0 +1,36 @@ +# test function args, keyword only with default value + +# a single arg with a default +def f1(*, a=1): + print(a) +f1() +f1(a=2) + +# 1 arg default, 1 not +def f2(*, a=1, b): + print(a, b) +f2(b=2) +f2(a=2, b=3) + +# 1 positional, 1 arg default, 1 not +def f3(a, *, b=2, c): + print(a, b, c) +f3(1, c=3) +f3(1, b=3, c=4) +f3(1, **{'c':3}) +f3(1, **{'b':'3', 'c':4}) + +# many args, not all with defaults +def f4(*, a=1, b, c=3, d, e=5, f): + print(a, b, c, d, e, f) +f4(b=2, d=4, f=6) +f4(a=11, b=2, d=4, f=6) +f4(a=11, b=2, c=33, d=4, e=55, f=6) +f4(f=6, e=55, d=4, c=33, b=2, a=11) + +# positional with default, then keyword only +def f5(a, b=4, *c, d=8): + print(a, b, c, d) +f5(1) +f5(1, d=9) +f5(1, b=44, d=9) diff --git a/tests/basics/fun_kwvarargs.py b/tests/basics/fun_kwvarargs.py new file mode 100644 index 000000000..6350d20d6 --- /dev/null +++ b/tests/basics/fun_kwvarargs.py @@ -0,0 +1,19 @@ +def f1(**kwargs): + print(kwargs) + +f1() +f1(a=1) + +def f2(a, **kwargs): + print(a, kwargs) + +f2(1) +f2(1, b=2) + +def f3(a, *vargs, **kwargs): + print(a, vargs, kwargs) + +f3(1) +f3(1, 2) +f3(1, b=2) +f3(1, 2, b=3) diff --git a/tests/basics/fun_varargs.py b/tests/basics/fun_varargs.py new file mode 100644 index 000000000..ff29c33f7 --- /dev/null +++ b/tests/basics/fun_varargs.py @@ -0,0 +1,41 @@ +# function with just varargs +def f1(*args): + print(args) + +f1() +f1(1) +f1(1, 2) + +# function with 1 arg, then varargs +def f2(a, *args): + print(a, args) + +f2(1) +f2(1, 2) +f2(1, 2, 3) + +# function with 2 args, then varargs +def f3(a, b, *args): + print(a, b, args) + +f3(1, 2) +f3(1, 2, 3) +f3(1, 2, 3, 4) + +# function with 1 default arg, then varargs +def f4(a=0, *args): + print(a, args) + +f4() +f4(1) +f4(1, 2) +f4(1, 2, 3) + +# function with 1 arg, 1 default arg, then varargs +def f5(a, b=0, *args): + print(a, b, args) + +f5(1) +f5(1, 2) +f5(1, 2, 3) +f5(1, 2, 3, 4) diff --git a/tests/basics/gen-yield-from-close.py b/tests/basics/gen-yield-from-close.py deleted file mode 100644 index 7982d5c99..000000000 --- a/tests/basics/gen-yield-from-close.py +++ /dev/null @@ -1,87 +0,0 @@ -def gen(): - yield 1 - yield 2 - yield 3 - yield 4 - -def gen2(): - yield -1 - print((yield from gen())) - yield 10 - yield 11 - -g = gen2() -print(next(g)) -print(next(g)) -g.close() -try: - print(next(g)) -except StopIteration: - print("StopIteration") - - -# Now variation of same test, but with leaf generator -# swallowing GeneratorExit exception - its upstream gen -# generator should still receive one. -def gen3(): - yield 1 - try: - yield 2 - except GeneratorExit: - print("leaf caught GeneratorExit and swallowed it") - return - yield 3 - yield 4 - -def gen4(): - yield -1 - try: - print((yield from gen3())) - except GeneratorExit: - print("delegating caught GeneratorExit") - raise - yield 10 - yield 11 - -g = gen4() -print(next(g)) -print(next(g)) -print(next(g)) -g.close() -try: - print(next(g)) -except StopIteration: - print("StopIteration") - - -# Yet another variation - leaf generator gets GeneratorExit, -# but raises StopIteration instead. This still should close chain properly. -def gen5(): - yield 1 - try: - yield 2 - except GeneratorExit: - print("leaf caught GeneratorExit and raised StopIteration instead") - raise StopIteration(123) - yield 3 - yield 4 - -def gen6(): - yield -1 - try: - print((yield from gen5())) - except GeneratorExit: - print("delegating caught GeneratorExit") - raise - yield 10 - yield 11 - -g = gen6() -print(next(g)) -print(next(g)) -print(next(g)) -g.close() -try: - print(next(g)) -except StopIteration: - print("StopIteration") diff --git a/tests/basics/gen-yield-from-ducktype.py b/tests/basics/gen-yield-from-ducktype.py deleted file mode 100644 index aa0109c91..000000000 --- a/tests/basics/gen-yield-from-ducktype.py +++ /dev/null @@ -1,44 +0,0 @@ -class MyGen: - - def __init__(self): - self.v = 0 - - def __iter__(self): - return self - - def __next__(self): - self.v += 1 - if self.v > 5: - raise StopIteration - return self.v - -def gen(): - yield from MyGen() - -def gen2(): - yield from gen() - -print(list(gen())) -print(list(gen2())) - - -class Incrementer: - - def __iter__(self): - return self - - def __next__(self): - return self.send(None) - - def send(self, val): - if val is None: - return "Incrementer initialized" - return val + 1 - -def gen3(): - yield from Incrementer() - -g = gen3() -print(next(g)) -print(g.send(5)) -print(g.send(100)) diff --git a/tests/basics/gen-yield-from-exc.py b/tests/basics/gen-yield-from-exc.py deleted file mode 100644 index 01c954f5b..000000000 --- a/tests/basics/gen-yield-from-exc.py +++ /dev/null @@ -1,13 +0,0 @@ -def gen(): - yield 1 - yield 2 - raise ValueError - -def gen2(): - try: - print((yield from gen())) - except ValueError: - print("caught ValueError from downstream") - -g = gen2() -print(list(g)) diff --git a/tests/basics/gen-yield-from-iter.py b/tests/basics/gen-yield-from-iter.py deleted file mode 100644 index 2d06328fb..000000000 --- a/tests/basics/gen-yield-from-iter.py +++ /dev/null @@ -1,8 +0,0 @@ -def gen(): - yield from (1, 2, 3) - -def gen2(): - yield from gen() - -print(list(gen())) -print(list(gen2())) diff --git a/tests/basics/gen-yield-from-send.py b/tests/basics/gen-yield-from-send.py deleted file mode 100644 index c2e94b5ad..000000000 --- a/tests/basics/gen-yield-from-send.py +++ /dev/null @@ -1,14 +0,0 @@ -def gen(): - print("sent:", (yield 1)) - yield 2 - -def gen2(): - print((yield from gen())) - -g = gen2() -next(g) -print("yielded:", g.send("val")) -try: - next(g) -except StopIteration: - print("StopIteration") diff --git a/tests/basics/gen-yield-from-throw.py b/tests/basics/gen-yield-from-throw.py deleted file mode 100644 index 30960fb9c..000000000 --- a/tests/basics/gen-yield-from-throw.py +++ /dev/null @@ -1,19 +0,0 @@ -def gen(): - try: - yield 1 - except ValueError: - print("got ValueError from upstream!") - yield "str1" - raise TypeError - -def gen2(): - print((yield from gen())) - -g = gen2() -print(next(g)) -print(g.throw(ValueError)) -try: - print(next(g)) -except TypeError: - print("got TypeError from downstream!") - diff --git a/tests/basics/gen-yield-from.py b/tests/basics/gen-yield-from.py deleted file mode 100644 index 5196b48d2..000000000 --- a/tests/basics/gen-yield-from.py +++ /dev/null @@ -1,42 +0,0 @@ -# Case of terminating subgen using return with value -def gen(): - yield 1 - yield 2 - return 3 - -def gen2(): - print("here1") - print((yield from gen())) - print("here2") - -g = gen2() -print(list(g)) - - -# Like above, but terminate subgen using StopIteration -def gen3(): - yield 1 - yield 2 - raise StopIteration - -def gen4(): - print("here1") - print((yield from gen3())) - print("here2") - -g = gen4() -print(list(g)) - -# Like above, but terminate subgen using StopIteration with value -def gen5(): - yield 1 - yield 2 - raise StopIteration(123) - -def gen6(): - print("here1") - print((yield from gen5())) - print("here2") - -g = gen6() -print(list(g)) diff --git a/tests/basics/gen_yield_from.py b/tests/basics/gen_yield_from.py new file mode 100644 index 000000000..5196b48d2 --- /dev/null +++ b/tests/basics/gen_yield_from.py @@ -0,0 +1,42 @@ +# Case of terminating subgen using return with value +def gen(): + yield 1 + yield 2 + return 3 + +def gen2(): + print("here1") + print((yield from gen())) + print("here2") + +g = gen2() +print(list(g)) + + +# Like above, but terminate subgen using StopIteration +def gen3(): + yield 1 + yield 2 + raise StopIteration + +def gen4(): + print("here1") + print((yield from gen3())) + print("here2") + +g = gen4() +print(list(g)) + +# Like above, but terminate subgen using StopIteration with value +def gen5(): + yield 1 + yield 2 + raise StopIteration(123) + +def gen6(): + print("here1") + print((yield from gen5())) + print("here2") + +g = gen6() +print(list(g)) diff --git a/tests/basics/gen_yield_from_close.py b/tests/basics/gen_yield_from_close.py new file mode 100644 index 000000000..7982d5c99 --- /dev/null +++ b/tests/basics/gen_yield_from_close.py @@ -0,0 +1,87 @@ +def gen(): + yield 1 + yield 2 + yield 3 + yield 4 + +def gen2(): + yield -1 + print((yield from gen())) + yield 10 + yield 11 + +g = gen2() +print(next(g)) +print(next(g)) +g.close() +try: + print(next(g)) +except StopIteration: + print("StopIteration") + + +# Now variation of same test, but with leaf generator +# swallowing GeneratorExit exception - its upstream gen +# generator should still receive one. +def gen3(): + yield 1 + try: + yield 2 + except GeneratorExit: + print("leaf caught GeneratorExit and swallowed it") + return + yield 3 + yield 4 + +def gen4(): + yield -1 + try: + print((yield from gen3())) + except GeneratorExit: + print("delegating caught GeneratorExit") + raise + yield 10 + yield 11 + +g = gen4() +print(next(g)) +print(next(g)) +print(next(g)) +g.close() +try: + print(next(g)) +except StopIteration: + print("StopIteration") + + +# Yet another variation - leaf generator gets GeneratorExit, +# but raises StopIteration instead. This still should close chain properly. +def gen5(): + yield 1 + try: + yield 2 + except GeneratorExit: + print("leaf caught GeneratorExit and raised StopIteration instead") + raise StopIteration(123) + yield 3 + yield 4 + +def gen6(): + yield -1 + try: + print((yield from gen5())) + except GeneratorExit: + print("delegating caught GeneratorExit") + raise + yield 10 + yield 11 + +g = gen6() +print(next(g)) +print(next(g)) +print(next(g)) +g.close() +try: + print(next(g)) +except StopIteration: + print("StopIteration") diff --git a/tests/basics/gen_yield_from_ducktype.py b/tests/basics/gen_yield_from_ducktype.py new file mode 100644 index 000000000..aa0109c91 --- /dev/null +++ b/tests/basics/gen_yield_from_ducktype.py @@ -0,0 +1,44 @@ +class MyGen: + + def __init__(self): + self.v = 0 + + def __iter__(self): + return self + + def __next__(self): + self.v += 1 + if self.v > 5: + raise StopIteration + return self.v + +def gen(): + yield from MyGen() + +def gen2(): + yield from gen() + +print(list(gen())) +print(list(gen2())) + + +class Incrementer: + + def __iter__(self): + return self + + def __next__(self): + return self.send(None) + + def send(self, val): + if val is None: + return "Incrementer initialized" + return val + 1 + +def gen3(): + yield from Incrementer() + +g = gen3() +print(next(g)) +print(g.send(5)) +print(g.send(100)) diff --git a/tests/basics/gen_yield_from_exc.py b/tests/basics/gen_yield_from_exc.py new file mode 100644 index 000000000..01c954f5b --- /dev/null +++ b/tests/basics/gen_yield_from_exc.py @@ -0,0 +1,13 @@ +def gen(): + yield 1 + yield 2 + raise ValueError + +def gen2(): + try: + print((yield from gen())) + except ValueError: + print("caught ValueError from downstream") + +g = gen2() +print(list(g)) diff --git a/tests/basics/gen_yield_from_iter.py b/tests/basics/gen_yield_from_iter.py new file mode 100644 index 000000000..2d06328fb --- /dev/null +++ b/tests/basics/gen_yield_from_iter.py @@ -0,0 +1,8 @@ +def gen(): + yield from (1, 2, 3) + +def gen2(): + yield from gen() + +print(list(gen())) +print(list(gen2())) diff --git a/tests/basics/gen_yield_from_send.py b/tests/basics/gen_yield_from_send.py new file mode 100644 index 000000000..c2e94b5ad --- /dev/null +++ b/tests/basics/gen_yield_from_send.py @@ -0,0 +1,14 @@ +def gen(): + print("sent:", (yield 1)) + yield 2 + +def gen2(): + print((yield from gen())) + +g = gen2() +next(g) +print("yielded:", g.send("val")) +try: + next(g) +except StopIteration: + print("StopIteration") diff --git a/tests/basics/gen_yield_from_throw.py b/tests/basics/gen_yield_from_throw.py new file mode 100644 index 000000000..30960fb9c --- /dev/null +++ b/tests/basics/gen_yield_from_throw.py @@ -0,0 +1,19 @@ +def gen(): + try: + yield 1 + except ValueError: + print("got ValueError from upstream!") + yield "str1" + raise TypeError + +def gen2(): + print((yield from gen())) + +g = gen2() +print(next(g)) +print(g.throw(ValueError)) +try: + print(next(g)) +except TypeError: + print("got TypeError from downstream!") + diff --git a/tests/basics/generator-args.py b/tests/basics/generator-args.py deleted file mode 100644 index 608210b4b..000000000 --- a/tests/basics/generator-args.py +++ /dev/null @@ -1,17 +0,0 @@ -# Handling of "complicated" arg forms to generators -# https://github.com/micropython/micropython/issues/397 -def gen(v=5): - for i in range(v): - yield i - -print(list(gen())) -print(list(gen(v=10))) - - -def g(*args, **kwargs): - for i in args: - yield i - for k, v in kwargs.items(): - yield (k, v) - -print(list(g(1, 2, 3, foo="bar"))) diff --git a/tests/basics/generator-closure.py b/tests/basics/generator-closure.py deleted file mode 100644 index d8a517ede..000000000 --- a/tests/basics/generator-closure.py +++ /dev/null @@ -1,26 +0,0 @@ -# a generator that closes over outer variables -def f(): - x = 1 # closed over by g - def g(): - yield x - yield x + 1 - return g() -for i in f(): - print(i) - -# a generator that has its variables closed over -def f(): - x = 1 # closed over by g - def g(): - return x + 1 - yield g() - x = 2 - yield g() -for i in f(): - print(i) - -# using comprehensions, the inner generator closes over y -generator_of_generators = (((x, y) for x in range(2)) for y in range(3)) -for i in generator_of_generators: - for j in i: - print(j) diff --git a/tests/basics/generator-exc.py b/tests/basics/generator-exc.py deleted file mode 100644 index 09aca5d9a..000000000 --- a/tests/basics/generator-exc.py +++ /dev/null @@ -1,53 +0,0 @@ -# Test proper handling of exceptions within generator across yield -def gen(): - try: - yield 1 - raise ValueError - except ValueError: - print("Caught") - yield 2 - -for i in gen(): - print(i) - - -# Test throwing exceptions out of generator -def gen2(): - yield 1 - raise ValueError - yield 2 - yield 3 - -g = gen2() -print(next(g)) -try: - print(next(g)) -except ValueError: - print("ValueError") - -try: - print(next(g)) -except StopIteration: - print("StopIteration") - - -# Test throwing exception into generator -def gen3(): - yield 1 - try: - yield 2 - except ValueError: - print("ValueError received") - yield 3 - yield 4 - yield 5 - -g = gen3() -print(next(g)) -print(next(g)) -print("out of throw:", g.throw(ValueError)) -print(next(g)) -try: - print("out of throw2:", g.throw(ValueError)) -except ValueError: - print("Boomerang ValueError caught") diff --git a/tests/basics/generator-return.py b/tests/basics/generator-return.py deleted file mode 100644 index a3ac88575..000000000 --- a/tests/basics/generator-return.py +++ /dev/null @@ -1,10 +0,0 @@ -def gen(): - yield 1 - return 42 - -g = gen() -print(next(g)) -try: - print(next(g)) -except StopIteration as e: - print(repr(e)) diff --git a/tests/basics/generator_args.py b/tests/basics/generator_args.py new file mode 100644 index 000000000..608210b4b --- /dev/null +++ b/tests/basics/generator_args.py @@ -0,0 +1,17 @@ +# Handling of "complicated" arg forms to generators +# https://github.com/micropython/micropython/issues/397 +def gen(v=5): + for i in range(v): + yield i + +print(list(gen())) +print(list(gen(v=10))) + + +def g(*args, **kwargs): + for i in args: + yield i + for k, v in kwargs.items(): + yield (k, v) + +print(list(g(1, 2, 3, foo="bar"))) diff --git a/tests/basics/generator_closure.py b/tests/basics/generator_closure.py new file mode 100644 index 000000000..d8a517ede --- /dev/null +++ b/tests/basics/generator_closure.py @@ -0,0 +1,26 @@ +# a generator that closes over outer variables +def f(): + x = 1 # closed over by g + def g(): + yield x + yield x + 1 + return g() +for i in f(): + print(i) + +# a generator that has its variables closed over +def f(): + x = 1 # closed over by g + def g(): + return x + 1 + yield g() + x = 2 + yield g() +for i in f(): + print(i) + +# using comprehensions, the inner generator closes over y +generator_of_generators = (((x, y) for x in range(2)) for y in range(3)) +for i in generator_of_generators: + for j in i: + print(j) diff --git a/tests/basics/generator_exc.py b/tests/basics/generator_exc.py new file mode 100644 index 000000000..09aca5d9a --- /dev/null +++ b/tests/basics/generator_exc.py @@ -0,0 +1,53 @@ +# Test proper handling of exceptions within generator across yield +def gen(): + try: + yield 1 + raise ValueError + except ValueError: + print("Caught") + yield 2 + +for i in gen(): + print(i) + + +# Test throwing exceptions out of generator +def gen2(): + yield 1 + raise ValueError + yield 2 + yield 3 + +g = gen2() +print(next(g)) +try: + print(next(g)) +except ValueError: + print("ValueError") + +try: + print(next(g)) +except StopIteration: + print("StopIteration") + + +# Test throwing exception into generator +def gen3(): + yield 1 + try: + yield 2 + except ValueError: + print("ValueError received") + yield 3 + yield 4 + yield 5 + +g = gen3() +print(next(g)) +print(next(g)) +print("out of throw:", g.throw(ValueError)) +print(next(g)) +try: + print("out of throw2:", g.throw(ValueError)) +except ValueError: + print("Boomerang ValueError caught") diff --git a/tests/basics/generator_return.py b/tests/basics/generator_return.py new file mode 100644 index 000000000..a3ac88575 --- /dev/null +++ b/tests/basics/generator_return.py @@ -0,0 +1,10 @@ +def gen(): + yield 1 + return 42 + +g = gen() +print(next(g)) +try: + print(next(g)) +except StopIteration as e: + print(repr(e)) diff --git a/tests/basics/globals-del.py b/tests/basics/globals-del.py deleted file mode 100644 index a1638ac27..000000000 --- a/tests/basics/globals-del.py +++ /dev/null @@ -1,27 +0,0 @@ -""" -1 -""" - -def _f(): pass -FunctionType = type(_f) -LambdaType = type(lambda: None) -CodeType = None -MappingProxyType = None -SimpleNamespace = None - -def _g(): - yield 1 -GeneratorType = type(_g()) - -class _C: - def _m(self): pass -MethodType = type(_C()._m) - -BuiltinFunctionType = type(len) -BuiltinMethodType = type([].append) - -del _f - -# print only the first 8 chars, since we have different str rep to CPython -print(str(FunctionType)[:8]) -print(str(BuiltinFunctionType)[:8]) diff --git a/tests/basics/globals_del.py b/tests/basics/globals_del.py new file mode 100644 index 000000000..a1638ac27 --- /dev/null +++ b/tests/basics/globals_del.py @@ -0,0 +1,27 @@ +""" +1 +""" + +def _f(): pass +FunctionType = type(_f) +LambdaType = type(lambda: None) +CodeType = None +MappingProxyType = None +SimpleNamespace = None + +def _g(): + yield 1 +GeneratorType = type(_g()) + +class _C: + def _m(self): pass +MethodType = type(_C()._m) + +BuiltinFunctionType = type(len) +BuiltinMethodType = type([].append) + +del _f + +# print only the first 8 chars, since we have different str rep to CPython +print(str(FunctionType)[:8]) +print(str(BuiltinFunctionType)[:8]) diff --git a/tests/basics/int-big-and.py b/tests/basics/int-big-and.py deleted file mode 100644 index a48848dbf..000000000 --- a/tests/basics/int-big-and.py +++ /dev/null @@ -1,24 +0,0 @@ -print(0 & (1 << 80)) -print(0 & (1 << 80) == 0) -print(bool(0 & (1 << 80))) - -a = 0xfffffffffffffffffffffffffffff -print(a & (1 << 80)) -print((a & (1 << 80)) >> 80) -print((a & (1 << 80)) >> 80 == 1) - -# test negative on rhs -a = 123456789012345678901234567890 -print(a & -1) -print(a & -2) -print(a & -2345678901234567890123456789) -print(a & (-a)) - -# test negative on lhs -a = 123456789012345678901234567890 -print(-1 & a) -print(-2 & a) -print(-2345678901234567890123456789 & a) -print((-a) & a) -print((-a) & 0xffffffff) -print((-a) & 0xffffffffffffffffffffffffffffffff) diff --git a/tests/basics/int-big-lshift.py b/tests/basics/int-big-lshift.py deleted file mode 100644 index af1d97504..000000000 --- a/tests/basics/int-big-lshift.py +++ /dev/null @@ -1,17 +0,0 @@ -# tests transition from small to large int representation by left-shift operation -for i in range(1, 17): - for shift in range(70): - print(i, '<<', shift, '=', i << shift) - -# test bit-shifting negative integers -for i in range(8): - print(-100000000000000000000000000000 << i) - print(-100000000000000000000000000001 << i) - print(-100000000000000000000000000002 << i) - print(-100000000000000000000000000003 << i) - print(-100000000000000000000000000004 << i) - print(-100000000000000000000000000000 >> i) - print(-100000000000000000000000000001 >> i) - print(-100000000000000000000000000002 >> i) - print(-100000000000000000000000000003 >> i) - print(-100000000000000000000000000004 >> i) diff --git a/tests/basics/int-big-mod.py b/tests/basics/int-big-mod.py deleted file mode 100644 index 77c0ffc46..000000000 --- a/tests/basics/int-big-mod.py +++ /dev/null @@ -1,10 +0,0 @@ -# test % operation on big integers - -delta = 100000000000000000000000000000012345 - -for i in range(11): - for j in range(11): - x = delta * (i)# - 5) # TODO reinstate negative number test when % is working with sign correctly - y = delta * (j)# - 5) # TODO reinstate negative number test when % is working with sign correctly - if y != 0: - print(x % y) diff --git a/tests/basics/int-big-mul.py b/tests/basics/int-big-mul.py deleted file mode 100644 index f8d3dcd80..000000000 --- a/tests/basics/int-big-mul.py +++ /dev/null @@ -1,8 +0,0 @@ -# tests transition from small to large int representation by multiplication -for rhs in range(2, 11): - lhs = 1 - for k in range(100): - res = lhs * rhs - print(lhs, '*', rhs, '=', res) - lhs = res - diff --git a/tests/basics/int-bytes.py b/tests/basics/int-bytes.py deleted file mode 100644 index 45965ed46..000000000 --- a/tests/basics/int-bytes.py +++ /dev/null @@ -1,6 +0,0 @@ -print((10).to_bytes(1, "little")) -print((111111).to_bytes(4, "little")) -print((100).to_bytes(10, "little")) -print(int.from_bytes(b"\x00\x01\0\0\0\0\0\0", "little")) -print(int.from_bytes(b"\x01\0\0\0\0\0\0\0", "little")) -print(int.from_bytes(b"\x00\x01\0\0\0\0\0\0", "little")) diff --git a/tests/basics/int-divzero.py b/tests/basics/int-divzero.py deleted file mode 100644 index 28ec2a699..000000000 --- a/tests/basics/int-divzero.py +++ /dev/null @@ -1,4 +0,0 @@ -try: - 1 // 0 -except ZeroDivisionError: - print("ZeroDivisionError") diff --git a/tests/basics/int-long.py b/tests/basics/int-long.py deleted file mode 100644 index a22075d1f..000000000 --- a/tests/basics/int-long.py +++ /dev/null @@ -1,54 +0,0 @@ -# This tests long ints for 32-bit machine - -a = 0x1ffffffff -b = 0x100000000 -print(a) -print(b) -print(a + b) -print(a - b) -print(b - a) -# overflows long long implementation -#print(a * b) -print(a // b) -print(a % b) -print("&", a & b) -print(a | b) -print(a ^ b) -print(a << 3) -print(a >> 1) - -a += b -print(a) -a -= 123456 -print(a) -a *= 257 -print(a) -a //= 257 -print(a) -a %= b -print(a) -a ^= b -print(a) -a |= b -print(a) -a &= b -print("&=", a) -a <<= 5 -print(a) -a >>= 1 -print(a) - -# Test referential integrity of long ints -a = 0x1ffffffff -b = a -a += 1 -print(a) -print(b) - -# Bitwise ops on 64-bit - -a = 0x1ffffffffffffffff -b = 0x10000000000000000 -print("&", a & b) -print(a | b) -print(a ^ b) diff --git a/tests/basics/int-mpz.py b/tests/basics/int-mpz.py deleted file mode 100644 index 0500d794c..000000000 --- a/tests/basics/int-mpz.py +++ /dev/null @@ -1,57 +0,0 @@ -# to test arbitrariy precision integers - -x = 1000000000000000000000000000000 -y = 2000000000000000000000000000000 - -# printing -print(x) -print(y) - -# addition -print(x + 1) -print(x + y) - -# subtraction -print(x - 1) -print(x - y) -print(y - x) - -# multiplication -print(x * 2) -print(x * y) - -# integer division -print(x // 2) -print(y // x) - -# bit inversion -print(~x) -print(~(-x)) - -# left shift -x = 0x10000000000000000000000 -for i in range(32): - x = x << 1 - print(x) - -# right shift -x = 0x10000000000000000000000 -for i in range(32): - x = x >> 1 - print(x) - -# left shift of a negative number -for i in range(8): - print(-10000000000000000000000000 << i) - print(-10000000000000000000000001 << i) - print(-10000000000000000000000002 << i) - print(-10000000000000000000000003 << i) - print(-10000000000000000000000004 << i) - -# right shift of a negative number -for i in range(8): - print(-10000000000000000000000000 >> i) - print(-10000000000000000000000001 >> i) - print(-10000000000000000000000002 >> i) - print(-10000000000000000000000003 >> i) - print(-10000000000000000000000004 >> i) diff --git a/tests/basics/int-small.py b/tests/basics/int-small.py deleted file mode 100644 index 102dac8ae..000000000 --- a/tests/basics/int-small.py +++ /dev/null @@ -1,50 +0,0 @@ -# This tests small int range for 32-bit machine - -# Small ints are variable-length encoded in MicroPython, so first -# test that encoding works as expected. - -print(0) -print(1) -print(-1) -# Value is split in 7-bit "subwords", and taking into account that all -# ints in Python are signed, there're 6 bits of magnitude. So, around 2^6 -# there's "turning point" -print(63) -print(64) -print(65) -print(-63) -print(-64) -print(-65) -# Maximum values of small ints on 32-bit platform -print(1073741823) -# Per python semantics, lexical integer is without a sign (i.e. positive) -# and '-' is unary minus operation applied to it. That's why -1073741824 -# (min two-complement's negative value) is not allowed. -print(-1073741823) - -# Operations tests - -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/int_big_and.py b/tests/basics/int_big_and.py new file mode 100644 index 000000000..a48848dbf --- /dev/null +++ b/tests/basics/int_big_and.py @@ -0,0 +1,24 @@ +print(0 & (1 << 80)) +print(0 & (1 << 80) == 0) +print(bool(0 & (1 << 80))) + +a = 0xfffffffffffffffffffffffffffff +print(a & (1 << 80)) +print((a & (1 << 80)) >> 80) +print((a & (1 << 80)) >> 80 == 1) + +# test negative on rhs +a = 123456789012345678901234567890 +print(a & -1) +print(a & -2) +print(a & -2345678901234567890123456789) +print(a & (-a)) + +# test negative on lhs +a = 123456789012345678901234567890 +print(-1 & a) +print(-2 & a) +print(-2345678901234567890123456789 & a) +print((-a) & a) +print((-a) & 0xffffffff) +print((-a) & 0xffffffffffffffffffffffffffffffff) diff --git a/tests/basics/int_big_lshift.py b/tests/basics/int_big_lshift.py new file mode 100644 index 000000000..af1d97504 --- /dev/null +++ b/tests/basics/int_big_lshift.py @@ -0,0 +1,17 @@ +# tests transition from small to large int representation by left-shift operation +for i in range(1, 17): + for shift in range(70): + print(i, '<<', shift, '=', i << shift) + +# test bit-shifting negative integers +for i in range(8): + print(-100000000000000000000000000000 << i) + print(-100000000000000000000000000001 << i) + print(-100000000000000000000000000002 << i) + print(-100000000000000000000000000003 << i) + print(-100000000000000000000000000004 << i) + print(-100000000000000000000000000000 >> i) + print(-100000000000000000000000000001 >> i) + print(-100000000000000000000000000002 >> i) + print(-100000000000000000000000000003 >> i) + print(-100000000000000000000000000004 >> i) diff --git a/tests/basics/int_big_mod.py b/tests/basics/int_big_mod.py new file mode 100644 index 000000000..77c0ffc46 --- /dev/null +++ b/tests/basics/int_big_mod.py @@ -0,0 +1,10 @@ +# test % operation on big integers + +delta = 100000000000000000000000000000012345 + +for i in range(11): + for j in range(11): + x = delta * (i)# - 5) # TODO reinstate negative number test when % is working with sign correctly + y = delta * (j)# - 5) # TODO reinstate negative number test when % is working with sign correctly + if y != 0: + print(x % y) diff --git a/tests/basics/int_big_mul.py b/tests/basics/int_big_mul.py new file mode 100644 index 000000000..f8d3dcd80 --- /dev/null +++ b/tests/basics/int_big_mul.py @@ -0,0 +1,8 @@ +# tests transition from small to large int representation by multiplication +for rhs in range(2, 11): + lhs = 1 + for k in range(100): + res = lhs * rhs + print(lhs, '*', rhs, '=', res) + lhs = res + diff --git a/tests/basics/int_bytes.py b/tests/basics/int_bytes.py new file mode 100644 index 000000000..45965ed46 --- /dev/null +++ b/tests/basics/int_bytes.py @@ -0,0 +1,6 @@ +print((10).to_bytes(1, "little")) +print((111111).to_bytes(4, "little")) +print((100).to_bytes(10, "little")) +print(int.from_bytes(b"\x00\x01\0\0\0\0\0\0", "little")) +print(int.from_bytes(b"\x01\0\0\0\0\0\0\0", "little")) +print(int.from_bytes(b"\x00\x01\0\0\0\0\0\0", "little")) diff --git a/tests/basics/int_divzero.py b/tests/basics/int_divzero.py new file mode 100644 index 000000000..28ec2a699 --- /dev/null +++ b/tests/basics/int_divzero.py @@ -0,0 +1,4 @@ +try: + 1 // 0 +except ZeroDivisionError: + print("ZeroDivisionError") diff --git a/tests/basics/int_long.py b/tests/basics/int_long.py new file mode 100644 index 000000000..a22075d1f --- /dev/null +++ b/tests/basics/int_long.py @@ -0,0 +1,54 @@ +# This tests long ints for 32-bit machine + +a = 0x1ffffffff +b = 0x100000000 +print(a) +print(b) +print(a + b) +print(a - b) +print(b - a) +# overflows long long implementation +#print(a * b) +print(a // b) +print(a % b) +print("&", a & b) +print(a | b) +print(a ^ b) +print(a << 3) +print(a >> 1) + +a += b +print(a) +a -= 123456 +print(a) +a *= 257 +print(a) +a //= 257 +print(a) +a %= b +print(a) +a ^= b +print(a) +a |= b +print(a) +a &= b +print("&=", a) +a <<= 5 +print(a) +a >>= 1 +print(a) + +# Test referential integrity of long ints +a = 0x1ffffffff +b = a +a += 1 +print(a) +print(b) + +# Bitwise ops on 64-bit + +a = 0x1ffffffffffffffff +b = 0x10000000000000000 +print("&", a & b) +print(a | b) +print(a ^ b) diff --git a/tests/basics/int_mpz.py b/tests/basics/int_mpz.py new file mode 100644 index 000000000..0500d794c --- /dev/null +++ b/tests/basics/int_mpz.py @@ -0,0 +1,57 @@ +# to test arbitrariy precision integers + +x = 1000000000000000000000000000000 +y = 2000000000000000000000000000000 + +# printing +print(x) +print(y) + +# addition +print(x + 1) +print(x + y) + +# subtraction +print(x - 1) +print(x - y) +print(y - x) + +# multiplication +print(x * 2) +print(x * y) + +# integer division +print(x // 2) +print(y // x) + +# bit inversion +print(~x) +print(~(-x)) + +# left shift +x = 0x10000000000000000000000 +for i in range(32): + x = x << 1 + print(x) + +# right shift +x = 0x10000000000000000000000 +for i in range(32): + x = x >> 1 + print(x) + +# left shift of a negative number +for i in range(8): + print(-10000000000000000000000000 << i) + print(-10000000000000000000000001 << i) + print(-10000000000000000000000002 << i) + print(-10000000000000000000000003 << i) + print(-10000000000000000000000004 << i) + +# right shift of a negative number +for i in range(8): + print(-10000000000000000000000000 >> i) + print(-10000000000000000000000001 >> i) + print(-10000000000000000000000002 >> i) + print(-10000000000000000000000003 >> i) + print(-10000000000000000000000004 >> i) diff --git a/tests/basics/int_small.py b/tests/basics/int_small.py new file mode 100644 index 000000000..102dac8ae --- /dev/null +++ b/tests/basics/int_small.py @@ -0,0 +1,50 @@ +# This tests small int range for 32-bit machine + +# Small ints are variable-length encoded in MicroPython, so first +# test that encoding works as expected. + +print(0) +print(1) +print(-1) +# Value is split in 7-bit "subwords", and taking into account that all +# ints in Python are signed, there're 6 bits of magnitude. So, around 2^6 +# there's "turning point" +print(63) +print(64) +print(65) +print(-63) +print(-64) +print(-65) +# Maximum values of small ints on 32-bit platform +print(1073741823) +# Per python semantics, lexical integer is without a sign (i.e. positive) +# and '-' is unary minus operation applied to it. That's why -1073741824 +# (min two-complement's negative value) is not allowed. +print(-1073741823) + +# Operations tests + +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/is-isnot.py b/tests/basics/is-isnot.py deleted file mode 100644 index 990190aa4..000000000 --- a/tests/basics/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/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/iter-of-iter.py b/tests/basics/iter-of-iter.py deleted file mode 100644 index 70282aa97..000000000 --- a/tests/basics/iter-of-iter.py +++ /dev/null @@ -1,8 +0,0 @@ -i = iter(iter((1, 2, 3))) -print(list(i)) -i = iter(iter([1, 2, 3])) -print(list(i)) -i = iter(iter({1:2, 3:4, 5:6})) -print(sorted(i)) -i = iter(iter({1, 2, 3})) -print(sorted(i)) diff --git a/tests/basics/iter_of_iter.py b/tests/basics/iter_of_iter.py new file mode 100644 index 000000000..70282aa97 --- /dev/null +++ b/tests/basics/iter_of_iter.py @@ -0,0 +1,8 @@ +i = iter(iter((1, 2, 3))) +print(list(i)) +i = iter(iter([1, 2, 3])) +print(list(i)) +i = iter(iter({1:2, 3:4, 5:6})) +print(sorted(i)) +i = iter(iter({1, 2, 3})) +print(sorted(i)) diff --git a/tests/basics/seq-unpack.py b/tests/basics/seq-unpack.py deleted file mode 100644 index af8b998d0..000000000 --- a/tests/basics/seq-unpack.py +++ /dev/null @@ -1,36 +0,0 @@ -# Basics -a, b = 1, 2 -print(a, b) -a, b = (1, 2) -print(a, b) -(a, b) = 1, 2 -print(a, b) -(a, b) = (1, 2) -print(a, b) - -# Tuples/lists are optimized -a, b = [1, 2] -print(a, b) -[a, b] = 100, 200 -print(a, b) - -try: - a, b, c = (1, 2) -except ValueError: - print("ValueError") -try: - a, b, c = [1, 2, 3, 4] -except ValueError: - print("ValueError") - -# Generic iterable object -a, b, c = range(3) -print(a, b, c) -try: - a, b, c = range(2) -except ValueError: - print("ValueError") -try: - a, b, c = range(4) -except ValueError: - print("ValueError") diff --git a/tests/basics/seq_unpack.py b/tests/basics/seq_unpack.py new file mode 100644 index 000000000..af8b998d0 --- /dev/null +++ b/tests/basics/seq_unpack.py @@ -0,0 +1,36 @@ +# Basics +a, b = 1, 2 +print(a, b) +a, b = (1, 2) +print(a, b) +(a, b) = 1, 2 +print(a, b) +(a, b) = (1, 2) +print(a, b) + +# Tuples/lists are optimized +a, b = [1, 2] +print(a, b) +[a, b] = 100, 200 +print(a, b) + +try: + a, b, c = (1, 2) +except ValueError: + print("ValueError") +try: + a, b, c = [1, 2, 3, 4] +except ValueError: + print("ValueError") + +# Generic iterable object +a, b, c = range(3) +print(a, b, c) +try: + a, b, c = range(2) +except ValueError: + print("ValueError") +try: + a, b, c = range(4) +except ValueError: + print("ValueError") diff --git a/tests/basics/string-compare.py b/tests/basics/string-compare.py deleted file mode 100644 index 740e1959c..000000000 --- a/tests/basics/string-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" == "10") - -print("1" > "1") -print("1" > "2") -print("2" > "1") -print("10" > "1") -print("1/" > "1") -print("1" > "10") -print("1" > "1/") - -print("1" < "1") -print("2" < "1") -print("1" < "2") -print("1" < "10") -print("1" < "1/") -print("10" < "1") -print("1/" < "1") - -print("1" >= "1") -print("1" >= "2") -print("2" >= "1") -print("10" >= "1") -print("1/" >= "1") -print("1" >= "10") -print("1" >= "1/") - -print("1" <= "1") -print("2" <= "1") -print("1" <= "2") -print("1" <= "10") -print("1" <= "1/") -print("10" <= "1") -print("1/" <= "1") diff --git a/tests/basics/string-escape.py b/tests/basics/string-escape.py deleted file mode 100644 index 000a8713e..000000000 --- a/tests/basics/string-escape.py +++ /dev/null @@ -1,11 +0,0 @@ -a = "a\1b" -print(len(a)) -print(ord(a[1])) -print(len("a\123b")) -a = "a\12345b" -print(len(a)) -print(ord(a[1])) - -a = "a\xffb" -print(len(a)) -print(ord(a[1])) diff --git a/tests/basics/string-format-modulo.py b/tests/basics/string-format-modulo.py deleted file mode 100644 index f3f57b45a..000000000 --- a/tests/basics/string-format-modulo.py +++ /dev/null @@ -1,86 +0,0 @@ -print("=%s=" % 1) -print("=%s=%s=" % (1, 2)) -print("=%s=" % (1,)) -print("=%s=" % [1, 2]) - -print("=%s=" % "str") -print("=%r=" % "str") - -try: - print("=%s=%s=" % 1) -except TypeError: - print("TypeError") - -try: - print("=%s=%s=%s=" % (1, 2)) -except TypeError: - print("TypeError") - -try: - print("=%s=" % (1, 2)) -except TypeError: - print("TypeError") - -print("%s" % True) -print("%s" % 1) - -print("%r" % True) -print("%r" % 1) - -print("%c" % 48) -print("%c" % 'a') -print("%10s" % 'abc') -print("%-10s" % 'abc') -print("%d" % 10) -print("%+d" % 10) -print("% d" % 10) -print("%d" % -10) -print("%d" % True) -print("%i" % -10) -print("%i" % True) -print("%u" % -10) -print("%u" % True) -print("%x" % 18) -print("%o" % 18) -print("%X" % 18) -print("%#x" % 18) -print("%#X" % 18) -print("%#6o" % 18) -print("%#6x" % 18) -print("%#06x" % 18) - -print("%*d" % (5, 10)) -print("%*.*d" % (2, 2, 20)) -print("%*.*d" % (5, 8, 20)) - -print(">%8.4d<" % -12) -print(">% 8.4d<" % -12) -print(">%+8.4d<" % 12) -print(">%+8.4d<" % -12) -print(">%08.4d<" % -12) -print(">%08.4d<" % 12) -print(">%-8.4d<" % -12) -print(">%-08.4d<" % -12) -print(">%-+08.4d<" % -12) -print(">%-+08.4d<" % 12) - -# Cases when "*" used and there's not enough values total -try: - print("%*s" % 5) -except TypeError: - print("TypeError") -try: - print("%*.*s" % (1, 15)) -except TypeError: - print("TypeError") - -print("%(foo)s" % {"foo": "bar", "baz": False}) -try: - print("%(foo)s" % {}) -except KeyError: - print("KeyError") -# Using in "*" with dict got to fail -try: - print("%(foo)*s" % {"foo": "bar"}) -except TypeError: - print("TypeError") diff --git a/tests/basics/string-format.py b/tests/basics/string-format.py deleted file mode 100644 index 84ea05475..000000000 --- a/tests/basics/string-format.py +++ /dev/null @@ -1,120 +0,0 @@ -# Change the following to True to get a much more comprehensive set of tests -# to run, albeit, which take considerably longer. - -full_tests = False - -def test(fmt, *args): - print('{:8s}'.format(fmt) + '>' + fmt.format(*args) + '<') - -test("{}-{}", 1, [4, 5]) -test("{0}-{1}", 1, [4, 5]) -test("{1}-{0}", 1, [4, 5]) -test("{:x}", 1) -test("{!r}", 2) -test("{:x}", 0x10) -test("{!r}", "foo") -test("{!s}", "foo") -test("{0!r:>10s} {0!s:>10s}", "foo") - -test("{:4b}", 10) -test("{:4c}", 48) -test("{:4d}", 123) -test("{:4n}", 123) -test("{:4o}", 123) -test("{:4x}", 123) -test("{:4X}", 123) - -test("{:4,d}", 12345678) - -test("{:#4b}", 10) -test("{:#4o}", 123) -test("{:#4x}", 123) -test("{:#4X}", 123) - -test("{:#4d}", 0) -test("{:#4b}", 0) -test("{:#4o}", 0) -test("{:#4x}", 0) -test("{:#4X}", 0) - -test("{:<6s}", "ab") -test("{:>6s}", "ab") -test("{:^6s}", "ab") - -test("{: <6d}", 123) -test("{: <6d}", -123) -test("{:0<6d}", 123) -test("{:0<6d}", -123) -test("{:@<6d}", 123) -test("{:@<6d}", -123) - -test("{:@< 6d}", 123) -test("{:@< 6d}", -123) -test("{:@<+6d}", 123) -test("{:@<+6d}", -123) -test("{:@<-6d}", 123) -test("{:@<-6d}", -123) - -test("{:@>6d}", -123) -test("{:@<6d}", -123) -test("{:@=6d}", -123) -test("{:06d}", -123) - -def test_fmt(conv, fill, alignment, sign, prefix, width, precision, type, arg): - fmt = '{' - if conv: - fmt += '!' - fmt += conv - fmt += ':' - if alignment: - fmt += fill - fmt += alignment - fmt += sign - fmt += prefix - fmt += width - if precision: - fmt += '.' - fmt += precision - fmt += type - fmt += '}' - test(fmt, arg) - if fill == '0' and alignment == '=': - fmt = '{:' - fmt += sign - fmt += prefix - fmt += width - if precision: - fmt += '.' - fmt += precision - fmt += type - fmt += '}' - test(fmt, arg) - -int_nums = (-1234, -123, -12, -1, 0, 1, 12, 123, 1234, True, False) -int_nums2 = (-12, -1, 0, 1, 12, True, False) - -if full_tests: - for type in ('', 'b', 'd', 'o', 'x', 'X'): - for width in ('', '1', '3', '5', '7'): - for alignment in ('', '<', '>', '=', '^'): - for fill in ('', ' ', '0', '@'): - for sign in ('', '+', '-', ' '): - for prefix in ('', '#'): - for num in int_nums: - test_fmt('', fill, alignment, sign, prefix, width, '', type, num) - -if full_tests: - for width in ('', '1', '2'): - for alignment in ('', '<', '>', '^'): - for fill in ('', ' ', '0', '@'): - test_fmt('', fill, alignment, '', '', width, '', 'c', 48) - -if full_tests: - for conv in ('', 'r', 's'): - for width in ('', '1', '4', '10'): - for alignment in ('', '<', '>', '^'): - for fill in ('', ' ', '0', '@'): - for str in ('', 'a', 'bcd', 'This is a test with a longer string'): - test_fmt(conv, fill, alignment, '', '', width, '', 's', str) - -# TODO Add tests for erroneous format strings. diff --git a/tests/basics/string-join.py b/tests/basics/string-join.py deleted file mode 100644 index 49bbfc5ca..000000000 --- a/tests/basics/string-join.py +++ /dev/null @@ -1,24 +0,0 @@ -print(','.join(())) -print(','.join(('a',))) -print(','.join(('a', 'b'))) - -print(','.join([])) -print(','.join(['a'])) -print(','.join(['a', 'b'])) - -print(''.join('')) -print(''.join('abc')) -print(','.join('abc')) -print(','.join('abc' for i in range(5))) - -print(b','.join([b'abc', b'123'])) - -try: - print(b','.join(['abc', b'123'])) -except TypeError: - print("TypeError") - -try: - print(','.join([b'abc', b'123'])) -except TypeError: - print("TypeError") diff --git a/tests/basics/string-repr.py b/tests/basics/string-repr.py deleted file mode 100644 index 2a3ef2527..000000000 --- a/tests/basics/string-repr.py +++ /dev/null @@ -1,4 +0,0 @@ -# anything above 0xa0 is printed as Unicode by CPython -# the abobe is CPython implementation detail, stick to ASCII -for c in range(0x80): - print("0x%02x: %s" % (c, repr(chr(c)))) diff --git a/tests/basics/string-slice.py b/tests/basics/string-slice.py deleted file mode 100644 index 89853d343..000000000 --- a/tests/basics/string-slice.py +++ /dev/null @@ -1,35 +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]) - -# bytes -print(b"123"[0:2]) diff --git a/tests/basics/string_compare.py b/tests/basics/string_compare.py new file mode 100644 index 000000000..740e1959c --- /dev/null +++ b/tests/basics/string_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" == "10") + +print("1" > "1") +print("1" > "2") +print("2" > "1") +print("10" > "1") +print("1/" > "1") +print("1" > "10") +print("1" > "1/") + +print("1" < "1") +print("2" < "1") +print("1" < "2") +print("1" < "10") +print("1" < "1/") +print("10" < "1") +print("1/" < "1") + +print("1" >= "1") +print("1" >= "2") +print("2" >= "1") +print("10" >= "1") +print("1/" >= "1") +print("1" >= "10") +print("1" >= "1/") + +print("1" <= "1") +print("2" <= "1") +print("1" <= "2") +print("1" <= "10") +print("1" <= "1/") +print("10" <= "1") +print("1/" <= "1") diff --git a/tests/basics/string_escape.py b/tests/basics/string_escape.py new file mode 100644 index 000000000..000a8713e --- /dev/null +++ b/tests/basics/string_escape.py @@ -0,0 +1,11 @@ +a = "a\1b" +print(len(a)) +print(ord(a[1])) +print(len("a\123b")) +a = "a\12345b" +print(len(a)) +print(ord(a[1])) + +a = "a\xffb" +print(len(a)) +print(ord(a[1])) diff --git a/tests/basics/string_format.py b/tests/basics/string_format.py new file mode 100644 index 000000000..84ea05475 --- /dev/null +++ b/tests/basics/string_format.py @@ -0,0 +1,120 @@ +# Change the following to True to get a much more comprehensive set of tests +# to run, albeit, which take considerably longer. + +full_tests = False + +def test(fmt, *args): + print('{:8s}'.format(fmt) + '>' + fmt.format(*args) + '<') + +test("{}-{}", 1, [4, 5]) +test("{0}-{1}", 1, [4, 5]) +test("{1}-{0}", 1, [4, 5]) +test("{:x}", 1) +test("{!r}", 2) +test("{:x}", 0x10) +test("{!r}", "foo") +test("{!s}", "foo") +test("{0!r:>10s} {0!s:>10s}", "foo") + +test("{:4b}", 10) +test("{:4c}", 48) +test("{:4d}", 123) +test("{:4n}", 123) +test("{:4o}", 123) +test("{:4x}", 123) +test("{:4X}", 123) + +test("{:4,d}", 12345678) + +test("{:#4b}", 10) +test("{:#4o}", 123) +test("{:#4x}", 123) +test("{:#4X}", 123) + +test("{:#4d}", 0) +test("{:#4b}", 0) +test("{:#4o}", 0) +test("{:#4x}", 0) +test("{:#4X}", 0) + +test("{:<6s}", "ab") +test("{:>6s}", "ab") +test("{:^6s}", "ab") + +test("{: <6d}", 123) +test("{: <6d}", -123) +test("{:0<6d}", 123) +test("{:0<6d}", -123) +test("{:@<6d}", 123) +test("{:@<6d}", -123) + +test("{:@< 6d}", 123) +test("{:@< 6d}", -123) +test("{:@<+6d}", 123) +test("{:@<+6d}", -123) +test("{:@<-6d}", 123) +test("{:@<-6d}", -123) + +test("{:@>6d}", -123) +test("{:@<6d}", -123) +test("{:@=6d}", -123) +test("{:06d}", -123) + +def test_fmt(conv, fill, alignment, sign, prefix, width, precision, type, arg): + fmt = '{' + if conv: + fmt += '!' + fmt += conv + fmt += ':' + if alignment: + fmt += fill + fmt += alignment + fmt += sign + fmt += prefix + fmt += width + if precision: + fmt += '.' + fmt += precision + fmt += type + fmt += '}' + test(fmt, arg) + if fill == '0' and alignment == '=': + fmt = '{:' + fmt += sign + fmt += prefix + fmt += width + if precision: + fmt += '.' + fmt += precision + fmt += type + fmt += '}' + test(fmt, arg) + +int_nums = (-1234, -123, -12, -1, 0, 1, 12, 123, 1234, True, False) +int_nums2 = (-12, -1, 0, 1, 12, True, False) + +if full_tests: + for type in ('', 'b', 'd', 'o', 'x', 'X'): + for width in ('', '1', '3', '5', '7'): + for alignment in ('', '<', '>', '=', '^'): + for fill in ('', ' ', '0', '@'): + for sign in ('', '+', '-', ' '): + for prefix in ('', '#'): + for num in int_nums: + test_fmt('', fill, alignment, sign, prefix, width, '', type, num) + +if full_tests: + for width in ('', '1', '2'): + for alignment in ('', '<', '>', '^'): + for fill in ('', ' ', '0', '@'): + test_fmt('', fill, alignment, '', '', width, '', 'c', 48) + +if full_tests: + for conv in ('', 'r', 's'): + for width in ('', '1', '4', '10'): + for alignment in ('', '<', '>', '^'): + for fill in ('', ' ', '0', '@'): + for str in ('', 'a', 'bcd', 'This is a test with a longer string'): + test_fmt(conv, fill, alignment, '', '', width, '', 's', str) + +# TODO Add tests for erroneous format strings. diff --git a/tests/basics/string_format_modulo.py b/tests/basics/string_format_modulo.py new file mode 100644 index 000000000..f3f57b45a --- /dev/null +++ b/tests/basics/string_format_modulo.py @@ -0,0 +1,86 @@ +print("=%s=" % 1) +print("=%s=%s=" % (1, 2)) +print("=%s=" % (1,)) +print("=%s=" % [1, 2]) + +print("=%s=" % "str") +print("=%r=" % "str") + +try: + print("=%s=%s=" % 1) +except TypeError: + print("TypeError") + +try: + print("=%s=%s=%s=" % (1, 2)) +except TypeError: + print("TypeError") + +try: + print("=%s=" % (1, 2)) +except TypeError: + print("TypeError") + +print("%s" % True) +print("%s" % 1) + +print("%r" % True) +print("%r" % 1) + +print("%c" % 48) +print("%c" % 'a') +print("%10s" % 'abc') +print("%-10s" % 'abc') +print("%d" % 10) +print("%+d" % 10) +print("% d" % 10) +print("%d" % -10) +print("%d" % True) +print("%i" % -10) +print("%i" % True) +print("%u" % -10) +print("%u" % True) +print("%x" % 18) +print("%o" % 18) +print("%X" % 18) +print("%#x" % 18) +print("%#X" % 18) +print("%#6o" % 18) +print("%#6x" % 18) +print("%#06x" % 18) + +print("%*d" % (5, 10)) +print("%*.*d" % (2, 2, 20)) +print("%*.*d" % (5, 8, 20)) + +print(">%8.4d<" % -12) +print(">% 8.4d<" % -12) +print(">%+8.4d<" % 12) +print(">%+8.4d<" % -12) +print(">%08.4d<" % -12) +print(">%08.4d<" % 12) +print(">%-8.4d<" % -12) +print(">%-08.4d<" % -12) +print(">%-+08.4d<" % -12) +print(">%-+08.4d<" % 12) + +# Cases when "*" used and there's not enough values total +try: + print("%*s" % 5) +except TypeError: + print("TypeError") +try: + print("%*.*s" % (1, 15)) +except TypeError: + print("TypeError") + +print("%(foo)s" % {"foo": "bar", "baz": False}) +try: + print("%(foo)s" % {}) +except KeyError: + print("KeyError") +# Using in "*" with dict got to fail +try: + print("%(foo)*s" % {"foo": "bar"}) +except TypeError: + print("TypeError") diff --git a/tests/basics/string_join.py b/tests/basics/string_join.py new file mode 100644 index 000000000..49bbfc5ca --- /dev/null +++ b/tests/basics/string_join.py @@ -0,0 +1,24 @@ +print(','.join(())) +print(','.join(('a',))) +print(','.join(('a', 'b'))) + +print(','.join([])) +print(','.join(['a'])) +print(','.join(['a', 'b'])) + +print(''.join('')) +print(''.join('abc')) +print(','.join('abc')) +print(','.join('abc' for i in range(5))) + +print(b','.join([b'abc', b'123'])) + +try: + print(b','.join(['abc', b'123'])) +except TypeError: + print("TypeError") + +try: + print(','.join([b'abc', b'123'])) +except TypeError: + print("TypeError") diff --git a/tests/basics/string_repr.py b/tests/basics/string_repr.py new file mode 100644 index 000000000..2a3ef2527 --- /dev/null +++ b/tests/basics/string_repr.py @@ -0,0 +1,4 @@ +# anything above 0xa0 is printed as Unicode by CPython +# the abobe is CPython implementation detail, stick to ASCII +for c in range(0x80): + print("0x%02x: %s" % (c, repr(chr(c)))) diff --git a/tests/basics/string_slice.py b/tests/basics/string_slice.py new file mode 100644 index 000000000..89853d343 --- /dev/null +++ b/tests/basics/string_slice.py @@ -0,0 +1,35 @@ +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]) + +# bytes +print(b"123"[0:2]) diff --git a/tests/basics/subclass-native1.py b/tests/basics/subclass-native1.py deleted file mode 100644 index a17689342..000000000 --- a/tests/basics/subclass-native1.py +++ /dev/null @@ -1,31 +0,0 @@ -class mylist(list): - pass - -a = mylist([1, 2, 5]) -# Test setting instance attr -a.attr = "something" -# Test base type __str__ -print(a) -# Test getting instance attr -print(a.attr) -# Test base type ->subscr -print(a[-1]) -a[0] = -1 -print(a) -# Test another base type unary op -print(len(a)) - -# Test binary op of base type, with 2nd arg being raw base type -print(a + [20, 30, 40]) -# Test binary op of base type, with 2nd arg being same class as 1st arg -# TODO: Faults -#print(a + a) - -def foo(): - print("hello from foo") - -try: - class myfunc(type(foo)): - pass -except TypeError: - print("TypeError") diff --git a/tests/basics/subclass-native2-list.py b/tests/basics/subclass-native2-list.py deleted file mode 100644 index 9ad0b77ef..000000000 --- a/tests/basics/subclass-native2-list.py +++ /dev/null @@ -1,26 +0,0 @@ -class Base1: - def __init__(self, *args): - print("Base1.__init__", args) - -class Clist1(Base1, list): - pass - -a = Clist1() -print(len(a)) -# Not compliant - list assignment should happen in list.__init__, which is not called -# because there's Base1.__init__, but we assign in list.__new__ -#a = Clist1([1, 2, 3]) -#print(len(a)) - -print("---") - -class Clist2(list, Base1): - pass - -# Not compliant - should call list.__init__, but we don't have it -#a = Clist2() -#print(len(a)) - -# Not compliant - should call list.__init__, but we don't have it -#a = Clist2([1, 2, 3]) -#print(len(a)) diff --git a/tests/basics/subclass-native2-tuple.py b/tests/basics/subclass-native2-tuple.py deleted file mode 100644 index 9eb69e157..000000000 --- a/tests/basics/subclass-native2-tuple.py +++ /dev/null @@ -1,21 +0,0 @@ -class Base1: - def __init__(self, *args): - print("Base1.__init__", args) - -class Ctuple1(Base1, tuple): - pass - -a = Ctuple1() -print(len(a)) -a = Ctuple1([1, 2, 3]) -print(len(a)) - -print("---") - -class Ctuple2(tuple, Base1): - pass - -a = Ctuple2() -print(len(a)) -a = Ctuple2([1, 2, 3]) -print(len(a)) diff --git a/tests/basics/subclass-native3.py b/tests/basics/subclass-native3.py deleted file mode 100644 index bd99ab0d6..000000000 --- a/tests/basics/subclass-native3.py +++ /dev/null @@ -1,22 +0,0 @@ -class MyExc(Exception): - pass - -e = MyExc(100, "Some error") -print(e) -print(repr(e)) -print(e.args) - -try: - raise MyExc("Some error") -except MyExc as e: - print("Caught exception:", repr(e)) - -try: - raise MyExc("Some error2") -except Exception as e: - print("Caught exception:", repr(e)) - -try: - raise MyExc("Some error2") -except: - print("Caught user exception") diff --git a/tests/basics/subclass-native4.py b/tests/basics/subclass-native4.py deleted file mode 100644 index b426793f5..000000000 --- a/tests/basics/subclass-native4.py +++ /dev/null @@ -1,9 +0,0 @@ -# Test calling non-special method inherited from native type - -class mylist(list): - pass - -l = mylist([1, 2, 3]) -print(l) -l.append(10) -print(l) diff --git a/tests/basics/subclass-native5.py b/tests/basics/subclass-native5.py deleted file mode 100644 index 6127dae33..000000000 --- a/tests/basics/subclass-native5.py +++ /dev/null @@ -1,12 +0,0 @@ -# Subclass from 2 bases explicitly subclasses from object - -class Base1(object): - pass - -class Base2(object): - pass - -class Sub(Base1, Base2): - pass - -o = Sub() diff --git a/tests/basics/subclass_native1.py b/tests/basics/subclass_native1.py new file mode 100644 index 000000000..a17689342 --- /dev/null +++ b/tests/basics/subclass_native1.py @@ -0,0 +1,31 @@ +class mylist(list): + pass + +a = mylist([1, 2, 5]) +# Test setting instance attr +a.attr = "something" +# Test base type __str__ +print(a) +# Test getting instance attr +print(a.attr) +# Test base type ->subscr +print(a[-1]) +a[0] = -1 +print(a) +# Test another base type unary op +print(len(a)) + +# Test binary op of base type, with 2nd arg being raw base type +print(a + [20, 30, 40]) +# Test binary op of base type, with 2nd arg being same class as 1st arg +# TODO: Faults +#print(a + a) + +def foo(): + print("hello from foo") + +try: + class myfunc(type(foo)): + pass +except TypeError: + print("TypeError") diff --git a/tests/basics/subclass_native2_list.py b/tests/basics/subclass_native2_list.py new file mode 100644 index 000000000..9ad0b77ef --- /dev/null +++ b/tests/basics/subclass_native2_list.py @@ -0,0 +1,26 @@ +class Base1: + def __init__(self, *args): + print("Base1.__init__", args) + +class Clist1(Base1, list): + pass + +a = Clist1() +print(len(a)) +# Not compliant - list assignment should happen in list.__init__, which is not called +# because there's Base1.__init__, but we assign in list.__new__ +#a = Clist1([1, 2, 3]) +#print(len(a)) + +print("---") + +class Clist2(list, Base1): + pass + +# Not compliant - should call list.__init__, but we don't have it +#a = Clist2() +#print(len(a)) + +# Not compliant - should call list.__init__, but we don't have it +#a = Clist2([1, 2, 3]) +#print(len(a)) diff --git a/tests/basics/subclass_native2_tuple.py b/tests/basics/subclass_native2_tuple.py new file mode 100644 index 000000000..9eb69e157 --- /dev/null +++ b/tests/basics/subclass_native2_tuple.py @@ -0,0 +1,21 @@ +class Base1: + def __init__(self, *args): + print("Base1.__init__", args) + +class Ctuple1(Base1, tuple): + pass + +a = Ctuple1() +print(len(a)) +a = Ctuple1([1, 2, 3]) +print(len(a)) + +print("---") + +class Ctuple2(tuple, Base1): + pass + +a = Ctuple2() +print(len(a)) +a = Ctuple2([1, 2, 3]) +print(len(a)) diff --git a/tests/basics/subclass_native3.py b/tests/basics/subclass_native3.py new file mode 100644 index 000000000..bd99ab0d6 --- /dev/null +++ b/tests/basics/subclass_native3.py @@ -0,0 +1,22 @@ +class MyExc(Exception): + pass + +e = MyExc(100, "Some error") +print(e) +print(repr(e)) +print(e.args) + +try: + raise MyExc("Some error") +except MyExc as e: + print("Caught exception:", repr(e)) + +try: + raise MyExc("Some error2") +except Exception as e: + print("Caught exception:", repr(e)) + +try: + raise MyExc("Some error2") +except: + print("Caught user exception") diff --git a/tests/basics/subclass_native4.py b/tests/basics/subclass_native4.py new file mode 100644 index 000000000..b426793f5 --- /dev/null +++ b/tests/basics/subclass_native4.py @@ -0,0 +1,9 @@ +# Test calling non-special method inherited from native type + +class mylist(list): + pass + +l = mylist([1, 2, 3]) +print(l) +l.append(10) +print(l) diff --git a/tests/basics/subclass_native5.py b/tests/basics/subclass_native5.py new file mode 100644 index 000000000..6127dae33 --- /dev/null +++ b/tests/basics/subclass_native5.py @@ -0,0 +1,12 @@ +# Subclass from 2 bases explicitly subclasses from object + +class Base1(object): + pass + +class Base2(object): + pass + +class Sub(Base1, Base2): + pass + +o = Sub() diff --git a/tests/basics/true-value.py b/tests/basics/true-value.py deleted file mode 100644 index 9ec209fe8..000000000 --- a/tests/basics/true-value.py +++ /dev/null @@ -1,30 +0,0 @@ -# Test true-ish value handling - -if not False: - print("False") - -if not None: - print("None") - -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/true_value.py b/tests/basics/true_value.py new file mode 100644 index 000000000..9ec209fe8 --- /dev/null +++ b/tests/basics/true_value.py @@ -0,0 +1,30 @@ +# Test true-ish value handling + +if not False: + print("False") + +if not None: + print("None") + +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/try-as-var.py b/tests/basics/try-as-var.py deleted file mode 100644 index 0a92f1cae..000000000 --- a/tests/basics/try-as-var.py +++ /dev/null @@ -1,10 +0,0 @@ -try: - raise ValueError(534) -except ValueError as e: - print(repr(e)) - -# Var bound in except block is automatically deleted -try: - e -except NameError: - print("NameError") diff --git a/tests/basics/try-finally-loops.py b/tests/basics/try-finally-loops.py deleted file mode 100644 index 28a8373dc..000000000 --- a/tests/basics/try-finally-loops.py +++ /dev/null @@ -1,35 +0,0 @@ -# Test various loop types, some may be implemented/optimized differently -while True: - try: - break - finally: - print('finally 1') - - -for i in [1, 5, 10]: - try: - continue - finally: - print('finally 2') - -for i in range(3): - try: - continue - finally: - print('finally 3') - -# Multi-level -for i in range(4): - print(i) - try: - while True: - try: - try: - break - finally: - print('finally 1') - finally: - print('finally 2') - print('here') - finally: - print('finnaly 3') diff --git a/tests/basics/try-finally-return.py b/tests/basics/try-finally-return.py deleted file mode 100644 index 4adf3f097..000000000 --- a/tests/basics/try-finally-return.py +++ /dev/null @@ -1,23 +0,0 @@ -def func1(): - try: - return "it worked" - finally: - print("finally 1") - -print(func1()) - - -def func2(): - try: - return "it worked" - finally: - print("finally 2") - -def func3(): - try: - s = func2() - return s + ", did this work?" - finally: - print("finally 3") - -print(func3()) diff --git a/tests/basics/try-finally1.py b/tests/basics/try-finally1.py deleted file mode 100644 index 2416f6d18..000000000 --- a/tests/basics/try-finally1.py +++ /dev/null @@ -1,71 +0,0 @@ -print("noexc-finally") -try: - print("try") -finally: - print("finally") - -print("noexc-finally-finally") -try: - print("try1") - try: - print("try2") - finally: - print("finally2") -finally: - print("finally1") -print() - -print("noexc-finally-func-finally") -def func2(): - try: - print("try2") - finally: - print("finally2") - -try: - print("try1") - func2() -finally: - print("finally1") -print() - - -print("exc-finally-except") -try: - print("try1") - try: - print("try2") - foo() - except: - print("except2") -finally: - print("finally1") -print() - -print("exc-finally-except-filter") -try: - print("try1") - try: - print("try2") - foo() - except NameError: - print("except2") -finally: - print("finally1") -print() - - -print("exc-except-finally-finally") -try: # top-level catch-all except to not fail script - try: - print("try1") - try: - print("try2") - foo() - finally: - print("finally2") - finally: - print("finally1") -except: - print("catch-all except") -print() diff --git a/tests/basics/try-reraise.py b/tests/basics/try-reraise.py deleted file mode 100644 index bf5e77c0b..000000000 --- a/tests/basics/try-reraise.py +++ /dev/null @@ -1,19 +0,0 @@ -# Reraising last exception with raise w/o args - -def f(): - try: - raise ValueError("val", 3) - except: - raise - -try: - f() -except ValueError as e: - print(repr(e)) - - -# Can reraise only in except block -try: - raise -except RuntimeError: - print("RuntimeError") diff --git a/tests/basics/try-reraise2.py b/tests/basics/try-reraise2.py deleted file mode 100644 index d9434397c..000000000 --- a/tests/basics/try-reraise2.py +++ /dev/null @@ -1,32 +0,0 @@ -# Reraise not the latest occured exception -def f(): - try: - raise ValueError("val", 3) - except: - try: - print(1) - raise TypeError - except: - print(2) - try: - print(3) - try: - print(4) - raise AttributeError - except: - print(5) - pass - print(6) - raise - except TypeError: - print(7) - pass - print(8) - print(9) - # This should raise original ValueError, not the most recently occurred AttributeError - raise - -try: - f() -except ValueError as e: - print(repr(e)) diff --git a/tests/basics/try_as_var.py b/tests/basics/try_as_var.py new file mode 100644 index 000000000..0a92f1cae --- /dev/null +++ b/tests/basics/try_as_var.py @@ -0,0 +1,10 @@ +try: + raise ValueError(534) +except ValueError as e: + print(repr(e)) + +# Var bound in except block is automatically deleted +try: + e +except NameError: + print("NameError") diff --git a/tests/basics/try_finally1.py b/tests/basics/try_finally1.py new file mode 100644 index 000000000..2416f6d18 --- /dev/null +++ b/tests/basics/try_finally1.py @@ -0,0 +1,71 @@ +print("noexc-finally") +try: + print("try") +finally: + print("finally") + +print("noexc-finally-finally") +try: + print("try1") + try: + print("try2") + finally: + print("finally2") +finally: + print("finally1") +print() + +print("noexc-finally-func-finally") +def func2(): + try: + print("try2") + finally: + print("finally2") + +try: + print("try1") + func2() +finally: + print("finally1") +print() + + +print("exc-finally-except") +try: + print("try1") + try: + print("try2") + foo() + except: + print("except2") +finally: + print("finally1") +print() + +print("exc-finally-except-filter") +try: + print("try1") + try: + print("try2") + foo() + except NameError: + print("except2") +finally: + print("finally1") +print() + + +print("exc-except-finally-finally") +try: # top-level catch-all except to not fail script + try: + print("try1") + try: + print("try2") + foo() + finally: + print("finally2") + finally: + print("finally1") +except: + print("catch-all except") +print() diff --git a/tests/basics/try_finally_loops.py b/tests/basics/try_finally_loops.py new file mode 100644 index 000000000..28a8373dc --- /dev/null +++ b/tests/basics/try_finally_loops.py @@ -0,0 +1,35 @@ +# Test various loop types, some may be implemented/optimized differently +while True: + try: + break + finally: + print('finally 1') + + +for i in [1, 5, 10]: + try: + continue + finally: + print('finally 2') + +for i in range(3): + try: + continue + finally: + print('finally 3') + +# Multi-level +for i in range(4): + print(i) + try: + while True: + try: + try: + break + finally: + print('finally 1') + finally: + print('finally 2') + print('here') + finally: + print('finnaly 3') diff --git a/tests/basics/try_finally_return.py b/tests/basics/try_finally_return.py new file mode 100644 index 000000000..4adf3f097 --- /dev/null +++ b/tests/basics/try_finally_return.py @@ -0,0 +1,23 @@ +def func1(): + try: + return "it worked" + finally: + print("finally 1") + +print(func1()) + + +def func2(): + try: + return "it worked" + finally: + print("finally 2") + +def func3(): + try: + s = func2() + return s + ", did this work?" + finally: + print("finally 3") + +print(func3()) diff --git a/tests/basics/try_reraise.py b/tests/basics/try_reraise.py new file mode 100644 index 000000000..bf5e77c0b --- /dev/null +++ b/tests/basics/try_reraise.py @@ -0,0 +1,19 @@ +# Reraising last exception with raise w/o args + +def f(): + try: + raise ValueError("val", 3) + except: + raise + +try: + f() +except ValueError as e: + print(repr(e)) + + +# Can reraise only in except block +try: + raise +except RuntimeError: + print("RuntimeError") diff --git a/tests/basics/try_reraise2.py b/tests/basics/try_reraise2.py new file mode 100644 index 000000000..d9434397c --- /dev/null +++ b/tests/basics/try_reraise2.py @@ -0,0 +1,32 @@ +# Reraise not the latest occured exception +def f(): + try: + raise ValueError("val", 3) + except: + try: + print(1) + raise TypeError + except: + print(2) + try: + print(3) + try: + print(4) + raise AttributeError + except: + print(5) + pass + print(6) + raise + except TypeError: + print(7) + pass + print(8) + print(9) + # This should raise original ValueError, not the most recently occurred AttributeError + raise + +try: + f() +except ValueError as e: + print(repr(e)) diff --git a/tests/basics/with-break.py b/tests/basics/with-break.py deleted file mode 100644 index f1063d582..000000000 --- a/tests/basics/with-break.py +++ /dev/null @@ -1,14 +0,0 @@ -class CtxMgr: - - def __enter__(self): - print("__enter__") - return self - - def __exit__(self, a, b, c): - print("__exit__", repr(a), repr(b)) - -for i in range(5): - print(i) - with CtxMgr(): - if i == 3: - break diff --git a/tests/basics/with-continue.py b/tests/basics/with-continue.py deleted file mode 100644 index fc2b24bd4..000000000 --- a/tests/basics/with-continue.py +++ /dev/null @@ -1,14 +0,0 @@ -class CtxMgr: - - def __enter__(self): - print("__enter__") - return self - - def __exit__(self, a, b, c): - print("__exit__", repr(a), repr(b)) - -for i in range(5): - print(i) - with CtxMgr(): - if i == 3: - continue diff --git a/tests/basics/with-return.py b/tests/basics/with-return.py deleted file mode 100644 index cb0135c8b..000000000 --- a/tests/basics/with-return.py +++ /dev/null @@ -1,14 +0,0 @@ -class CtxMgr: - - def __enter__(self): - print("__enter__") - return self - - def __exit__(self, a, b, c): - print("__exit__", repr(a), repr(b)) - -def foo(): - with CtxMgr(): - return 4 - -print(foo()) diff --git a/tests/basics/with_break.py b/tests/basics/with_break.py new file mode 100644 index 000000000..f1063d582 --- /dev/null +++ b/tests/basics/with_break.py @@ -0,0 +1,14 @@ +class CtxMgr: + + def __enter__(self): + print("__enter__") + return self + + def __exit__(self, a, b, c): + print("__exit__", repr(a), repr(b)) + +for i in range(5): + print(i) + with CtxMgr(): + if i == 3: + break diff --git a/tests/basics/with_continue.py b/tests/basics/with_continue.py new file mode 100644 index 000000000..fc2b24bd4 --- /dev/null +++ b/tests/basics/with_continue.py @@ -0,0 +1,14 @@ +class CtxMgr: + + def __enter__(self): + print("__enter__") + return self + + def __exit__(self, a, b, c): + print("__exit__", repr(a), repr(b)) + +for i in range(5): + print(i) + with CtxMgr(): + if i == 3: + continue diff --git a/tests/basics/with_return.py b/tests/basics/with_return.py new file mode 100644 index 000000000..cb0135c8b --- /dev/null +++ b/tests/basics/with_return.py @@ -0,0 +1,14 @@ +class CtxMgr: + + def __enter__(self): + print("__enter__") + return self + + def __exit__(self, a, b, c): + print("__exit__", repr(a), repr(b)) + +def foo(): + with CtxMgr(): + return 4 + +print(foo()) diff --git a/tests/float/builtin-float-minmax.py b/tests/float/builtin-float-minmax.py deleted file mode 100644 index ce45a768a..000000000 --- a/tests/float/builtin-float-minmax.py +++ /dev/null @@ -1,26 +0,0 @@ -# test builtin min and max functions with float args - -print(min(0,1.0)) -print(min(1.0,0)) -print(min(0,-1.0)) -print(min(-1.0,0)) - -print(max(0,1.0)) -print(max(1.0,0)) -print(max(0,-1.0)) -print(max(-1.0,0)) - -print(min(1.5,-1.5)) -print(min(-1.5,1.5)) - -print(max(1.5,-1.5)) -print(max(-1.5,1.5)) - -print(min([1,2.9,4,0,-1,2])) -print(max([1,2.9,4,0,-1,2])) - -print(min([1,2.9,4,6.5,-1,2])) -print(max([1,2.9,4,6.5,-1,2])) -print(min([1,2.9,4,-6.5,-1,2])) -print(max([1,2.9,4,-6.5,-1,2])) - diff --git a/tests/float/builtin_float_minmax.py b/tests/float/builtin_float_minmax.py new file mode 100644 index 000000000..ce45a768a --- /dev/null +++ b/tests/float/builtin_float_minmax.py @@ -0,0 +1,26 @@ +# test builtin min and max functions with float args + +print(min(0,1.0)) +print(min(1.0,0)) +print(min(0,-1.0)) +print(min(-1.0,0)) + +print(max(0,1.0)) +print(max(1.0,0)) +print(max(0,-1.0)) +print(max(-1.0,0)) + +print(min(1.5,-1.5)) +print(min(-1.5,1.5)) + +print(max(1.5,-1.5)) +print(max(-1.5,1.5)) + +print(min([1,2.9,4,0,-1,2])) +print(max([1,2.9,4,0,-1,2])) + +print(min([1,2.9,4,6.5,-1,2])) +print(max([1,2.9,4,6.5,-1,2])) +print(min([1,2.9,4,-6.5,-1,2])) +print(max([1,2.9,4,-6.5,-1,2])) + diff --git a/tests/float/int-divzero.py b/tests/float/int-divzero.py deleted file mode 100644 index b037dd8c7..000000000 --- a/tests/float/int-divzero.py +++ /dev/null @@ -1,4 +0,0 @@ -try: - 1 / 0 -except ZeroDivisionError: - print("ZeroDivisionError") diff --git a/tests/float/int_divzero.py b/tests/float/int_divzero.py new file mode 100644 index 000000000..b037dd8c7 --- /dev/null +++ b/tests/float/int_divzero.py @@ -0,0 +1,4 @@ +try: + 1 / 0 +except ZeroDivisionError: + print("ZeroDivisionError") diff --git a/tests/float/list-index.py b/tests/float/list-index.py deleted file mode 100644 index 13e4557af..000000000 --- a/tests/float/list-index.py +++ /dev/null @@ -1,8 +0,0 @@ -x = [1, 2] - -print(x[1]) - -try: - print(x[1.0]) -except TypeError: - print("TypeError") diff --git a/tests/float/list_index.py b/tests/float/list_index.py new file mode 100644 index 000000000..13e4557af --- /dev/null +++ b/tests/float/list_index.py @@ -0,0 +1,8 @@ +x = [1, 2] + +print(x[1]) + +try: + print(x[1.0]) +except TypeError: + print("TypeError") diff --git a/tests/float/math-fun-bool.py b/tests/float/math-fun-bool.py deleted file mode 100644 index 57232857a..000000000 --- a/tests/float/math-fun-bool.py +++ /dev/null @@ -1,17 +0,0 @@ -# Test the bool functions from math - -try: - from math import isfinite, isnan, isinf -except ImportError: - print("SKIP") - import sys - sys.exit() - -test_values = [1, 0, -1, 1.0, 0.0, -1.0, float('NaN'), float('Inf'), - -float('NaN'), -float('Inf')] - -functions = [isfinite, isnan, isinf] - -for val in test_values: - for f in functions: - print(f(val)) diff --git a/tests/float/math-fun.py b/tests/float/math-fun.py deleted file mode 100644 index fa111e33e..000000000 --- a/tests/float/math-fun.py +++ /dev/null @@ -1,51 +0,0 @@ -# Tests the functions imported from math - -try: - from math import * -except ImportError: - print("SKIP") - import sys - sys.exit() - -test_values = [-100., -1.23456, -1, -0.5, 0.0, 0.5, 1.23456, 100.] -p_test_values = [0.1, 0.5, 1.23456] -unit_range_test_values = [-1., -0.75, -0.5, -0.25, 0., 0.25, 0.5, 0.75, 1.] - -functions = [('sqrt', sqrt, p_test_values), - ('exp', exp, test_values), - ('expm1', expm1, test_values), - ('log', log, p_test_values), - ('log2', log2, p_test_values), - ('log10', log10, p_test_values), - ('cosh', cosh, test_values), - ('sinh', sinh, test_values), - ('tanh', tanh, test_values), - ('acosh', acosh, [1.0, 5.0, 1.0]), - ('asinh', asinh, test_values), - ('atanh', atanh, [-0.99, -0.5, 0.0, 0.5, 0.99]), - ('cos', cos, test_values), - ('sin', sin, test_values), - ('tan', tan, test_values), - ('acos', acos, unit_range_test_values), - ('asin', asin, unit_range_test_values), - ('atan', atan, test_values), - ('ceil', ceil, test_values), - ('fabs', fabs, test_values), - ('floor', floor, test_values), - #('frexp', frexp, test_values), - ('trunc', trunc, test_values) - ] - -for function_name, function, test_vals in functions: - print(function_name) - for value in test_vals: - print("{:.7g}".format(function(value))) - -binary_functions = [('copysign', copysign, [(23., 42.), (-23., 42.), (23., -42.), - (-23., -42.), (1., 0.0), (1., -0.0)]) - ] - -for function_name, function, test_vals in binary_functions: - print(function_name) - for value1, value2 in test_vals: - print("{:.7g}".format(function(value1, value2))) diff --git a/tests/float/math_fun.py b/tests/float/math_fun.py new file mode 100644 index 000000000..fa111e33e --- /dev/null +++ b/tests/float/math_fun.py @@ -0,0 +1,51 @@ +# Tests the functions imported from math + +try: + from math import * +except ImportError: + print("SKIP") + import sys + sys.exit() + +test_values = [-100., -1.23456, -1, -0.5, 0.0, 0.5, 1.23456, 100.] +p_test_values = [0.1, 0.5, 1.23456] +unit_range_test_values = [-1., -0.75, -0.5, -0.25, 0., 0.25, 0.5, 0.75, 1.] + +functions = [('sqrt', sqrt, p_test_values), + ('exp', exp, test_values), + ('expm1', expm1, test_values), + ('log', log, p_test_values), + ('log2', log2, p_test_values), + ('log10', log10, p_test_values), + ('cosh', cosh, test_values), + ('sinh', sinh, test_values), + ('tanh', tanh, test_values), + ('acosh', acosh, [1.0, 5.0, 1.0]), + ('asinh', asinh, test_values), + ('atanh', atanh, [-0.99, -0.5, 0.0, 0.5, 0.99]), + ('cos', cos, test_values), + ('sin', sin, test_values), + ('tan', tan, test_values), + ('acos', acos, unit_range_test_values), + ('asin', asin, unit_range_test_values), + ('atan', atan, test_values), + ('ceil', ceil, test_values), + ('fabs', fabs, test_values), + ('floor', floor, test_values), + #('frexp', frexp, test_values), + ('trunc', trunc, test_values) + ] + +for function_name, function, test_vals in functions: + print(function_name) + for value in test_vals: + print("{:.7g}".format(function(value))) + +binary_functions = [('copysign', copysign, [(23., 42.), (-23., 42.), (23., -42.), + (-23., -42.), (1., 0.0), (1., -0.0)]) + ] + +for function_name, function, test_vals in binary_functions: + print(function_name) + for value1, value2 in test_vals: + print("{:.7g}".format(function(value1, value2))) diff --git a/tests/float/math_fun_bool.py b/tests/float/math_fun_bool.py new file mode 100644 index 000000000..57232857a --- /dev/null +++ b/tests/float/math_fun_bool.py @@ -0,0 +1,17 @@ +# Test the bool functions from math + +try: + from math import isfinite, isnan, isinf +except ImportError: + print("SKIP") + import sys + sys.exit() + +test_values = [1, 0, -1, 1.0, 0.0, -1.0, float('NaN'), float('Inf'), + -float('NaN'), -float('Inf')] + +functions = [isfinite, isnan, isinf] + +for val in test_values: + for f in functions: + print(f(val)) diff --git a/tests/float/string-format-modulo.py b/tests/float/string-format-modulo.py deleted file mode 100644 index ddca0b555..000000000 --- a/tests/float/string-format-modulo.py +++ /dev/null @@ -1,19 +0,0 @@ -print("%s" % 1.0) -print("%r" % 1.0) - -print("%d" % 1.0) -print("%i" % 1.0) -print("%u" % 1.0) - -# these 3 have different behaviour in Python 3.x versions -# uPy raises a TypeError, following Python 3.5 (earlier versions don't) -#print("%x" % 18.0) -#print("%o" % 18.0) -#print("%X" % 18.0) - -print("%e" % 1.23456) -print("%E" % 1.23456) -print("%f" % 1.23456) -print("%F" % 1.23456) -print("%g" % 1.23456) -print("%G" % 1.23456) diff --git a/tests/float/string-format.py b/tests/float/string-format.py deleted file mode 100644 index b5ff68b8c..000000000 --- a/tests/float/string-format.py +++ /dev/null @@ -1,123 +0,0 @@ -# Change the following to True to get a much more comprehensive set of tests -# to run, albeit, which take considerably longer. - -full_tests = False - -def test(fmt, *args): - print('{:8s}'.format(fmt) + '>' + fmt.format(*args) + '<') - -test("{:10.4e}", 123.456) -test("{:10.4e}", -123.456) -test("{:10.4f}", 123.456) -test("{:10.4f}", -123.456) -test("{:10.4g}", 123.456) -test("{:10.4g}", -123.456) -test("{:e}", 100) -test("{:f}", 200) -test("{:g}", 300) - -test("{:10.4E}", 123.456) -test("{:10.4E}", -123.456) -test("{:10.4F}", 123.456) -test("{:10.4F}", -123.456) -test("{:10.4G}", 123.456) -test("{:10.4G}", -123.456) - -# The following fails right now -#test("{:10.1}", 0.0) - -def test_fmt(conv, fill, alignment, sign, prefix, width, precision, type, arg): - fmt = '{' - if conv: - fmt += '!' - fmt += conv - fmt += ':' - if alignment: - fmt += fill - fmt += alignment - fmt += sign - fmt += prefix - fmt += width - if precision: - fmt += '.' - fmt += precision - fmt += type - fmt += '}' - test(fmt, arg) - if fill == '0' and alignment == '=': - fmt = '{:' - fmt += sign - fmt += prefix - fmt += width - if precision: - fmt += '.' - fmt += precision - fmt += type - fmt += '}' - test(fmt, arg) - -eg_nums = (0.0, -0.0, 0.1, 1.234, 12.3459, 1.23456789, 123456789.0, -0.0, - -0.1, -1.234, -12.3459, 1e4, 1e-4, 1e5, 1e-5, 1e6, 1e-6, 1e10, - 1e37, -1e37, 1e-37, -1e-37, - 1.23456e8, 1.23456e7, 1.23456e6, 1.23456e5, 1.23456e4, 1.23456e3, 1.23456e2, 1.23456e1, 1.23456e0, - 1.23456e-1, 1.23456e-2, 1.23456e-3, 1.23456e-4, 1.23456e-5, 1.23456e-6, 1.23456e-7, 1.23456e-8, - -1.23456e8, -1.23456e7, -1.23456e6, -1.23456e5, -1.23456e4, -1.23456e3, -1.23456e2, -1.23456e1, -1.23456e0, - -1.23456e-1, -1.23456e-2, -1.23456e-3, -1.23456e-4, -1.23456e-5, -1.23456e-6, -1.23456e-7, -1.23456e-8) - -if full_tests: - for type in ('e', 'E', 'g', 'G', 'n'): - for width in ('', '4', '6', '8', '10'): - for alignment in ('', '<', '>', '=', '^'): - for fill in ('', '@', '0', ' '): - for sign in ('', '+', '-', ' '): - for prec in ('', '1', '3', '6'): - for num in eg_nums: - test_fmt('', fill, alignment, sign, '', width, prec, type, num) - -# Note: We use 1.23459 rather than 1.2345 because '{:3f}'.format(1.2345) -# rounds differently than print("%.3f", 1.2345); - -f_nums = (0.0, -0.0, 0.0001, 0.001, 0.01, 0.1, 1.0, 10.0, - 0.0012, 0.0123, 0.1234, 1.23459, 12.3456, - -0.0001, -0.001, -0.01, -0.1, -1.0, -10.0, - -0.0012, -0.0123, -0.1234, -1.23459, -12.3456) - -if full_tests: - for type in ('f', 'F'): - for width in ('', '4', '6', '8', '10'): - for alignment in ('', '<', '>', '=', '^'): - for fill in ('', ' ', '0', '@'): - for sign in ('', '+', '-', ' '): - # An empty precision defaults to 6, but when uPy is - # configured to use a float, we can only use a - # precision of 6 with numbers less than 10 and still - # get results that compare to CPython (which uses - # long doubles). - for prec in ('1', '2', '3'): - for num in f_nums: - test_fmt('', fill, alignment, sign, '', width, prec, type, num) - for num in int_nums2: - test_fmt('', fill, alignment, sign, '', width, '', type, num) - -pct_nums1 = (0.1, 0.58, 0.99, -0.1, -0.58, -0.99) -pct_nums2 = (True, False, 1, 0, -1) - -if full_tests: - type = '%' - for width in ('', '4', '6', '8', '10'): - for alignment in ('', '<', '>', '=', '^'): - for fill in ('', ' ', '0', '@'): - for sign in ('', '+', '-', ' '): - # An empty precision defaults to 6, but when uPy is - # configured to use a float, we can only use a - # precision of 6 with numbers less than 10 and still - # get results that compare to CPython (which uses - # long doubles). - for prec in ('1', '2', '3'): - for num in pct_nums1: - test_fmt('', fill, alignment, sign, '', width, prec, type, num) - for num in pct_nums2: - test_fmt('', fill, alignment, sign, '', width, '', type, num) - -# We don't currently test a type of '' with floats (see the detailed comment -# in objstr.c) diff --git a/tests/float/string_format.py b/tests/float/string_format.py new file mode 100644 index 000000000..b5ff68b8c --- /dev/null +++ b/tests/float/string_format.py @@ -0,0 +1,123 @@ +# Change the following to True to get a much more comprehensive set of tests +# to run, albeit, which take considerably longer. + +full_tests = False + +def test(fmt, *args): + print('{:8s}'.format(fmt) + '>' + fmt.format(*args) + '<') + +test("{:10.4e}", 123.456) +test("{:10.4e}", -123.456) +test("{:10.4f}", 123.456) +test("{:10.4f}", -123.456) +test("{:10.4g}", 123.456) +test("{:10.4g}", -123.456) +test("{:e}", 100) +test("{:f}", 200) +test("{:g}", 300) + +test("{:10.4E}", 123.456) +test("{:10.4E}", -123.456) +test("{:10.4F}", 123.456) +test("{:10.4F}", -123.456) +test("{:10.4G}", 123.456) +test("{:10.4G}", -123.456) + +# The following fails right now +#test("{:10.1}", 0.0) + +def test_fmt(conv, fill, alignment, sign, prefix, width, precision, type, arg): + fmt = '{' + if conv: + fmt += '!' + fmt += conv + fmt += ':' + if alignment: + fmt += fill + fmt += alignment + fmt += sign + fmt += prefix + fmt += width + if precision: + fmt += '.' + fmt += precision + fmt += type + fmt += '}' + test(fmt, arg) + if fill == '0' and alignment == '=': + fmt = '{:' + fmt += sign + fmt += prefix + fmt += width + if precision: + fmt += '.' + fmt += precision + fmt += type + fmt += '}' + test(fmt, arg) + +eg_nums = (0.0, -0.0, 0.1, 1.234, 12.3459, 1.23456789, 123456789.0, -0.0, + -0.1, -1.234, -12.3459, 1e4, 1e-4, 1e5, 1e-5, 1e6, 1e-6, 1e10, + 1e37, -1e37, 1e-37, -1e-37, + 1.23456e8, 1.23456e7, 1.23456e6, 1.23456e5, 1.23456e4, 1.23456e3, 1.23456e2, 1.23456e1, 1.23456e0, + 1.23456e-1, 1.23456e-2, 1.23456e-3, 1.23456e-4, 1.23456e-5, 1.23456e-6, 1.23456e-7, 1.23456e-8, + -1.23456e8, -1.23456e7, -1.23456e6, -1.23456e5, -1.23456e4, -1.23456e3, -1.23456e2, -1.23456e1, -1.23456e0, + -1.23456e-1, -1.23456e-2, -1.23456e-3, -1.23456e-4, -1.23456e-5, -1.23456e-6, -1.23456e-7, -1.23456e-8) + +if full_tests: + for type in ('e', 'E', 'g', 'G', 'n'): + for width in ('', '4', '6', '8', '10'): + for alignment in ('', '<', '>', '=', '^'): + for fill in ('', '@', '0', ' '): + for sign in ('', '+', '-', ' '): + for prec in ('', '1', '3', '6'): + for num in eg_nums: + test_fmt('', fill, alignment, sign, '', width, prec, type, num) + +# Note: We use 1.23459 rather than 1.2345 because '{:3f}'.format(1.2345) +# rounds differently than print("%.3f", 1.2345); + +f_nums = (0.0, -0.0, 0.0001, 0.001, 0.01, 0.1, 1.0, 10.0, + 0.0012, 0.0123, 0.1234, 1.23459, 12.3456, + -0.0001, -0.001, -0.01, -0.1, -1.0, -10.0, + -0.0012, -0.0123, -0.1234, -1.23459, -12.3456) + +if full_tests: + for type in ('f', 'F'): + for width in ('', '4', '6', '8', '10'): + for alignment in ('', '<', '>', '=', '^'): + for fill in ('', ' ', '0', '@'): + for sign in ('', '+', '-', ' '): + # An empty precision defaults to 6, but when uPy is + # configured to use a float, we can only use a + # precision of 6 with numbers less than 10 and still + # get results that compare to CPython (which uses + # long doubles). + for prec in ('1', '2', '3'): + for num in f_nums: + test_fmt('', fill, alignment, sign, '', width, prec, type, num) + for num in int_nums2: + test_fmt('', fill, alignment, sign, '', width, '', type, num) + +pct_nums1 = (0.1, 0.58, 0.99, -0.1, -0.58, -0.99) +pct_nums2 = (True, False, 1, 0, -1) + +if full_tests: + type = '%' + for width in ('', '4', '6', '8', '10'): + for alignment in ('', '<', '>', '=', '^'): + for fill in ('', ' ', '0', '@'): + for sign in ('', '+', '-', ' '): + # An empty precision defaults to 6, but when uPy is + # configured to use a float, we can only use a + # precision of 6 with numbers less than 10 and still + # get results that compare to CPython (which uses + # long doubles). + for prec in ('1', '2', '3'): + for num in pct_nums1: + test_fmt('', fill, alignment, sign, '', width, prec, type, num) + for num in pct_nums2: + test_fmt('', fill, alignment, sign, '', width, '', type, num) + +# We don't currently test a type of '' with floats (see the detailed comment +# in objstr.c) diff --git a/tests/float/string_format_modulo.py b/tests/float/string_format_modulo.py new file mode 100644 index 000000000..ddca0b555 --- /dev/null +++ b/tests/float/string_format_modulo.py @@ -0,0 +1,19 @@ +print("%s" % 1.0) +print("%r" % 1.0) + +print("%d" % 1.0) +print("%i" % 1.0) +print("%u" % 1.0) + +# these 3 have different behaviour in Python 3.x versions +# uPy raises a TypeError, following Python 3.5 (earlier versions don't) +#print("%x" % 18.0) +#print("%o" % 18.0) +#print("%X" % 18.0) + +print("%e" % 1.23456) +print("%E" % 1.23456) +print("%f" % 1.23456) +print("%F" % 1.23456) +print("%g" % 1.23456) +print("%G" % 1.23456) diff --git a/tests/float/true-value.py b/tests/float/true-value.py deleted file mode 100644 index df415f003..000000000 --- a/tests/float/true-value.py +++ /dev/null @@ -1,7 +0,0 @@ -# Test true-ish value handling - -if not 0.0: - print("float 0") - -if not 0+0j: - print("complex 0") diff --git a/tests/float/true_value.py b/tests/float/true_value.py new file mode 100644 index 000000000..df415f003 --- /dev/null +++ b/tests/float/true_value.py @@ -0,0 +1,7 @@ +# Test true-ish value handling + +if not 0.0: + print("float 0") + +if not 0+0j: + print("complex 0") diff --git a/tests/import/import-pkg1.py b/tests/import/import-pkg1.py deleted file mode 100644 index 8cd77af79..000000000 --- a/tests/import/import-pkg1.py +++ /dev/null @@ -1,11 +0,0 @@ -import pkg.mod - -print(pkg.__name__) -print(pkg.mod.__name__) -print(pkg.mod.foo()) - -# Import 2nd time, must be same module objects -pkg_ = __import__("pkg.mod") -print(pkg_ is not pkg.mod) -print(pkg_ is pkg) -print(pkg_.mod is pkg.mod) diff --git a/tests/import/import-pkg2.py b/tests/import/import-pkg2.py deleted file mode 100644 index 2e9f34121..000000000 --- a/tests/import/import-pkg2.py +++ /dev/null @@ -1,18 +0,0 @@ -from pkg.mod import foo - -try: - pkg -except NameError: - print("NameError") -try: - pkg.mod -except NameError: - print("NameError") -print(foo()) - -# Import few times, must be same module objects -mod_1 = __import__("pkg.mod", None, None, ("foo",)) -mod_2 = __import__("pkg.mod", None, None, ("foo",)) -print(mod_1 is mod_2) -print(mod_1.foo is mod_2.foo) -print(foo is mod_1.foo) diff --git a/tests/import/import-pkg3.py b/tests/import/import-pkg3.py deleted file mode 100644 index 0ee885b22..000000000 --- a/tests/import/import-pkg3.py +++ /dev/null @@ -1,6 +0,0 @@ -from pkg import mod - -print(mod.foo()) - -import pkg.mod -print(mod is pkg.mod) diff --git a/tests/import/import-pkg4.py b/tests/import/import-pkg4.py deleted file mode 100644 index 90b6f2e0e..000000000 --- a/tests/import/import-pkg4.py +++ /dev/null @@ -1,2 +0,0 @@ -# Testing that "recursive" imports (pkg2/__init__.py imports from pkg2) work -import pkg2 diff --git a/tests/import/import-pkg5.py b/tests/import/import-pkg5.py deleted file mode 100644 index aa74bb45f..000000000 --- a/tests/import/import-pkg5.py +++ /dev/null @@ -1,6 +0,0 @@ -# This tests relative imports as used in pkg3 -import pkg3 -import pkg3.mod1 -import pkg3.subpkg1.mod1 - -pkg3.subpkg1.mod1.foo() diff --git a/tests/import/import_pkg1.py b/tests/import/import_pkg1.py new file mode 100644 index 000000000..8cd77af79 --- /dev/null +++ b/tests/import/import_pkg1.py @@ -0,0 +1,11 @@ +import pkg.mod + +print(pkg.__name__) +print(pkg.mod.__name__) +print(pkg.mod.foo()) + +# Import 2nd time, must be same module objects +pkg_ = __import__("pkg.mod") +print(pkg_ is not pkg.mod) +print(pkg_ is pkg) +print(pkg_.mod is pkg.mod) diff --git a/tests/import/import_pkg2.py b/tests/import/import_pkg2.py new file mode 100644 index 000000000..2e9f34121 --- /dev/null +++ b/tests/import/import_pkg2.py @@ -0,0 +1,18 @@ +from pkg.mod import foo + +try: + pkg +except NameError: + print("NameError") +try: + pkg.mod +except NameError: + print("NameError") +print(foo()) + +# Import few times, must be same module objects +mod_1 = __import__("pkg.mod", None, None, ("foo",)) +mod_2 = __import__("pkg.mod", None, None, ("foo",)) +print(mod_1 is mod_2) +print(mod_1.foo is mod_2.foo) +print(foo is mod_1.foo) diff --git a/tests/import/import_pkg3.py b/tests/import/import_pkg3.py new file mode 100644 index 000000000..0ee885b22 --- /dev/null +++ b/tests/import/import_pkg3.py @@ -0,0 +1,6 @@ +from pkg import mod + +print(mod.foo()) + +import pkg.mod +print(mod is pkg.mod) diff --git a/tests/import/import_pkg4.py b/tests/import/import_pkg4.py new file mode 100644 index 000000000..90b6f2e0e --- /dev/null +++ b/tests/import/import_pkg4.py @@ -0,0 +1,2 @@ +# Testing that "recursive" imports (pkg2/__init__.py imports from pkg2) work +import pkg2 diff --git a/tests/import/import_pkg5.py b/tests/import/import_pkg5.py new file mode 100644 index 000000000..aa74bb45f --- /dev/null +++ b/tests/import/import_pkg5.py @@ -0,0 +1,6 @@ +# This tests relative imports as used in pkg3 +import pkg3 +import pkg3.mod1 +import pkg3.subpkg1.mod1 + +pkg3.subpkg1.mod1.foo() diff --git a/tests/import/try-module.py b/tests/import/try-module.py deleted file mode 100644 index 03a9db15b..000000000 --- a/tests/import/try-module.py +++ /dev/null @@ -1,15 +0,0 @@ -# Regression test for #290 - throwing exception in another module led to -# its namespace stick and namespace of current module not coming back. -import import1b - -def func1(): - print('func1') - -def func2(): - try: - import1b.throw() - except ValueError: - pass - func1() - -func2() diff --git a/tests/import/try_module.py b/tests/import/try_module.py new file mode 100644 index 000000000..03a9db15b --- /dev/null +++ b/tests/import/try_module.py @@ -0,0 +1,15 @@ +# Regression test for #290 - throwing exception in another module led to +# its namespace stick and namespace of current module not coming back. +import import1b + +def func1(): + print('func1') + +def func2(): + try: + import1b.throw() + except ValueError: + pass + func1() + +func2() diff --git a/tests/io/file-iter.py b/tests/io/file-iter.py deleted file mode 100644 index 48e873996..000000000 --- a/tests/io/file-iter.py +++ /dev/null @@ -1,3 +0,0 @@ -f = open("io/data/file1") -for l in f: - print(l) diff --git a/tests/io/file-stdio.py b/tests/io/file-stdio.py deleted file mode 100644 index cbdb07016..000000000 --- a/tests/io/file-stdio.py +++ /dev/null @@ -1,4 +0,0 @@ -import sys - -print(sys.stdin.fileno()) -print(sys.stdout.fileno()) diff --git a/tests/io/file-with.py b/tests/io/file-with.py deleted file mode 100644 index ee1e70242..000000000 --- a/tests/io/file-with.py +++ /dev/null @@ -1,21 +0,0 @@ -f = open("io/data/file1") - -with f as f2: - print(f2.read()) - -# File should be closed -try: - f.read() -except: - # Note: CPython and us throw different exception trying to read from - # close file. - print("can't read file after with") - - -# Regression test: test that exception in with initialization properly -# thrown and doesn't crash. -try: - with open('__non_existent', 'r'): - pass -except OSError: - print("OSError") diff --git a/tests/io/file_iter.py b/tests/io/file_iter.py new file mode 100644 index 000000000..48e873996 --- /dev/null +++ b/tests/io/file_iter.py @@ -0,0 +1,3 @@ +f = open("io/data/file1") +for l in f: + print(l) diff --git a/tests/io/file_stdio.py b/tests/io/file_stdio.py new file mode 100644 index 000000000..cbdb07016 --- /dev/null +++ b/tests/io/file_stdio.py @@ -0,0 +1,4 @@ +import sys + +print(sys.stdin.fileno()) +print(sys.stdout.fileno()) diff --git a/tests/io/file_with.py b/tests/io/file_with.py new file mode 100644 index 000000000..ee1e70242 --- /dev/null +++ b/tests/io/file_with.py @@ -0,0 +1,21 @@ +f = open("io/data/file1") + +with f as f2: + print(f2.read()) + +# File should be closed +try: + f.read() +except: + # Note: CPython and us throw different exception trying to read from + # close file. + print("can't read file after with") + + +# Regression test: test that exception in with initialization properly +# thrown and doesn't crash. +try: + with open('__non_existent', 'r'): + pass +except OSError: + print("OSError") diff --git a/tests/misc/rge-sm.py b/tests/misc/rge-sm.py deleted file mode 100644 index 1860f7a31..000000000 --- a/tests/misc/rge-sm.py +++ /dev/null @@ -1,114 +0,0 @@ -# evolve the RGEs of the standard model from electroweak scale up -# by dpgeorge - -import math - -class RungeKutta(object): - def __init__(self, functions, initConditions, t0, dh, save=True): - self.Trajectory, self.save = [[t0] + initConditions], save - self.functions = [lambda *args: 1.0] + list(functions) - self.N, self.dh = len(self.functions), dh - self.coeff = [1.0/6.0, 2.0/6.0, 2.0/6.0, 1.0/6.0] - self.InArgCoeff = [0.0, 0.5, 0.5, 1.0] - - def iterate(self): - step = self.Trajectory[-1][:] - istep, iac = step[:], self.InArgCoeff - k, ktmp = self.N * [0.0], self.N * [0.0] - for ic, c in enumerate(self.coeff): - for if_, f in enumerate(self.functions): - arguments = [ (x + k[i]*iac[ic]) for i, x in enumerate(istep)] - try: - feval = f(*arguments) - except OverflowError: - return False - if abs(feval) > 1e2: # stop integrating - return False - ktmp[if_] = self.dh * feval - k = ktmp[:] - step = [s + c*k[ik] for ik,s in enumerate(step)] - if self.save: - self.Trajectory += [step] - else: - self.Trajectory = [step] - return True - - def solve(self, finishtime): - while self.Trajectory[-1][0] < finishtime: - if not self.iterate(): - break - - def solveNSteps(self, nSteps): - for i in range(nSteps): - if not self.iterate(): - break - - def series(self): - return zip(*self.Trajectory) - -# 1-loop RGES for the main parameters of the SM -# couplings are: g1, g2, g3 of U(1), SU(2), SU(3); yt (top Yukawa), lambda (Higgs quartic) -# see arxiv.org/abs/0812.4950, eqs 10-15 -sysSM = ( - lambda *a: 41.0 / 96.0 / math.pi**2 * a[1]**3, # g1 - lambda *a: -19.0 / 96.0 / math.pi**2 * a[2]**3, # g2 - lambda *a: -42.0 / 96.0 / math.pi**2 * a[3]**3, # g3 - lambda *a: 1.0 / 16.0 / math.pi**2 * (9.0 / 2.0 * a[4]**3 - 8.0 * a[3]**2 * a[4] - 9.0 / 4.0 * a[2]**2 * a[4] - 17.0 / 12.0 * a[1]**2 * a[4]), # yt - lambda *a: 1.0 / 16.0 / math.pi**2 * (24.0 * a[5]**2 + 12.0 * a[4]**2 * a[5] - 9.0 * a[5] * (a[2]**2 + 1.0 / 3.0 * a[1]**2) - 6.0 * a[4]**4 + 9.0 / 8.0 * a[2]**4 + 3.0 / 8.0 * a[1]**4 + 3.0 / 4.0 * a[2]**2 * a[1]**2), # lambda -) - -def drange(start, stop, step): - r = start - while r < stop: - yield r - r += step - -def phaseDiagram(system, trajStart, trajPlot, h=0.1, tend=1.0, range=1.0): - tstart = 0.0 - for i in drange(0, range, 0.1 * range): - for j in drange(0, range, 0.1 * range): - rk = RungeKutta(system, trajStart(i, j), tstart, h) - rk.solve(tend) - # draw the line - for tr in rk.Trajectory: - x, y = trajPlot(tr) - print(x, y) - print() - # draw the arrow - continue - l = (len(rk.Trajectory) - 1) / 3 - if l > 0 and 2 * l < len(rk.Trajectory): - p1 = rk.Trajectory[l] - p2 = rk.Trajectory[2 * l] - x1, y1 = trajPlot(p1) - x2, y2 = trajPlot(p2) - dx = -0.5 * (y2 - y1) # orthogonal to line - dy = 0.5 * (x2 - x1) # orthogonal to line - #l = math.sqrt(dx*dx + dy*dy) - #if abs(l) > 1e-3: - # l = 0.1 / l - # dx *= l - # dy *= l - print(x1 + dx, y1 + dy) - print(x2, y2) - print(x1 - dx, y1 - dy) - print() - -def singleTraj(system, trajStart, h=0.02, tend=1.0): - tstart = 0.0 - - # compute the trajectory - - rk = RungeKutta(system, trajStart, tstart, h) - rk.solve(tend) - - # print out trajectory - - for i in range(len(rk.Trajectory)): - tr = rk.Trajectory[i] - print(' '.join(["{:.5f}".format(t) for t in tr])) - -#phaseDiagram(sysSM, (lambda i, j: [0.354, 0.654, 1.278, 0.8 + 0.2 * i, 0.1 + 0.1 * j]), (lambda a: (a[4], a[5])), h=0.1, tend=math.log(10**17)) - -# initial conditions at M_Z -singleTraj(sysSM, [0.354, 0.654, 1.278, 0.983, 0.131], h=0.5, tend=math.log(10**17)) # true values diff --git a/tests/misc/rge_sm.py b/tests/misc/rge_sm.py new file mode 100644 index 000000000..1860f7a31 --- /dev/null +++ b/tests/misc/rge_sm.py @@ -0,0 +1,114 @@ +# evolve the RGEs of the standard model from electroweak scale up +# by dpgeorge + +import math + +class RungeKutta(object): + def __init__(self, functions, initConditions, t0, dh, save=True): + self.Trajectory, self.save = [[t0] + initConditions], save + self.functions = [lambda *args: 1.0] + list(functions) + self.N, self.dh = len(self.functions), dh + self.coeff = [1.0/6.0, 2.0/6.0, 2.0/6.0, 1.0/6.0] + self.InArgCoeff = [0.0, 0.5, 0.5, 1.0] + + def iterate(self): + step = self.Trajectory[-1][:] + istep, iac = step[:], self.InArgCoeff + k, ktmp = self.N * [0.0], self.N * [0.0] + for ic, c in enumerate(self.coeff): + for if_, f in enumerate(self.functions): + arguments = [ (x + k[i]*iac[ic]) for i, x in enumerate(istep)] + try: + feval = f(*arguments) + except OverflowError: + return False + if abs(feval) > 1e2: # stop integrating + return False + ktmp[if_] = self.dh * feval + k = ktmp[:] + step = [s + c*k[ik] for ik,s in enumerate(step)] + if self.save: + self.Trajectory += [step] + else: + self.Trajectory = [step] + return True + + def solve(self, finishtime): + while self.Trajectory[-1][0] < finishtime: + if not self.iterate(): + break + + def solveNSteps(self, nSteps): + for i in range(nSteps): + if not self.iterate(): + break + + def series(self): + return zip(*self.Trajectory) + +# 1-loop RGES for the main parameters of the SM +# couplings are: g1, g2, g3 of U(1), SU(2), SU(3); yt (top Yukawa), lambda (Higgs quartic) +# see arxiv.org/abs/0812.4950, eqs 10-15 +sysSM = ( + lambda *a: 41.0 / 96.0 / math.pi**2 * a[1]**3, # g1 + lambda *a: -19.0 / 96.0 / math.pi**2 * a[2]**3, # g2 + lambda *a: -42.0 / 96.0 / math.pi**2 * a[3]**3, # g3 + lambda *a: 1.0 / 16.0 / math.pi**2 * (9.0 / 2.0 * a[4]**3 - 8.0 * a[3]**2 * a[4] - 9.0 / 4.0 * a[2]**2 * a[4] - 17.0 / 12.0 * a[1]**2 * a[4]), # yt + lambda *a: 1.0 / 16.0 / math.pi**2 * (24.0 * a[5]**2 + 12.0 * a[4]**2 * a[5] - 9.0 * a[5] * (a[2]**2 + 1.0 / 3.0 * a[1]**2) - 6.0 * a[4]**4 + 9.0 / 8.0 * a[2]**4 + 3.0 / 8.0 * a[1]**4 + 3.0 / 4.0 * a[2]**2 * a[1]**2), # lambda +) + +def drange(start, stop, step): + r = start + while r < stop: + yield r + r += step + +def phaseDiagram(system, trajStart, trajPlot, h=0.1, tend=1.0, range=1.0): + tstart = 0.0 + for i in drange(0, range, 0.1 * range): + for j in drange(0, range, 0.1 * range): + rk = RungeKutta(system, trajStart(i, j), tstart, h) + rk.solve(tend) + # draw the line + for tr in rk.Trajectory: + x, y = trajPlot(tr) + print(x, y) + print() + # draw the arrow + continue + l = (len(rk.Trajectory) - 1) / 3 + if l > 0 and 2 * l < len(rk.Trajectory): + p1 = rk.Trajectory[l] + p2 = rk.Trajectory[2 * l] + x1, y1 = trajPlot(p1) + x2, y2 = trajPlot(p2) + dx = -0.5 * (y2 - y1) # orthogonal to line + dy = 0.5 * (x2 - x1) # orthogonal to line + #l = math.sqrt(dx*dx + dy*dy) + #if abs(l) > 1e-3: + # l = 0.1 / l + # dx *= l + # dy *= l + print(x1 + dx, y1 + dy) + print(x2, y2) + print(x1 - dx, y1 - dy) + print() + +def singleTraj(system, trajStart, h=0.02, tend=1.0): + tstart = 0.0 + + # compute the trajectory + + rk = RungeKutta(system, trajStart, tstart, h) + rk.solve(tend) + + # print out trajectory + + for i in range(len(rk.Trajectory)): + tr = rk.Trajectory[i] + print(' '.join(["{:.5f}".format(t) for t in tr])) + +#phaseDiagram(sysSM, (lambda i, j: [0.354, 0.654, 1.278, 0.8 + 0.2 * i, 0.1 + 0.1 * j]), (lambda a: (a[4], a[5])), h=0.1, tend=math.log(10**17)) + +# initial conditions at M_Z +singleTraj(sysSM, [0.354, 0.654, 1.278, 0.983, 0.131], h=0.5, tend=math.log(10**17)) # true values -- cgit v1.2.3