-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from pimoroni/patch-tests
Udpate tests
- Loading branch information
Showing
6 changed files
with
65 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters