mirror of
https://github.com/thearn/Python-Arduino-Command-API.git
synced 2026-01-12 16:08:45 -05:00
updated tests
This commit is contained in:
10
README.md
10
README.md
@@ -49,6 +49,16 @@ bluetooth, xbee, etc + associated drivers)
|
||||
For a collection of examples, see `examples.py`. This file contains methods which replicate
|
||||
the functionality of many Arduino demo sketches.
|
||||
|
||||
## Testing:
|
||||
The `tests` directory contains some basic tests for the library. Extensive coverage is a bit difficult, since a positive test involves actually
|
||||
connecting and issuing commands to a live Arduino, hosting any hardware
|
||||
required to test a particular function. But a core of basic communication tests
|
||||
should at least be maintained here.
|
||||
|
||||
After installation, the tests can be run directly:
|
||||
```bash
|
||||
$ python tests/test_main.py
|
||||
```
|
||||
## Classes
|
||||
- `Arduino(baud)` - Set up communication with currently connected and powered
|
||||
Arduino.
|
||||
|
||||
@@ -1,13 +1,40 @@
|
||||
import unittest
|
||||
import time
|
||||
from Arduino import Arduino
|
||||
|
||||
"""
|
||||
A collection of some basic tests for the Arduino library.
|
||||
|
||||
class TestConnect(unittest.TestCase):
|
||||
Extensive coverage is a bit difficult, since a positive test involves actually
|
||||
connecting and issuing commands to a live Arduino, hosting any hardware
|
||||
required to test a particular function. But a core of basic communication tests
|
||||
should at least be maintained here.
|
||||
"""
|
||||
|
||||
|
||||
class TestBasics(unittest.TestCase):
|
||||
_ = raw_input('Plug in Arduino board w/LED at pin 13, then press enter')
|
||||
board = Arduino('9600')
|
||||
|
||||
def test_find(self):
|
||||
board = Arduino('9600')
|
||||
self.assertIsNotNone(board.port)
|
||||
"""
|
||||
Tests auto-connection/board detection
|
||||
"""
|
||||
self.assertIsNotNone(self.board.port)
|
||||
|
||||
def test_blink(self):
|
||||
"""
|
||||
Tests digital pin functionality
|
||||
"""
|
||||
led_pin = 13
|
||||
board.digitalWrite(led_pin, "LOW")
|
||||
state = board.digitalRead(led_pin)
|
||||
self.assertEqual(state, 0)
|
||||
time.sleep(1)
|
||||
board.digitalWrite(led_pin, "HIGH")
|
||||
state = board.digitalRead(led_pin)
|
||||
self.assertEqual(state, 1)
|
||||
board.digitalWrite(led_pin, "LOW")
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user