summaryrefslogtreecommitdiffstatshomepage
path: root/tests/basics/fun_code.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/basics/fun_code.py')
-rw-r--r--tests/basics/fun_code.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/basics/fun_code.py b/tests/basics/fun_code.py
new file mode 100644
index 0000000000..59e1f7ec04
--- /dev/null
+++ b/tests/basics/fun_code.py
@@ -0,0 +1,36 @@
+# Test function.__code__ attribute.
+
+try:
+ (lambda: 0).__code__
+except AttributeError:
+ print("SKIP")
+ raise SystemExit
+
+
+def f():
+ return a
+
+
+ftype = type(f)
+
+# Test __code__ access and function constructor.
+code = f.__code__
+print(type(ftype(code, {})) is ftype)
+
+# Test instantiating multiple code's with different globals dicts.
+code = f.__code__
+f1 = ftype(code, {"a": 1})
+f2 = ftype(code, {"a": 2})
+print(f1(), f2())
+
+# Test bad first argument type.
+try:
+ ftype(None, {})
+except TypeError:
+ print("TypeError")
+
+# Test bad second argument type.
+try:
+ ftype(f.__code__, None)
+except TypeError:
+ print("TypeError")