tests best practices
This commit is contained in:
1
tests/__init__.py
Normal file
1
tests/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .config import Config
|
35
tests/config.py
Normal file
35
tests/config.py
Normal file
@@ -0,0 +1,35 @@
|
||||
"""
|
||||
Tests config
|
||||
"""
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
|
||||
# relative import
|
||||
basedir = os.path.abspath(os.path.dirname(__file__))
|
||||
|
||||
# load config from corresponding file
|
||||
load_dotenv(os.path.join(basedir, '.env'))
|
||||
|
||||
|
||||
class Config:
|
||||
get = os.environ.get
|
||||
|
||||
# show generated images via preview?
|
||||
USE_PREVIEW = False
|
||||
|
||||
# ical_parser_test
|
||||
OPENWEATHERMAP_API_KEY = get("OPENWEATHERMAP_API_KEY")
|
||||
TEST_ICAL_URL = get("TEST_ICAL_URL")
|
||||
|
||||
# inkycal_agenda_test & inkycal_calendar_test
|
||||
SAMPLE_ICAL_URL = get("SAMPLE_ICAL_URL")
|
||||
|
||||
# inkycal_todoist_test
|
||||
TODOIST_API_KEY = get("TODOIST_API_KEY")
|
||||
|
||||
TEMP_PATH = f"{basedir}/tmp"
|
||||
|
||||
|
||||
|
||||
|
||||
|
49
tests/settings.json
Normal file
49
tests/settings.json
Normal file
@@ -0,0 +1,49 @@
|
||||
|
||||
{
|
||||
"model": "epd_7_in_5_v3_colour",
|
||||
"update_interval": 5,
|
||||
"orientation": 0,
|
||||
"info_section": true,
|
||||
"info_section_height": 70,
|
||||
"calibration_hours": [0, 12, 18],
|
||||
"border_around_modules": true,
|
||||
"modules": [
|
||||
{
|
||||
"position": 1,
|
||||
"name": "Jokes",
|
||||
"config": {
|
||||
"size": [528, 80],
|
||||
"padding_x": 10,"padding_y": 10,"fontsize": 14,"language": "en"
|
||||
}
|
||||
},
|
||||
{
|
||||
"position": 2,
|
||||
"name": "Calendar",
|
||||
"config": {
|
||||
"size": [
|
||||
528,
|
||||
343
|
||||
],
|
||||
"week_starts_on": "Monday",
|
||||
"show_events": true,
|
||||
"ical_urls": "https://www.officeholidays.com/ics-fed/usa",
|
||||
"ical_files": null,
|
||||
"date_format": "D MMM",
|
||||
"time_format": "HH:mm",
|
||||
"padding_x": 10,"padding_y": 10,"fontsize": 14,"language": "en"
|
||||
}
|
||||
},
|
||||
{
|
||||
"position": 3,
|
||||
"name": "Feeds",
|
||||
"config": {
|
||||
"size": [528,132],
|
||||
"feed_urls": "http://feeds.bbci.co.uk/news/world/rss.xml#",
|
||||
"shuffle_feeds": true,
|
||||
"padding_x": 10,"padding_y": 10,"fontsize": 14,"language": "en"
|
||||
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
50
tests/test_ical_parser.py
Executable file
50
tests/test_ical_parser.py
Executable file
@@ -0,0 +1,50 @@
|
||||
"""
|
||||
iCalendar parser test (ical_parser)
|
||||
"""
|
||||
import logging
|
||||
import os
|
||||
import unittest
|
||||
from urllib.request import urlopen
|
||||
|
||||
import arrow
|
||||
from inkycal.modules.ical_parser import iCalendar
|
||||
from tests import Config
|
||||
|
||||
ical = iCalendar()
|
||||
test_ical = Config.TEST_ICAL_URL
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
|
||||
class TestIcalendar(unittest.TestCase):
|
||||
|
||||
def test_load_url(self):
|
||||
logger.info('testing loading via URL...')
|
||||
ical.load_url(test_ical)
|
||||
logger.info('OK')
|
||||
|
||||
def test_get_events(self):
|
||||
logger.info('testing parsing of events...')
|
||||
ical.get_events(arrow.now(), arrow.now().shift(weeks=30))
|
||||
logger.info('OK')
|
||||
|
||||
def test_sorting(self):
|
||||
logger.info('testing sorting of events...')
|
||||
ical.sort()
|
||||
logger.info('OK')
|
||||
|
||||
def test_show_events(self):
|
||||
logger.info('testing if events can be shown...')
|
||||
ical.show_events()
|
||||
logger.info('OK')
|
||||
|
||||
def test_laod_from_file(self):
|
||||
logger.info('testing loading from file...')
|
||||
dummy = str(urlopen(test_ical, timeout=10).read().decode())
|
||||
with open('dummy.ical', mode="w", encoding="utf-8") as file:
|
||||
file.write(dummy)
|
||||
ical.load_from_file('dummy.ical')
|
||||
logger.info('OK')
|
||||
os.remove('dummy.ical')
|
||||
|
75
tests/test_inkycal_agenda.py
Executable file
75
tests/test_inkycal_agenda.py
Executable file
@@ -0,0 +1,75 @@
|
||||
"""
|
||||
inkycal_agenda unittest
|
||||
"""
|
||||
import logging
|
||||
import unittest
|
||||
|
||||
from inkycal.modules import Agenda
|
||||
from inkycal.modules.inky_image import Inkyimage
|
||||
from tests import Config
|
||||
|
||||
preview = Inkyimage.preview
|
||||
merge = Inkyimage.merge
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
sample_url = Config.SAMPLE_ICAL_URL
|
||||
|
||||
tests = [
|
||||
{
|
||||
"name": "Agenda",
|
||||
"config": {
|
||||
"size": [400, 200],
|
||||
"ical_urls": sample_url,
|
||||
"ical_files": None,
|
||||
"date_format": "ddd D MMM",
|
||||
"time_format": "HH:mm",
|
||||
"padding_x": 10,
|
||||
"padding_y": 10,
|
||||
"fontsize": 12,
|
||||
"language": "en"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Agenda",
|
||||
"config": {
|
||||
"size": [500, 800],
|
||||
"ical_urls": sample_url,
|
||||
"ical_files": None,
|
||||
"date_format": "ddd D MMM",
|
||||
"time_format": "HH:mm",
|
||||
"padding_x": 10,
|
||||
"padding_y": 10,
|
||||
"fontsize": 12,
|
||||
"language": "en"
|
||||
}
|
||||
},
|
||||
{
|
||||
"position": 1,
|
||||
"name": "Agenda",
|
||||
"config": {
|
||||
"size": [300, 800],
|
||||
"ical_urls": sample_url,
|
||||
"ical_files": None,
|
||||
"date_format": "ddd D MMM",
|
||||
"time_format": "HH:mm",
|
||||
"padding_x": 10,
|
||||
"padding_y": 10,
|
||||
"fontsize": 12,
|
||||
"language": "en"
|
||||
}
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
class TestAgenda(unittest.TestCase):
|
||||
|
||||
def test_generate_image(self):
|
||||
for test in tests:
|
||||
logger.info(f'test {tests.index(test) + 1} generating image..')
|
||||
module = Agenda(test)
|
||||
im_black, im_colour = module.generate_image()
|
||||
logger.info('OK')
|
||||
if Config.USE_PREVIEW:
|
||||
preview(merge(im_black, im_colour))
|
80
tests/test_inkycal_calendar.py
Executable file
80
tests/test_inkycal_calendar.py
Executable file
@@ -0,0 +1,80 @@
|
||||
"""
|
||||
inkycal_calendar unittest
|
||||
"""
|
||||
import logging
|
||||
import unittest
|
||||
|
||||
from inkycal.modules import Calendar
|
||||
from inkycal.modules.inky_image import Inkyimage
|
||||
from tests import Config
|
||||
|
||||
preview = Inkyimage.preview
|
||||
merge = Inkyimage.merge
|
||||
|
||||
sample_url = Config.SAMPLE_ICAL_URL
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
tests = [
|
||||
{
|
||||
"name": "Calendar",
|
||||
"config": {
|
||||
"size": [500, 500],
|
||||
"week_starts_on": "Monday",
|
||||
"show_events": True,
|
||||
"ical_urls": sample_url,
|
||||
"ical_files": None,
|
||||
"date_format": "D MMM", "time_format": "HH:mm",
|
||||
"padding_x": 10, "padding_y": 10, "fontsize": 12, "language": "en"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Calendar",
|
||||
"config": {
|
||||
"size": [400, 800],
|
||||
"week_starts_on": "Sunday",
|
||||
"show_events": True,
|
||||
"ical_urls": sample_url,
|
||||
"ical_files": None,
|
||||
"date_format": "D MMM", "time_format": "HH:mm",
|
||||
"padding_x": 10, "padding_y": 10, "fontsize": 12, "language": "en"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Calendar",
|
||||
"config": {
|
||||
"size": [400, 800],
|
||||
"week_starts_on": "Monday",
|
||||
"show_events": False,
|
||||
"ical_urls": sample_url,
|
||||
"ical_files": None,
|
||||
"date_format": "D MMM", "time_format": "HH:mm",
|
||||
"padding_x": 10, "padding_y": 10, "fontsize": 12, "language": "en"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Calendar",
|
||||
"config": {
|
||||
"size": [400, 800],
|
||||
"week_starts_on": "Monday",
|
||||
"show_events": True,
|
||||
"ical_urls": None,
|
||||
"ical_files": None,
|
||||
"date_format": "D MMM", "time_format": "HH:mm",
|
||||
"padding_x": 10, "padding_y": 10, "fontsize": 12, "language": "en"
|
||||
}
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
class TestCalendar(unittest.TestCase):
|
||||
|
||||
def test_generate_image(self):
|
||||
for test in tests:
|
||||
print(f'test {tests.index(test) + 1} generating image..', end="")
|
||||
module = Calendar(test)
|
||||
im_black, im_colour = module.generate_image()
|
||||
print('OK')
|
||||
if Config.USE_PREVIEW:
|
||||
preview(merge(im_black, im_colour))
|
57
tests/test_inkycal_feeds.py
Executable file
57
tests/test_inkycal_feeds.py
Executable file
@@ -0,0 +1,57 @@
|
||||
"""
|
||||
inkycal_feeds unittest
|
||||
"""
|
||||
import logging
|
||||
import unittest
|
||||
from inkycal.modules import Feeds
|
||||
from inkycal.modules.inky_image import Inkyimage
|
||||
from tests import Config
|
||||
|
||||
preview = Inkyimage.preview
|
||||
merge = Inkyimage.merge
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
tests = [
|
||||
{
|
||||
"name": "Feeds",
|
||||
"config": {
|
||||
"size": [400, 200],
|
||||
"feed_urls": "http://feeds.bbci.co.uk/news/world/rss.xml#",
|
||||
"shuffle_feeds": True,
|
||||
"padding_x": 10, "padding_y": 10, "fontsize": 12, "language": "en"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Feeds",
|
||||
"config": {
|
||||
"size": [400, 800],
|
||||
"feed_urls": "https://www.foodandco.fi/modules/MenuRss/MenuRss/CurrentDay?costNumber=3003&language=en",
|
||||
"shuffle_feeds": False,
|
||||
"padding_x": 10, "padding_y": 10, "fontsize": 14, "language": "en"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Feeds",
|
||||
"config": {
|
||||
"size": [400, 100],
|
||||
"feed_urls": "https://www.anekdot.ru/rss/export_top.xml",
|
||||
"shuffle_feeds": False,
|
||||
"padding_x": 10, "padding_y": 10, "fontsize": 12, "language": "en"
|
||||
}
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
class TestFeeds(unittest.TestCase):
|
||||
|
||||
def test_generate_image(self):
|
||||
for test in tests:
|
||||
logger.info(f'test {tests.index(test) + 1} generating image..')
|
||||
module = Feeds(test)
|
||||
im_black, im_colour = module.generate_image()
|
||||
logger.info('OK')
|
||||
if Config.USE_PREVIEW:
|
||||
preview(merge(im_black, im_colour))
|
||||
|
116
tests/test_inkycal_image.py
Executable file
116
tests/test_inkycal_image.py
Executable file
@@ -0,0 +1,116 @@
|
||||
"""
|
||||
inkycal_image unittest
|
||||
"""
|
||||
import logging
|
||||
import unittest
|
||||
|
||||
import requests
|
||||
from PIL import Image
|
||||
|
||||
from inkycal.modules import Inkyimage as Module
|
||||
from inkycal.modules.inky_image import Inkyimage
|
||||
from tests import Config
|
||||
|
||||
preview = Inkyimage.preview
|
||||
merge = Inkyimage.merge
|
||||
|
||||
url = "https://github.com/aceinnolab/Inkycal/raw/assets/Repo/coffee.png"
|
||||
|
||||
im = Image.open(requests.get(url, stream=True).raw)
|
||||
im.save("test.png", "PNG")
|
||||
test_path = "test.png"
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
tests = [
|
||||
{
|
||||
"name": "Inkyimage",
|
||||
"config": {
|
||||
"size": [400, 200],
|
||||
"path": test_path,
|
||||
"palette": "bwr",
|
||||
"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"
|
||||
}
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
class TestInkyImage(unittest.TestCase):
|
||||
|
||||
def test_generate_image(self):
|
||||
for test in tests:
|
||||
logger.info(f'test {tests.index(test) + 1} generating image..')
|
||||
module = Module(test)
|
||||
im_black, im_colour = module.generate_image()
|
||||
logger.info('OK')
|
||||
if Config.USE_PREVIEW:
|
||||
preview(merge(im_black, im_colour))
|
60
tests/test_inkycal_jokes.py
Executable file
60
tests/test_inkycal_jokes.py
Executable file
@@ -0,0 +1,60 @@
|
||||
"""
|
||||
inkycal_jokes unittest
|
||||
"""
|
||||
import logging
|
||||
import unittest
|
||||
|
||||
from inkycal.modules import Jokes
|
||||
from inkycal.modules.inky_image import Inkyimage
|
||||
from tests import Config
|
||||
|
||||
preview = Inkyimage.preview
|
||||
merge = Inkyimage.merge
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
tests = [
|
||||
{
|
||||
"name": "Jokes",
|
||||
"config": {
|
||||
"size": [300, 60],
|
||||
"padding_x": 10,
|
||||
"padding_y": 10,
|
||||
"fontsize": 12,
|
||||
"language": "en"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Jokes",
|
||||
"config": {
|
||||
"size": [300, 30],
|
||||
"padding_x": 10,
|
||||
"padding_y": 10,
|
||||
"fontsize": 12,
|
||||
"language": "en"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Jokes",
|
||||
"config": {
|
||||
"size": [100, 800],
|
||||
"padding_x": 10,
|
||||
"padding_y": 10,
|
||||
"fontsize": 18,
|
||||
"language": "en"
|
||||
}
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
class TestJokes(unittest.TestCase):
|
||||
|
||||
def test_generate_image(self):
|
||||
for test in tests:
|
||||
logger.info(f'test {tests.index(test) + 1} generating image..')
|
||||
module = Jokes(test)
|
||||
im_black, im_colour = module.generate_image()
|
||||
logger.info('OK')
|
||||
if Config.USE_PREVIEW:
|
||||
preview(merge(im_black, im_colour))
|
164
tests/test_inkycal_slideshow.py
Executable file
164
tests/test_inkycal_slideshow.py
Executable file
@@ -0,0 +1,164 @@
|
||||
"""
|
||||
Slideshow test (inkycal_slideshow)
|
||||
"""
|
||||
import logging
|
||||
import os
|
||||
import unittest
|
||||
|
||||
import requests
|
||||
from PIL import Image
|
||||
|
||||
from inkycal.modules import Slideshow
|
||||
from inkycal.modules.inky_image import Inkyimage
|
||||
from tests import Config
|
||||
|
||||
preview = Inkyimage.preview
|
||||
merge = Inkyimage.merge
|
||||
|
||||
if not os.path.exists("tmp"):
|
||||
os.mkdir("tmp")
|
||||
|
||||
im_urls = [
|
||||
"https://github.com/aceinnolab/Inkycal/raw/assets/Repo/coffee.png",
|
||||
"https://github.com/aceinnolab/Inkycal/raw/assets/Repo/coffee.png"
|
||||
]
|
||||
|
||||
for count, url in enumerate(im_urls):
|
||||
im = Image.open(requests.get(url, stream=True).raw)
|
||||
im.save(f"tmp/{count}.png", "PNG")
|
||||
|
||||
test_path = "tmp"
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
tests = [
|
||||
{
|
||||
"name": "Slideshow",
|
||||
"config": {
|
||||
"size": [400, 200],
|
||||
"path": test_path,
|
||||
"palette": "bwy",
|
||||
"autoflip": True,
|
||||
"orientation": "vertical",
|
||||
"padding_x": 10,
|
||||
"padding_y": 10,
|
||||
"fontsize": 12,
|
||||
"language": "en"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Slideshow",
|
||||
"config": {
|
||||
"size": [800, 500],
|
||||
"path": test_path,
|
||||
"palette": "bw",
|
||||
"autoflip": True,
|
||||
"orientation": "vertical",
|
||||
"padding_x": 10,
|
||||
"padding_y": 10,
|
||||
"fontsize": 12,
|
||||
"language": "en"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Slideshow",
|
||||
"config": {
|
||||
"size": [400, 100],
|
||||
"path": test_path,
|
||||
"palette": "bwr",
|
||||
"autoflip": False,
|
||||
"orientation": "vertical",
|
||||
"padding_x": 10,
|
||||
"padding_y": 10,
|
||||
"fontsize": 12,
|
||||
"language": "en"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Slideshow",
|
||||
"config": {
|
||||
"size": [400, 100],
|
||||
"path": test_path,
|
||||
"palette": "bwy",
|
||||
"autoflip": True,
|
||||
"orientation": "vertical",
|
||||
"padding_x": 10,
|
||||
"padding_y": 10,
|
||||
"fontsize": 12,
|
||||
"language": "en"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Slideshow",
|
||||
"config": {
|
||||
"size": [400, 100],
|
||||
"path": test_path,
|
||||
"palette": "bwy",
|
||||
"autoflip": True,
|
||||
"orientation": "horizontal",
|
||||
"padding_x": 10,
|
||||
"padding_y": 10,
|
||||
"fontsize": 12,
|
||||
"language": "en"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Slideshow",
|
||||
"config": {
|
||||
"size": [500, 800],
|
||||
"path": test_path,
|
||||
"palette": "bw",
|
||||
"autoflip": True,
|
||||
"orientation": "vertical",
|
||||
"padding_x": 0,
|
||||
"padding_y": 0,
|
||||
"fontsize": 12,
|
||||
"language": "en"
|
||||
}
|
||||
},
|
||||
{
|
||||
"position": 1,
|
||||
"name": "Slideshow",
|
||||
"config": {
|
||||
"size": [500, 800],
|
||||
"path": test_path,
|
||||
"palette": "bwr",
|
||||
"autoflip": True,
|
||||
"orientation": "vertical",
|
||||
"padding_x": 20,
|
||||
"padding_y": 20,
|
||||
"fontsize": 12,
|
||||
"language": "en"
|
||||
}
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
class TestSlideshow(unittest.TestCase):
|
||||
|
||||
def test_generate_image(self):
|
||||
for test in tests:
|
||||
logger.info(f'test {tests.index(test) + 1} generating image..')
|
||||
module = Slideshow(test)
|
||||
im_black, im_colour = module.generate_image()
|
||||
logger.info('OK')
|
||||
if Config.USE_PREVIEW:
|
||||
preview(merge(im_black, im_colour))
|
||||
|
||||
def test_switch_to_next_image(self):
|
||||
logger.info(f'testing switching to next images..')
|
||||
module = Slideshow(tests[0])
|
||||
im_black, im_colour = module.generate_image()
|
||||
if Config.USE_PREVIEW:
|
||||
preview(merge(im_black, im_colour))
|
||||
|
||||
im_black, im_colour = module.generate_image()
|
||||
if Config.USE_PREVIEW:
|
||||
preview(merge(im_black, im_colour))
|
||||
|
||||
im_black, im_colour = module.generate_image()
|
||||
if Config.USE_PREVIEW:
|
||||
preview(merge(im_black, im_colour))
|
||||
|
||||
logger.info('OK')
|
57
tests/test_inkycal_stocks.py
Executable file
57
tests/test_inkycal_stocks.py
Executable file
@@ -0,0 +1,57 @@
|
||||
import logging
|
||||
import unittest
|
||||
|
||||
from inkycal.modules import Stocks
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
tests = [
|
||||
{
|
||||
"position": 1,
|
||||
"name": "Stocks",
|
||||
"config": {
|
||||
"size": [400, 100],
|
||||
"tickers": ['TSLA', 'AMD', 'NVDA', '^DJI', 'BTC-USD', 'EURUSD=X'],
|
||||
"padding_x": 10, "padding_y": 10, "fontsize": 12, "language": "en"
|
||||
}
|
||||
},
|
||||
{
|
||||
"position": 1,
|
||||
"name": "Stocks",
|
||||
"config": {
|
||||
"size": [400, 200],
|
||||
"tickers": [],
|
||||
"padding_x": 10, "padding_y": 10, "fontsize": 12, "language": "en"
|
||||
}
|
||||
},
|
||||
{
|
||||
"position": 1,
|
||||
"name": "Stocks",
|
||||
"config": {
|
||||
"size": [400, 300],
|
||||
"tickers": ['TSLA', 'AMD', 'NVDA', '^DJI', 'BTC-USD', 'EURUSD=X'],
|
||||
"padding_x": 10, "padding_y": 10, "fontsize": 12, "language": "en"
|
||||
}
|
||||
},
|
||||
{
|
||||
"position": 1,
|
||||
"name": "Stocks",
|
||||
"config": {
|
||||
"size": [400, 400],
|
||||
"tickers": ['TSLA', 'AMD', 'NVDA', '^DJI', 'BTC-USD', 'EURUSD=X'],
|
||||
"padding_x": 10, "padding_y": 10, "fontsize": 12, "language": "en"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
class TestStocks(unittest.TestCase):
|
||||
|
||||
def test_generate_image(self):
|
||||
for test in tests:
|
||||
logger.info(f'test {tests.index(test) + 1} generating image..')
|
||||
module = Stocks(test)
|
||||
module.generate_image()
|
||||
logger.info('OK')
|
||||
|
108
tests/test_inkycal_textfile_to_display.py
Normal file
108
tests/test_inkycal_textfile_to_display.py
Normal file
@@ -0,0 +1,108 @@
|
||||
"""
|
||||
Inkycal Text module
|
||||
"""
|
||||
|
||||
import logging
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from inkycal.modules import TextToDisplay
|
||||
from inkycal.modules.inky_image import Inkyimage
|
||||
from tests import Config
|
||||
|
||||
preview = Inkyimage.preview
|
||||
merge = Inkyimage.merge
|
||||
|
||||
temp_path = f"{Config.TEMP_PATH}/temp.txt"
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
dummy_data = [
|
||||
'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', ' Donec feugiat facilisis neque vel blandit.',
|
||||
'Integer viverra dolor risus.', ' Etiam neque tellus, sollicitudin at nisi a, mollis ornare enim.',
|
||||
'Quisque sed ante eu leo dictum sagittis quis nec nisi.',
|
||||
'Suspendisse id nulla dictum, sollicitudin urna id, iaculis elit.',
|
||||
'Nulla luctus pellentesque diam, ac consequat urna molestie vitae.',
|
||||
'Donec elementum turpis eget augue laoreet, nec maximus lacus malesuada.', '\n\nEtiam eu nunc mauris.',
|
||||
'Nullam aliquam tristique leo, at dignissim turpis sodales vitae.',
|
||||
'Aenean cursus laoreet neque, sit amet semper orci tincidunt et.',
|
||||
'Proin orci urna, efficitur malesuada mattis at, pretium commodo odio.',
|
||||
'Maecenas in ante id eros aliquam porttitor quis eget est.',
|
||||
'Duis ex urna, porta nec semper nec, dignissim eu urna.', ' Quisque eleifend non magna at rutrum.',
|
||||
'\nSed at eros blandit, tempor quam et, mollis ante.', ' Etiam fringilla euismod gravida.',
|
||||
'Curabitur facilisis consectetur luctus.',
|
||||
'Integer lectus augue, convallis a consequat id, sollicitudin eget lorem.',
|
||||
'Curabitur tincidunt suscipit nibh quis mollis.',
|
||||
'Fusce cursus, orci ut maximus fringilla, velit mauris dictum est, sed ultricies ante orci viverra erat.',
|
||||
'Quisque pellentesque, mauris nec vulputate commodo, risus libero volutpat nibh, vel tristique mi neque id quam.',
|
||||
'\nVivamus blandit, dolor ut interdum sagittis, arcu tortor finibus nibh, ornare convallis dui velit quis nunc.',
|
||||
'Sed turpis justo, pellentesque eu risus scelerisque, vestibulum vulputate magna.',
|
||||
'Vivamus tincidunt sollicitudin nisl, feugiat euismod nulla consequat ut.',
|
||||
'Praesent bibendum, sapien sit amet aliquet posuere, tellus purus porta lectus, ut volutpat purus tellus tempus est.',
|
||||
'Maecenas condimentum lobortis erat nec dignissim', ' Nulla molestie posuere est',
|
||||
'Proin ultrices, nisl id luctus lacinia, augue ipsum pharetra leo, quis commodo augue dui varius urna.',
|
||||
'Morbi ultrices turpis malesuada tellus fermentum vulputate.',
|
||||
'Aliquam viverra nulla aliquam viverra gravida.', ' Pellentesque eu viverra massa.',
|
||||
'Vestibulum id nisl vehicula, aliquet dui sed, venenatis eros.',
|
||||
'Nunc iaculis, neque vitae euismod viverra, nisl mauris luctus velit, a aliquam turpis erat fringilla libero.',
|
||||
'Ut ligula elit, lacinia convallis tempus interdum, finibus ut ex.',
|
||||
'Nulla efficitur ac ligula sit amet dignissim.', ' Donec sed mi et justo venenatis faucibus.',
|
||||
'Sed tincidunt nibh erat, in vestibulum purus consequat eget.',
|
||||
'\nNulla iaculis volutpat orci id efficitur.', ' Vivamus vehicula sit amet augue tristique dignissim.',
|
||||
'Praesent eget nulla est.', ' Integer nec diam fermentum, convallis metus lacinia, lobortis mauris.',
|
||||
'Nulla venenatis metus fringilla, lacinia sem nec, pharetra sapien.',
|
||||
'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.',
|
||||
'Duis facilisis sapien est, a elementum lorem maximus ut.'
|
||||
]
|
||||
|
||||
tests = [
|
||||
{
|
||||
"position": 1,
|
||||
"name": "TextToFile",
|
||||
"config": {
|
||||
"size": [500, 100],
|
||||
"filepath": temp_path,
|
||||
"padding_x": 10,
|
||||
"padding_y": 10,
|
||||
"fontsize": 12,
|
||||
"language": "en"
|
||||
}
|
||||
},
|
||||
{
|
||||
"position": 1,
|
||||
"name": "TextToFile",
|
||||
"config": {
|
||||
"size": [500, 400],
|
||||
"filepath": "https://de.wikipedia.org/wiki/Nationale_Rotkreuz-_und_Rothalbmond-Gesellschaft",
|
||||
"padding_x": 10,
|
||||
"padding_y": 10,
|
||||
"fontsize": 12,
|
||||
"language": "en"
|
||||
}
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
class TestTextToDisplay(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.temp_path = temp_path
|
||||
if not os.path.exists(self.temp_path):
|
||||
logger.info("could not find temporary file, creating now.")
|
||||
with open(self.temp_path, encoding="utf-8", mode="w") as file:
|
||||
file.writelines(dummy_data)
|
||||
|
||||
def test_generate_image(self):
|
||||
for test in tests:
|
||||
logger.info(f'test {tests.index(test) + 1} generating image..')
|
||||
module = TextToDisplay(test)
|
||||
im_black, im_colour = module.generate_image()
|
||||
logger.info('OK')
|
||||
if Config.USE_PREVIEW:
|
||||
preview(merge(im_black, im_colour))
|
||||
|
||||
def tearDown(self):
|
||||
if os.path.exists(self.temp_path):
|
||||
logger.info("deleting temporary file.")
|
||||
os.remove(self.temp_path)
|
47
tests/test_inkycal_todoist.py
Normal file
47
tests/test_inkycal_todoist.py
Normal file
@@ -0,0 +1,47 @@
|
||||
"""
|
||||
inkycal_todoist unittest
|
||||
"""
|
||||
import logging
|
||||
import sys
|
||||
import unittest
|
||||
from inkycal.modules import Todoist
|
||||
|
||||
from inkycal.modules.inky_image import Inkyimage
|
||||
from tests import Config
|
||||
preview = Inkyimage.preview
|
||||
merge = Inkyimage.merge
|
||||
|
||||
api_key = Config.TODOIST_API_KEY
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
tests = [
|
||||
{
|
||||
"name": "Todoist",
|
||||
"config": {
|
||||
"size": [400, 1000],
|
||||
"api_key": api_key,
|
||||
"project_filter": None,
|
||||
"padding_x": 10,
|
||||
"padding_y": 10,
|
||||
"fontsize": 12,
|
||||
"language": "en"
|
||||
}
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
class TestTodoist(unittest.TestCase):
|
||||
|
||||
def test_generate_image(self):
|
||||
if api_key:
|
||||
for test in tests:
|
||||
print(f'test {tests.index(test) + 1} generating image..')
|
||||
module = Todoist(test)
|
||||
im_black, im_colour = module.generate_image()
|
||||
print('OK')
|
||||
if Config.USE_PREVIEW:
|
||||
preview(merge(im_black, im_colour))
|
||||
else:
|
||||
print('No api key given, omitting test')
|
186
tests/test_inkycal_weather.py
Executable file
186
tests/test_inkycal_weather.py
Executable file
@@ -0,0 +1,186 @@
|
||||
"""
|
||||
inkycal_weather unittest
|
||||
"""
|
||||
import logging
|
||||
import unittest
|
||||
|
||||
from inkycal.modules import Weather
|
||||
from inkycal.modules.inky_image import Inkyimage
|
||||
from tests import Config
|
||||
|
||||
preview = Inkyimage.preview
|
||||
merge = Inkyimage.merge
|
||||
|
||||
owm_api_key = Config.OPENWEATHERMAP_API_KEY
|
||||
location = '2825297'
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
tests = [
|
||||
{
|
||||
"position": 1,
|
||||
"name": "Weather",
|
||||
"config": {
|
||||
"size": [500, 100],
|
||||
"api_key": owm_api_key,
|
||||
"location": location,
|
||||
"round_temperature": True,
|
||||
"round_windspeed": True,
|
||||
"forecast_interval": "daily",
|
||||
"units": "metric",
|
||||
"hour_format": "12",
|
||||
"use_beaufort": True,
|
||||
"padding_x": 10,
|
||||
"padding_y": 10,
|
||||
"fontsize": 12,
|
||||
"language": "en"
|
||||
}
|
||||
},
|
||||
{
|
||||
"position": 1,
|
||||
"name": "Weather",
|
||||
"config": {
|
||||
"size": [500, 150],
|
||||
"api_key": owm_api_key,
|
||||
"location": "2643123",
|
||||
"round_temperature": True,
|
||||
"round_windspeed": True,
|
||||
"forecast_interval": "daily",
|
||||
"units": "metric",
|
||||
"hour_format": "12",
|
||||
"use_beaufort": True,
|
||||
"padding_x": 10,
|
||||
"padding_y": 10,
|
||||
"fontsize": 12,
|
||||
"language": "en"
|
||||
}
|
||||
},
|
||||
{
|
||||
"position": 1,
|
||||
"name": "Weather",
|
||||
"config": {
|
||||
"size": [500, 200],
|
||||
"api_key": owm_api_key,
|
||||
"location": location,
|
||||
"round_temperature": False,
|
||||
"round_windspeed": True,
|
||||
"forecast_interval": "daily",
|
||||
"units": "metric",
|
||||
"hour_format": "12",
|
||||
"use_beaufort": True,
|
||||
"padding_x": 10,
|
||||
"padding_y": 10,
|
||||
"fontsize": 12,
|
||||
"language": "en"
|
||||
}
|
||||
},
|
||||
{
|
||||
"position": 1,
|
||||
"name": "Weather",
|
||||
"config": {
|
||||
"size": [500, 100],
|
||||
"api_key": owm_api_key,
|
||||
"location": location,
|
||||
"round_temperature": True,
|
||||
"round_windspeed": False,
|
||||
"forecast_interval": "daily",
|
||||
"units": "metric",
|
||||
"hour_format": "12",
|
||||
"use_beaufort": True,
|
||||
"padding_x": 10,
|
||||
"padding_y": 10,
|
||||
"fontsize": 12,
|
||||
"language": "en"
|
||||
}
|
||||
},
|
||||
{
|
||||
"position": 1,
|
||||
"name": "Weather",
|
||||
"config": {
|
||||
"size": [500, 150],
|
||||
"api_key": owm_api_key,
|
||||
"location": location,
|
||||
"round_temperature": True,
|
||||
"round_windspeed": True,
|
||||
"forecast_interval": "hourly",
|
||||
"units": "metric",
|
||||
"hour_format": "12",
|
||||
"use_beaufort": True,
|
||||
"padding_x": 10,
|
||||
"padding_y": 10,
|
||||
"fontsize": 12,
|
||||
"language": "en"
|
||||
}
|
||||
},
|
||||
{
|
||||
"position": 1,
|
||||
"name": "Weather",
|
||||
"config": {
|
||||
"size": [500, 150],
|
||||
"api_key": owm_api_key,
|
||||
"location": location,
|
||||
"round_temperature": True,
|
||||
"round_windspeed": True,
|
||||
"forecast_interval": "daily",
|
||||
"units": "imperial",
|
||||
"hour_format": "12",
|
||||
"use_beaufort": True,
|
||||
"padding_x": 10,
|
||||
"padding_y": 10,
|
||||
"fontsize": 12,
|
||||
"language": "en"
|
||||
}
|
||||
},
|
||||
{
|
||||
"position": 1,
|
||||
"name": "Weather",
|
||||
"config": {
|
||||
"size": [500, 100],
|
||||
"api_key": owm_api_key,
|
||||
"location": location,
|
||||
"round_temperature": True,
|
||||
"round_windspeed": True,
|
||||
"forecast_interval": "daily",
|
||||
"units": "metric",
|
||||
"hour_format": "24",
|
||||
"use_beaufort": True,
|
||||
"padding_x": 10,
|
||||
"padding_y": 10,
|
||||
"fontsize": 12,
|
||||
"language": "en"
|
||||
}
|
||||
},
|
||||
{
|
||||
"position": 1,
|
||||
"name": "Weather",
|
||||
"config": {
|
||||
"size": [500, 100],
|
||||
"api_key": owm_api_key,
|
||||
"location": location,
|
||||
"round_temperature": True,
|
||||
"round_windspeed": True,
|
||||
"forecast_interval": "daily",
|
||||
"units": "metric",
|
||||
"hour_format": "12",
|
||||
"use_beaufort": False,
|
||||
"padding_x": 10,
|
||||
"padding_y": 10,
|
||||
"fontsize": 12,
|
||||
"language": "en"
|
||||
}
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
class TestWeather(unittest.TestCase):
|
||||
|
||||
def test_generate_image(self):
|
||||
for test in tests:
|
||||
logger.info(f'test {tests.index(test) + 1} generating image..')
|
||||
module = Weather(test)
|
||||
im_black, im_colour = module.generate_image()
|
||||
logger.info('OK')
|
||||
if Config.USE_PREVIEW:
|
||||
merged = merge(im_black, im_colour)
|
||||
preview(merged)
|
Reference in New Issue
Block a user