updated tests

This commit is contained in:
Tristan Hearn
2013-05-11 20:25:03 -04:00
parent 0f35e09fc1
commit eaf1783d7f
2 changed files with 40 additions and 3 deletions

View File

@@ -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.

View File

@@ -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()