summaryrefslogtreecommitdiff
path: root/tests/basics/subclass_native_call.py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-02-24 23:13:42 +1100
committerDamien George <damien.p.george@gmail.com>2018-02-24 23:13:42 +1100
commit90da791a08bee6e4d9706dd80f9c15f22ff4c50f (patch)
tree6e6948652e34aca456f75f072fbb452d20049351 /tests/basics/subclass_native_call.py
parentc0bcf00ed100181a532240d904395de11addcd33 (diff)
tests/basics: Add test for calling a subclass of a native class.
Adding this test gets py/objtype.c to 100% coverage.
Diffstat (limited to 'tests/basics/subclass_native_call.py')
-rw-r--r--tests/basics/subclass_native_call.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/basics/subclass_native_call.py b/tests/basics/subclass_native_call.py
new file mode 100644
index 000000000..c64557522
--- /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())