Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit Test Framework #2

Open
cefn opened this issue Feb 17, 2018 · 2 comments
Open

Unit Test Framework #2

cefn opened this issue Feb 17, 2018 · 2 comments

Comments

@cefn
Copy link
Owner

cefn commented Feb 17, 2018

Worth coming up with a strategy for unit testing and Testcases for bug triage structured around TDD.

For now, using unittest from https://github.com/micropython/micropython-lib/blob/cfa1b9cce0c93a3115bbff3886c9bbcddd9e8047/unittest/unittest.py and populating a testing folder in the root. In the end these will be separated to avoid cluttering the distributed files.

MicroPython v1.9.3-8-g63826ac5c on 2017-11-01; ESP module with ESP8266
Type "help()" for more information.
>>> from testing.platform.all import main
>>> main()
test_iteritems (TestEnum) ... ok
test_repr (TestEnum) ... ok
test_str (TestEnum) ... ok
Ran 3 tests

OK
test_pins_exist (TestMicrocontrollerModule) ... ok
Ran 1 tests

OK

@cefn
Copy link
Owner Author

cefn commented Feb 19, 2018

As of 3b2fc26 the approach is now functioning and successfully testing LED control and Button push detection on Feather Huzzah running Micropython.

Here is an example log...


>>> import testing
>>> testing.main()
Run suite testing.implementation.all.digitalio (Y/n)?
Suite begin: testing.implementation.all.digitalio
test_switch_to_output (TestDigitalInOut) ... ok
test_switch_to_input (TestDigitalInOut) ... ok
test_default (TestDigitalInOut) ... ok
test_button_pull_down (TestDigitalInOutInteractive) ...
digitalio.Pull.DOWN unsupported on feather_huzzah
 ok
test_button_pull_up (TestDigitalInOutInteractive) ...
Is Button wired to mcp.Pin.GPIO4 to GND (Y/n)?
Waiting 60 sec until button pressed (CTRL+C give up)
 ok
test_blink (TestDigitalInOutInteractive) ...
Is LED lit (Y/n)?
Winking LED...
Did LED wink twice (Y/n)?
 ok
Ran 6 tests

OK
Suite end: testing.implementation.all.digitalio
Run suite testing.implementation.micropython.digitalio (Y/n)?
Suite begin: testing.implementation.micropython.digitalio
test_context_manager (TestDigitalInOut) ... ok
Ran 1 tests

OK
Suite end: testing.implementation.micropython.digitalio
>>> 

@ladyada
Copy link

ladyada commented Feb 19, 2018

fyi used this code for testing GPIO input & output

from board import pyboard as board
from digitalio import DigitalInOut, Direction, Pull

print("Hello!")
print(dir(board))

led = DigitalInOut(board.LED_YELLOW)
led.direction = Direction.OUTPUT
 
button = DigitalInOut(board.SW)
button.direction = Direction.INPUT
button.pull = Pull.UP
 
while True:
    led.value = not button.value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants