From ecc635d551aa8fa5e02d2cb810b929ec92c54c3f Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 2 Mar 2017 16:09:16 +1100 Subject: [PATCH] tests/extmod: Add test for machine.Signal class. --- tests/extmod/machine_signal.py | 40 ++++++++++++++++++++++++++++++ tests/extmod/machine_signal.py.exp | 4 +++ 2 files changed, 44 insertions(+) create mode 100644 tests/extmod/machine_signal.py create mode 100644 tests/extmod/machine_signal.py.exp diff --git a/tests/extmod/machine_signal.py b/tests/extmod/machine_signal.py new file mode 100644 index 0000000000..401533f230 --- /dev/null +++ b/tests/extmod/machine_signal.py @@ -0,0 +1,40 @@ +# test machine.Signal class + +try: + import umachine as machine +except ImportError: + import machine +try: + machine.PinBase + machine.Signal +except AttributeError: + print("SKIP") + import sys + sys.exit() + +class Pin(machine.PinBase): + def __init__(self): + self.v = 0 + + def value(self, v=None): + if v is None: + return self.v + else: + self.v = int(v) + + +# test non-inverted +p = Pin() +s = machine.Signal(p) +s.value(0) +print(p.value(), s.value()) +s.value(1) +print(p.value(), s.value()) + +# test inverted, and using on/off methods +p = Pin() +s = machine.Signal(p, inverted=True) +s.off() +print(p.value(), s.value()) +s.on() +print(p.value(), s.value()) diff --git a/tests/extmod/machine_signal.py.exp b/tests/extmod/machine_signal.py.exp new file mode 100644 index 0000000000..7e9dd67966 --- /dev/null +++ b/tests/extmod/machine_signal.py.exp @@ -0,0 +1,4 @@ +0 0 +1 1 +1 0 +0 1