Skip to content

Commit

Permalink
Set up testing with pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrgn committed Jan 8, 2017
1 parent c4b1732 commit 8518ed5
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ docs/*.pdf

# Python
VIRTUAL/
.cache/
11 changes: 7 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
language: python
python:
- 2.7
- 3.4
- 2.7
- 3.2
- 3.3
- 3.4
- 3.5
install:
- pip install flake8
- pip install -r requirements-dev.txt
script:
- flake8 --max-line-length=99 --ignore=E126,E127,E128,C901 RPLCD/[a-zA-Z]*.py
- py.test -v
14 changes: 14 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ You can find the documentation here: https://readthedocs.org/projects/rplcd/
Testing
=======

Test Scripts
------------

To test your 20x4 display, please run the ``test_20x4.py`` script and
confirm/verify each step with the enter key. If you don't use the standard
wiring, make sure to add your pin numbers to the ``CharLCD`` constructor in
Expand All @@ -96,6 +99,17 @@ wiring, make sure to add your pin numbers to the ``CharLCD`` constructor in
To test a 16x2 display, proceed as explained above, but use the ``test_16x2.py``
script instead.

Unit Tests
----------

There are also unit tests. First, install dependencies:

pip install -U -r requirements-dev.txt

Then run the tests:

py.test -v


Coding Guidelines
=================
Expand Down
1 change: 1 addition & 0 deletions RPLCD/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from .contextmanagers import cursor, cleared
from .gpio import CharLCD as GpioCharLCD


class CharLCD(GpioCharLCD):
def __init__(self, *args, **kwargs):
warnings.warn("Using RPLCD.CharLCD directly is deprecated. " +
Expand Down
12 changes: 12 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[pytest]
addopts = --pep8 --tb=short
python_paths = ..
python_files = tests/test_*.py
pep8ignore =
*.py E126 E127 E128
*/tests/* ALL
docs/* ALL
setup.py ALL
test_16x2.py ALL
test_20x4.py ALL
pep8maxlinelength = 99
4 changes: 4 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pytest==3.0.5
pytest-mock==1.5.0
pytest-pep8==1.0.6
pytest-pythonpath==0.7.1
11 changes: 11 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import mock


# Mock RPi.GPIO module (https://m.reddit.com/r/Python/comments/5eddp5/mock_testing_rpigpio/)
MockRPi = mock.MagicMock()
modules = {
'RPi': MockRPi,
'RPi.GPIO': MockRPi.GPIO,
}
patcher = mock.patch.dict('sys.modules', modules)
patcher.start()

0 comments on commit 8518ed5

Please sign in to comment.