From 36f79523abe8d79fec1cc7af41e8e96e8ceb2cc4 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 14 Dec 2017 12:25:30 +1100 Subject: [PATCH] tests: Add tests to improve coverage of py/objtype.c. --- tests/basics/class_inherit_mul.py | 5 +++++ tests/basics/class_super_multinherit.py | 16 ++++++++++++++++ tests/basics/sys_getsizeof.py | 15 +++++++++++++++ tests/misc/non_compliant.py | 15 +++++++++++++++ tests/misc/non_compliant.py.exp | 2 ++ 5 files changed, 53 insertions(+) create mode 100644 tests/basics/class_super_multinherit.py create mode 100644 tests/basics/sys_getsizeof.py diff --git a/tests/basics/class_inherit_mul.py b/tests/basics/class_inherit_mul.py index 23476132ba..4a43a7f410 100644 --- a/tests/basics/class_inherit_mul.py +++ b/tests/basics/class_inherit_mul.py @@ -1,3 +1,5 @@ +# test multiple inheritance of user classes + class A: def __init__(self, x): print('A init', x) @@ -30,6 +32,9 @@ class Sub(A, B): def g(self): print(self.x) +print(issubclass(Sub, A)) +print(issubclass(Sub, B)) + o = Sub() print(o.x) o.f() diff --git a/tests/basics/class_super_multinherit.py b/tests/basics/class_super_multinherit.py new file mode 100644 index 0000000000..642a73ce1a --- /dev/null +++ b/tests/basics/class_super_multinherit.py @@ -0,0 +1,16 @@ +# test super with multiple inheritance + +class A: + def foo(self): + print('A.foo') + +class B: + def foo(self): + print('B.foo') + +class C(A, B): + def foo(self): + print('C.foo') + super().foo() + +C().foo() diff --git a/tests/basics/sys_getsizeof.py b/tests/basics/sys_getsizeof.py new file mode 100644 index 0000000000..d16eb1561a --- /dev/null +++ b/tests/basics/sys_getsizeof.py @@ -0,0 +1,15 @@ +# test sys.getsizeof() function + +import sys +try: + sys.getsizeof +except AttributeError: + print('SKIP') + raise SystemExit + +print(sys.getsizeof([1, 2]) >= 2) +print(sys.getsizeof({1: 2}) >= 2) + +class A: + pass +print(sys.getsizeof(A()) > 0) diff --git a/tests/misc/non_compliant.py b/tests/misc/non_compliant.py index 152633c3b7..31129f0759 100644 --- a/tests/misc/non_compliant.py +++ b/tests/misc/non_compliant.py @@ -124,3 +124,18 @@ try: f.x = 1 except AttributeError: print('AttributeError') + +# can't call a function type (ie make new instances of a function) +try: + type(f)() +except TypeError: + print('TypeError') + +# test when object explicitly listed at not-last position in parent tuple +# this is not compliant with CPython because of illegal MRO +class A: + def foo(self): + print('A.foo') +class B(object, A): + pass +B().foo() diff --git a/tests/misc/non_compliant.py.exp b/tests/misc/non_compliant.py.exp index 9c157fd5bd..061e3fcc87 100644 --- a/tests/misc/non_compliant.py.exp +++ b/tests/misc/non_compliant.py.exp @@ -18,3 +18,5 @@ b'\x01\x02' b'\x01\x00' NotImplementedError AttributeError +TypeError +A.foo