2020-12-05 00:16:07 +01:00
|
|
|
"""
|
2023-01-11 22:24:39 +01:00
|
|
|
inkycal_image unittest
|
2020-12-05 00:16:07 +01:00
|
|
|
"""
|
2023-01-11 22:24:39 +01:00
|
|
|
import logging
|
2020-11-23 22:36:04 +01:00
|
|
|
import unittest
|
2022-04-14 05:53:10 +02:00
|
|
|
|
|
|
|
import requests
|
|
|
|
from PIL import Image
|
|
|
|
|
2020-11-23 22:36:04 +01:00
|
|
|
from inkycal.modules import Inkyimage as Module
|
2023-01-11 22:24:39 +01:00
|
|
|
from inkycal.modules.inky_image import Inkyimage
|
2023-11-21 15:18:19 +01:00
|
|
|
from tests import Config
|
|
|
|
|
2023-01-11 22:24:39 +01:00
|
|
|
preview = Inkyimage.preview
|
|
|
|
merge = Inkyimage.merge
|
2020-12-05 00:16:07 +01:00
|
|
|
|
2024-02-10 22:43:57 +01:00
|
|
|
url ="https://raw.githubusercontent.com/aceinnolab/Inkycal/assets/tests/Inkycal_cover.png"
|
2022-04-14 05:53:10 +02:00
|
|
|
|
|
|
|
im = Image.open(requests.get(url, stream=True).raw)
|
|
|
|
im.save("test.png", "PNG")
|
|
|
|
test_path = "test.png"
|
2020-11-23 22:36:04 +01:00
|
|
|
|
2023-11-21 15:18:19 +01:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
|
|
|
2020-11-23 22:36:04 +01:00
|
|
|
tests = [
|
2022-04-02 01:30:17 +02:00
|
|
|
{
|
|
|
|
"name": "Inkyimage",
|
|
|
|
"config": {
|
2023-12-14 01:51:10 +01:00
|
|
|
"size": [800, 600],
|
2022-04-02 01:30:17 +02:00
|
|
|
"path": test_path,
|
2023-12-14 01:51:10 +01:00
|
|
|
"palette": "16gray",
|
2022-04-02 01:30:17 +02:00
|
|
|
"autoflip": True,
|
|
|
|
"orientation": "vertical",
|
|
|
|
"padding_x": 10, "padding_y": 10, "fontsize": 12, "language": "en"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "Inkyimage",
|
|
|
|
"config": {
|
|
|
|
"size": [800, 500],
|
|
|
|
"path": test_path,
|
|
|
|
"palette": "bwy",
|
|
|
|
"autoflip": True,
|
|
|
|
"orientation": "vertical",
|
|
|
|
"padding_x": 10, "padding_y": 10, "fontsize": 12, "language": "en"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "Inkyimage",
|
|
|
|
"config": {
|
|
|
|
"size": [400, 100],
|
|
|
|
"path": test_path,
|
|
|
|
"palette": "bw",
|
|
|
|
"autoflip": False,
|
|
|
|
"orientation": "vertical",
|
|
|
|
"padding_x": 10, "padding_y": 10, "fontsize": 12, "language": "en"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "Inkyimage",
|
|
|
|
"config": {
|
|
|
|
"size": [400, 100],
|
|
|
|
"path": test_path,
|
|
|
|
"palette": "bwr",
|
|
|
|
"autoflip": True,
|
|
|
|
"orientation": "vertical",
|
|
|
|
"padding_x": 10, "padding_y": 10, "fontsize": 12, "language": "en"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "Inkyimage",
|
|
|
|
"config": {
|
|
|
|
"size": [400, 100],
|
|
|
|
"path": test_path,
|
|
|
|
"palette": "bwy",
|
|
|
|
"autoflip": True,
|
|
|
|
"orientation": "horizontal",
|
|
|
|
"padding_x": 10, "padding_y": 10, "fontsize": 12, "language": "en"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "Inkyimage",
|
|
|
|
"config": {
|
|
|
|
"size": [500, 800],
|
|
|
|
"path": test_path,
|
|
|
|
"palette": "bw",
|
|
|
|
"autoflip": True,
|
|
|
|
"orientation": "vertical",
|
|
|
|
"padding_x": 0, "padding_y": 0, "fontsize": 12, "language": "en"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "Inkyimage",
|
|
|
|
"config": {
|
|
|
|
"size": [500, 800],
|
|
|
|
"path": test_path,
|
|
|
|
"palette": "bwr",
|
|
|
|
"autoflip": True,
|
|
|
|
"orientation": "vertical",
|
|
|
|
"padding_x": 20, "padding_y": 20, "fontsize": 12, "language": "en"
|
|
|
|
}
|
|
|
|
},
|
2020-11-23 22:36:04 +01:00
|
|
|
]
|
|
|
|
|
2022-04-02 01:30:17 +02:00
|
|
|
|
2023-11-21 15:18:19 +01:00
|
|
|
class TestInkyImage(unittest.TestCase):
|
2020-11-23 22:36:04 +01:00
|
|
|
|
2022-04-02 01:30:17 +02:00
|
|
|
def test_generate_image(self):
|
|
|
|
for test in tests:
|
2023-11-21 15:18:19 +01:00
|
|
|
logger.info(f'test {tests.index(test) + 1} generating image..')
|
2022-04-02 01:30:17 +02:00
|
|
|
module = Module(test)
|
|
|
|
im_black, im_colour = module.generate_image()
|
2023-11-21 15:18:19 +01:00
|
|
|
logger.info('OK')
|
2023-01-11 22:24:39 +01:00
|
|
|
if Config.USE_PREVIEW:
|
2022-04-02 01:30:17 +02:00
|
|
|
preview(merge(im_black, im_colour))
|