2019-08-14 15:11:25 +01:00
|
|
|
print("Now comes the language constructions tests.")
|
|
|
|
|
2023-02-02 00:51:48 +00:00
|
|
|
|
2019-08-14 15:11:25 +01:00
|
|
|
# function
|
|
|
|
def test_func():
|
|
|
|
def test_sub_func():
|
|
|
|
print("test_function")
|
|
|
|
|
|
|
|
test_sub_func()
|
|
|
|
|
2020-03-23 02:26:08 +00:00
|
|
|
|
2019-08-14 15:11:25 +01:00
|
|
|
# closure
|
|
|
|
def test_closure(msg):
|
|
|
|
def make_closure():
|
|
|
|
print(msg)
|
|
|
|
|
|
|
|
return make_closure
|
|
|
|
|
2020-03-23 02:26:08 +00:00
|
|
|
|
2019-08-14 15:11:25 +01:00
|
|
|
# exception
|
|
|
|
def test_exception():
|
|
|
|
try:
|
|
|
|
raise Exception("test_exception")
|
|
|
|
|
|
|
|
except Exception:
|
|
|
|
pass
|
2020-03-23 02:26:08 +00:00
|
|
|
|
2019-08-14 15:11:25 +01:00
|
|
|
finally:
|
|
|
|
pass
|
|
|
|
|
2020-03-23 02:26:08 +00:00
|
|
|
|
2019-08-14 15:11:25 +01:00
|
|
|
# listcomp
|
|
|
|
def test_listcomp():
|
|
|
|
print("test_listcomp", [x for x in range(3)])
|
|
|
|
|
2020-03-23 02:26:08 +00:00
|
|
|
|
2019-08-14 15:11:25 +01:00
|
|
|
# lambda
|
|
|
|
def test_lambda():
|
|
|
|
func_obj_1 = lambda a, b: a + b
|
|
|
|
print(func_obj_1(10, 20))
|
|
|
|
|
2020-03-23 02:26:08 +00:00
|
|
|
|
2019-08-14 15:11:25 +01:00
|
|
|
# import
|
|
|
|
def test_import():
|
2020-12-15 10:54:34 +00:00
|
|
|
from sys_settrace_subdir import sys_settrace_importme
|
2020-03-23 02:26:08 +00:00
|
|
|
|
2020-12-15 10:54:34 +00:00
|
|
|
sys_settrace_importme.dummy()
|
|
|
|
sys_settrace_importme.saysomething()
|
2019-08-14 15:11:25 +01:00
|
|
|
|
2020-03-23 02:26:08 +00:00
|
|
|
|
2019-08-14 15:11:25 +01:00
|
|
|
# class
|
|
|
|
class TLClass:
|
|
|
|
def method():
|
|
|
|
pass
|
2020-03-23 02:26:08 +00:00
|
|
|
|
2019-08-14 15:11:25 +01:00
|
|
|
pass
|
|
|
|
|
2020-03-23 02:26:08 +00:00
|
|
|
|
2019-08-14 15:11:25 +01:00
|
|
|
def test_class():
|
|
|
|
class TestClass:
|
|
|
|
__anynum = -9
|
2020-03-23 02:26:08 +00:00
|
|
|
|
2019-08-14 15:11:25 +01:00
|
|
|
def method(self):
|
|
|
|
print("test_class_method")
|
|
|
|
self.__anynum += 1
|
2020-03-23 02:26:08 +00:00
|
|
|
|
2019-08-14 15:11:25 +01:00
|
|
|
def prprty_getter(self):
|
|
|
|
return self.__anynum
|
2020-03-23 02:26:08 +00:00
|
|
|
|
2019-08-14 15:11:25 +01:00
|
|
|
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()
|
|
|
|
|
2020-03-23 02:26:08 +00:00
|
|
|
|
2019-08-14 15:11:25 +01:00
|
|
|
print("And it's done!")
|