diff --git a/README.md b/README.md index 7bab802..274c07d 100644 --- a/README.md +++ b/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. diff --git a/tests/test_main.py b/tests/test_main.py index 23fc376..54a0750 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -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()