From 90da791a08bee6e4d9706dd80f9c15f22ff4c50f Mon Sep 17 00:00:00 2001 From: Damien George Date: Sat, 24 Feb 2018 23:13:42 +1100 Subject: [PATCH] tests/basics: Add test for calling a subclass of a native class. Adding this test gets py/objtype.c to 100% coverage. --- tests/basics/subclass_native_call.py | 30 ++++++++++++++++++++++++ tests/basics/subclass_native_call.py.exp | 1 + 2 files changed, 31 insertions(+) create mode 100644 tests/basics/subclass_native_call.py create mode 100644 tests/basics/subclass_native_call.py.exp diff --git a/tests/basics/subclass_native_call.py b/tests/basics/subclass_native_call.py new file mode 100644 index 0000000000..c645575225 --- /dev/null +++ b/tests/basics/subclass_native_call.py @@ -0,0 +1,30 @@ +# test calling a subclass of a native class that supports calling + +# For this test we need a native class that can be subclassed (has make_new) +# and is callable (has call). The only one available is machine.Signal, which +# in turns needs PinBase. +try: + import umachine as machine +except ImportError: + import machine +try: + machine.PinBase + machine.Signal +except AttributeError: + print("SKIP") + raise SystemExit + +class Pin(machine.PinBase): + #def __init__(self): + # self.v = 0 + + def value(self, v=None): + return 42 + +class MySignal(machine.Signal): + pass + +s = MySignal(Pin()) + +# apply call to the subclass, which should call the native base +print(s()) diff --git a/tests/basics/subclass_native_call.py.exp b/tests/basics/subclass_native_call.py.exp new file mode 100644 index 0000000000..d81cc0710e --- /dev/null +++ b/tests/basics/subclass_native_call.py.exp @@ -0,0 +1 @@ +42