diff options
| author | Milan Rossa | 2019-08-14 16:11:25 +0200 |
|---|---|---|
| committer | Damien George | 2019-08-30 16:48:22 +1000 |
| commit | 498e35219e1f54243ff6d650781c525e20cad9b1 (patch) | |
| tree | d028a0679913355853958a0a5ddc9f09796b6b56 /tests/misc/sys_settrace_subdir | |
| parent | 310b3d1b81d561e19d719acd89ee47b759e3795c (diff) | |
tests: Add tests for sys.settrace feature.
Diffstat (limited to 'tests/misc/sys_settrace_subdir')
| -rw-r--r-- | tests/misc/sys_settrace_subdir/trace_generic.py | 82 | ||||
| -rw-r--r-- | tests/misc/sys_settrace_subdir/trace_importme.py | 24 |
2 files changed, 106 insertions, 0 deletions
diff --git a/tests/misc/sys_settrace_subdir/trace_generic.py b/tests/misc/sys_settrace_subdir/trace_generic.py new file mode 100644 index 000000000..3239a019c --- /dev/null +++ b/tests/misc/sys_settrace_subdir/trace_generic.py @@ -0,0 +1,82 @@ +print("Now comes the language constructions tests.") + +# function +def test_func(): + def test_sub_func(): + print("test_function") + + test_sub_func() + +# closure +def test_closure(msg): + + def make_closure(): + print(msg) + + return make_closure + +# exception +def test_exception(): + try: + raise Exception("test_exception") + + except Exception: + pass + + finally: + pass + +# listcomp +def test_listcomp(): + print("test_listcomp", [x for x in range(3)]) + +# lambda +def test_lambda(): + func_obj_1 = lambda a, b: a + b + print(func_obj_1(10, 20)) + +# import +def test_import(): + from sys_settrace_subdir import trace_importme + trace_importme.dummy() + trace_importme.saysomething() + +# class +class TLClass(): + def method(): + pass + pass + +def test_class(): + class TestClass: + __anynum = -9 + def method(self): + print("test_class_method") + self.__anynum += 1 + + def prprty_getter(self): + return self.__anynum + + def prprty_setter(self, what): + self.__anynum = what + + prprty = property(prprty_getter, prprty_setter) + + cls = TestClass() + cls.method() + print("test_class_property", cls.prprty) + cls.prprty = 12 + print("test_class_property", cls.prprty) + + +def run_tests(): + test_func() + test_closure_inst = test_closure("test_closure") + test_closure_inst() + test_exception() + test_listcomp() + test_lambda() + test_class() + test_import() + +print("And it's done!") diff --git a/tests/misc/sys_settrace_subdir/trace_importme.py b/tests/misc/sys_settrace_subdir/trace_importme.py new file mode 100644 index 000000000..0ff7c6d5b --- /dev/null +++ b/tests/misc/sys_settrace_subdir/trace_importme.py @@ -0,0 +1,24 @@ +print("Yep, I got imported.") + +try: + x = const(1) +except NameError: + print('const not defined') + +const = lambda x: x + +_CNT01 = "CONST01" +_CNT02 = const(123) +A123 = const(123) +a123 = const(123) + +def dummy(): + return False + +def saysomething(): + print("There, I said it.") + +def neverexecuted(): + print("Never got here!") + +print("Yep, got here") |
