-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactors and adds tests for display
- Loading branch information
Showing
5 changed files
with
81 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +0,0 @@ | ||
import os | ||
import sys | ||
|
||
picdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "pic") | ||
libdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "lib") | ||
if os.path.exists(libdir): | ||
sys.path.append(libdir) | ||
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
Binary file not shown.
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,26 +1,43 @@ | ||
import unittest | ||
import os | ||
from lib import parse_api_result | ||
from lib import create_to_display_image, parse_api_result, font | ||
from lib.waveshare_epd import epd4in2 | ||
from PIL import Image, ImageChops | ||
|
||
TEST_RESULT_FILENAME = "api_result_test.tsv" | ||
TEST_IMAGE_FILENAME = "test_display.bmp" | ||
|
||
test_result_filepath = os.path.join( | ||
os.path.dirname(os.path.dirname(os.path.realpath(__file__))), | ||
"api_fetcher", | ||
TEST_RESULT_FILENAME, | ||
) | ||
|
||
class TestParse(unittest.TestCase): | ||
test_image_filepath = os.path.join( | ||
os.path.dirname(os.path.realpath(__file__)), TEST_IMAGE_FILENAME | ||
) | ||
|
||
|
||
class TestDisplayController(unittest.TestCase): | ||
def test_parse_result(self): | ||
test_result_filepath = os.path.join( | ||
os.path.dirname(os.path.dirname(os.path.realpath(__file__))), | ||
"api_fetcher", | ||
TEST_RESULT_FILENAME, | ||
) | ||
expected = [ | ||
"6 Gen..age 10:46+1", | ||
"3 Gra..tti 10:46+1", | ||
"9 Ver..urs 10:46", | ||
"6 Ver..age 10:47", | ||
"10 Gen..ive 10:47", | ||
"6 Gen..age 10:46+1", | ||
"3 Gra..tti 10:46+1", | ||
"9 Ver..urs 10:46", | ||
"6 Ver..age 10:47", | ||
"10 Gen..ive 10:47", | ||
] | ||
self.assertEqual(parse_api_result(test_result_filepath), expected) | ||
|
||
def test_generate_image(self): | ||
to_display = parse_api_result(test_result_filepath) | ||
epd = epd4in2.EPD() | ||
|
||
test_image = create_to_display_image(to_display, epd.width, epd.height, font) | ||
with Image.open(test_image_filepath) as expected_image: | ||
diff = ImageChops.difference(test_image, expected_image) | ||
self.assertIsNone(diff.getbbox()) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |