Skip to content

Commit 90da791

Browse files
committed
tests/basics: Add test for calling a subclass of a native class.
Adding this test gets py/objtype.c to 100% coverage.
1 parent c0bcf00 commit 90da791

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# test calling a subclass of a native class that supports calling
2+
3+
# For this test we need a native class that can be subclassed (has make_new)
4+
# and is callable (has call). The only one available is machine.Signal, which
5+
# in turns needs PinBase.
6+
try:
7+
import umachine as machine
8+
except ImportError:
9+
import machine
10+
try:
11+
machine.PinBase
12+
machine.Signal
13+
except AttributeError:
14+
print("SKIP")
15+
raise SystemExit
16+
17+
class Pin(machine.PinBase):
18+
#def __init__(self):
19+
# self.v = 0
20+
21+
def value(self, v=None):
22+
return 42
23+
24+
class MySignal(machine.Signal):
25+
pass
26+
27+
s = MySignal(Pin())
28+
29+
# apply call to the subclass, which should call the native base
30+
print(s())
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
42

0 commit comments

Comments
 (0)