Skip to content

Commit

Permalink
Merge pull request #12 from pimoroni/patch-tests
Browse files Browse the repository at this point in the history
Udpate tests
  • Loading branch information
Gadgetoid committed Apr 27, 2021
2 parents 52583ce + c01f2fd commit df4439f
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 26 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python: [2.7, 3.6, 3.7, 3.8]
python: [2.7, 3.7, 3.8, 3.9]

steps:
- uses: actions/checkout@v2
Expand All @@ -33,5 +33,5 @@ jobs:
run: |
python -m pip install coveralls
coveralls --service=github
if: ${{ matrix.python == '3.8' }}
if: ${{ matrix.python == '3.9' }}

38 changes: 38 additions & 0 deletions library/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import sys
import mock
import pytest

@pytest.fixture(scope='function', autouse=False)
def GPIO():
"""Mock RPi.GPIO module."""

GPIO = mock.MagicMock()
# Fudge for Python < 37 (possibly earlier)
sys.modules['RPi'] = mock.Mock()
sys.modules['RPi'].GPIO = GPIO
sys.modules['RPi.GPIO'] = GPIO
yield GPIO
del sys.modules['RPi']
del sys.modules['RPi.GPIO']


@pytest.fixture(scope='function', autouse=False)
def spidev():
"""Mock Spidev module."""

spidev = mock.MagicMock()

sys.modules['spidev'] = spidev
yield spidev
del sys.modules['spidev']


@pytest.fixture(scope='function', autouse=False)
def numpy():
"""Mock numpy module."""

numpy = mock.MagicMock()

sys.modules['numpy'] = numpy
yield numpy
del sys.modules['numpy']
14 changes: 1 addition & 13 deletions library/tests/test_dimensions.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
import sys
import mock


def _mock():
sys.modules['numpy'] = mock.Mock()
sys.modules['spidev'] = mock.Mock()
sys.modules['RPi'] = mock.Mock()
sys.modules['RPi.GPIO'] = mock.Mock()


def test_240_240():
_mock()
def test_240_240(GPIO, spidev, numpy):
import ST7789
display = ST7789.ST7789(port=0, cs=0, dc=24, width=240, height=240, rotation=0)
assert display.width == 240
Expand Down
20 changes: 20 additions & 0 deletions library/tests/test_display.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import pytest

def test_display_pil_image(GPIO, spidev):
from PIL import Image
import ST7789
display = ST7789.ST7789(port=0, cs=0, dc=24)

image = Image.new("RGB", (display.width, display.width))
display.display(image)


def test_display_numpy_array(GPIO, spidev):
import numpy
import ST7789
display = ST7789.ST7789(port=0, cs=0, dc=24)

image = numpy.empty((display.width, display.height, 3))

with pytest.raises(AttributeError):
display.display(image)
11 changes: 1 addition & 10 deletions library/tests/test_setup.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
import sys
import mock


def test_setup():
sys.modules['numpy'] = mock.Mock()
sys.modules['spidev'] = mock.Mock()
sys.modules['RPi'] = mock.Mock()
sys.modules['RPi.GPIO'] = mock.Mock()

def test_setup(GPIO, spidev, numpy):
import ST7789
display = ST7789.ST7789(port=0, cs=0, dc=24)
del display
4 changes: 3 additions & 1 deletion library/tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py{27,36,37,38},qa
envlist = py{27,37,38,39},qa
skip_missing_interpreters = True

[testenv]
Expand All @@ -8,6 +8,8 @@ commands =
coverage run -m py.test -v -r wsx
coverage report
deps =
numpy
pillow
mock
pytest>=3.1
pytest-cov
Expand Down

0 comments on commit df4439f

Please sign in to comment.