tests best practices
This commit is contained in:
@@ -83,12 +83,11 @@ class Inkyimage:
|
||||
|
||||
@staticmethod
|
||||
def preview(image):
|
||||
""""Previews an image on gpicview (only works on Rapsbian with Desktop).
|
||||
"""
|
||||
path = '/home/pi/Desktop/'
|
||||
image.save(path + 'temp.png')
|
||||
os.system("gpicview " + path + 'temp.png')
|
||||
os.system('rm ' + path + 'temp.png')
|
||||
"""Previews an image on gpicview (only works on Rapsbian with Desktop)."""
|
||||
path = '~/temp'
|
||||
image.save(path + '/temp.png')
|
||||
os.system("gpicview " + path + '/temp.png')
|
||||
os.system('rm ' + path + '/temp.png')
|
||||
|
||||
def _image_loaded(self):
|
||||
"""returns True if image was loaded"""
|
||||
|
@@ -1,5 +1,3 @@
|
||||
#!/usr/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Stocks Module for Inkycal Project
|
||||
|
||||
@@ -15,6 +13,7 @@ import logging
|
||||
import os
|
||||
|
||||
from PIL import Image
|
||||
from matplotlib import pyplot
|
||||
|
||||
from inkycal.custom import write, internet_available
|
||||
from inkycal.modules.template import inkycal_module
|
||||
@@ -71,17 +70,14 @@ class Stocks(inkycal_module):
|
||||
im_colour = Image.new('RGB', size=im_size, color='white')
|
||||
|
||||
# Create tmp path
|
||||
tmpPath = '/tmp/inkycal_stocks/'
|
||||
tmpPath = 'temp/'
|
||||
|
||||
try:
|
||||
if not os.path.exists(tmpPath):
|
||||
print(f"Creating tmp directory {tmpPath}")
|
||||
os.mkdir(tmpPath)
|
||||
except OSError:
|
||||
print(f"Creation of tmp directory {tmpPath} failed")
|
||||
else:
|
||||
print(f"Successfully created tmp directory {tmpPath} ")
|
||||
|
||||
# Check if internet is available
|
||||
if internet_available() == True:
|
||||
if internet_available():
|
||||
logger.info('Connection test passed')
|
||||
else:
|
||||
raise Exception('Network could not be reached :/')
|
||||
@@ -89,7 +85,7 @@ class Stocks(inkycal_module):
|
||||
# Set some parameters for formatting feeds
|
||||
line_spacing = 1
|
||||
text_bbox = self.font.getbbox("hg")
|
||||
line_height = text_bbox[3] - text_bbox[1] + line_spacing
|
||||
line_height = text_bbox[3] + line_spacing
|
||||
line_width = im_width
|
||||
max_lines = (im_height // (line_height + line_spacing))
|
||||
|
||||
@@ -204,7 +200,7 @@ class Stocks(inkycal_module):
|
||||
else:
|
||||
parsed_tickers_colour.append("")
|
||||
|
||||
if (_ < len(tickerCount)):
|
||||
if _ < len(tickerCount):
|
||||
parsed_tickers.append("")
|
||||
parsed_tickers_colour.append("")
|
||||
|
||||
@@ -225,9 +221,10 @@ class Stocks(inkycal_module):
|
||||
logger.info(f'chartSpace is...{im_width} {im_height}')
|
||||
logger.info(f'open chart ...{chartPath}')
|
||||
chartImage = Image.open(chartPath)
|
||||
chartImage.thumbnail((im_width / 4, line_height * 4), Image.BICUBIC)
|
||||
chartImage.thumbnail((int(im_width / 4), int(line_height * 4)), Image.BICUBIC)
|
||||
pyplot.close()
|
||||
|
||||
chartPasteX = im_width - (chartImage.width)
|
||||
chartPasteX = im_width - chartImage.width
|
||||
chartPasteY = line_height * 5 * _
|
||||
logger.info(f'pasting chart image with index {_} to...{chartPasteX} {chartPasteY}')
|
||||
|
||||
@@ -258,6 +255,3 @@ class Stocks(inkycal_module):
|
||||
# Save image of black and colour channel in image-folder
|
||||
return im_black, im_colour
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print('running module in standalone/debug mode')
|
||||
|
@@ -1 +0,0 @@
|
||||
from .config import Config
|
@@ -1,36 +0,0 @@
|
||||
#!python
|
||||
"""
|
||||
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"
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -1,49 +0,0 @@
|
||||
|
||||
{
|
||||
"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"
|
||||
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@@ -1,56 +0,0 @@
|
||||
#!python3
|
||||
"""
|
||||
iCalendar parser test (ical_parser)
|
||||
"""
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
from urllib.request import urlopen
|
||||
|
||||
import arrow
|
||||
from inkycal.modules.ical_parser import iCalendar
|
||||
from inkycal.tests import Config
|
||||
|
||||
ical = iCalendar()
|
||||
test_ical = Config.TEST_ICAL_URL
|
||||
|
||||
|
||||
class ical_parser_test(unittest.TestCase):
|
||||
|
||||
def test_load_url(self):
|
||||
print('testing loading via URL...', end="")
|
||||
ical.load_url(test_ical)
|
||||
print('OK')
|
||||
|
||||
def test_get_events(self):
|
||||
print('testing parsing of events...', end="")
|
||||
ical.get_events(arrow.now(), arrow.now().shift(weeks=30))
|
||||
print('OK')
|
||||
|
||||
def test_sorting(self):
|
||||
print('testing sorting of events...', end="")
|
||||
ical.sort()
|
||||
print('OK')
|
||||
|
||||
def test_show_events(self):
|
||||
print('testing if events can be shown...', end="")
|
||||
ical.show_events()
|
||||
print('OK')
|
||||
|
||||
def test_laod_from_file(self):
|
||||
print('testing loading from file...', end="")
|
||||
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')
|
||||
print('OK')
|
||||
os.remove('dummy.ical')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
logger = logging.getLogger()
|
||||
logger.level = logging.DEBUG
|
||||
logger.addHandler(logging.StreamHandler(sys.stdout))
|
||||
|
||||
unittest.main()
|
@@ -1,85 +0,0 @@
|
||||
#!python3
|
||||
"""
|
||||
inkycal_agenda unittest
|
||||
"""
|
||||
import logging
|
||||
import sys
|
||||
import unittest
|
||||
from inkycal.modules import Agenda as Module
|
||||
|
||||
from inkycal.modules.inky_image import Inkyimage
|
||||
from inkycal.tests import Config
|
||||
preview = Inkyimage.preview
|
||||
merge = Inkyimage.merge
|
||||
|
||||
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 module_test(unittest.TestCase):
|
||||
def test_get_config(self):
|
||||
print('getting data for web-ui...', end="")
|
||||
Module.get_config()
|
||||
print('OK')
|
||||
|
||||
def test_generate_image(self):
|
||||
for test in tests:
|
||||
print(f'test {tests.index(test) + 1} generating image..')
|
||||
module = Module(test)
|
||||
im_black, im_colour = module.generate_image()
|
||||
print('OK')
|
||||
if Config.USE_PREVIEW:
|
||||
preview(merge(im_black, im_colour))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
logger = logging.getLogger()
|
||||
logger.level = logging.DEBUG
|
||||
logger.addHandler(logging.StreamHandler(sys.stdout))
|
||||
|
||||
unittest.main()
|
@@ -1,91 +0,0 @@
|
||||
#!python3
|
||||
"""
|
||||
inkycal_calendar unittest
|
||||
"""
|
||||
import logging
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
from inkycal.modules import Calendar as Module
|
||||
|
||||
from inkycal.modules.inky_image import Inkyimage
|
||||
from inkycal.tests import Config
|
||||
preview = Inkyimage.preview
|
||||
merge = Inkyimage.merge
|
||||
|
||||
sample_url = Config.SAMPLE_ICAL_URL
|
||||
|
||||
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 module_test(unittest.TestCase):
|
||||
def test_get_config(self):
|
||||
print('getting data for web-ui...', end="")
|
||||
Module.get_config()
|
||||
print('OK')
|
||||
|
||||
def test_generate_image(self):
|
||||
for test in tests:
|
||||
print(f'test {tests.index(test) + 1} generating image..', end="")
|
||||
module = Module(test)
|
||||
im_black, im_colour = module.generate_image()
|
||||
print('OK')
|
||||
if Config.USE_PREVIEW:
|
||||
preview(merge(im_black, im_colour))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
logger = logging.getLogger()
|
||||
logger.level = logging.DEBUG
|
||||
logger.addHandler(logging.StreamHandler(sys.stdout))
|
||||
|
||||
unittest.main()
|
@@ -1,67 +0,0 @@
|
||||
#!python3
|
||||
"""
|
||||
inkycal_feeds unittest
|
||||
"""
|
||||
import logging
|
||||
import sys
|
||||
import unittest
|
||||
from inkycal.modules import Feeds as Module
|
||||
from inkycal.modules.inky_image import Inkyimage
|
||||
from inkycal.tests import Config
|
||||
|
||||
preview = Inkyimage.preview
|
||||
merge = Inkyimage.merge
|
||||
|
||||
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 module_test(unittest.TestCase):
|
||||
def test_get_config(self):
|
||||
print('getting data for web-ui...', end="")
|
||||
Module.get_config()
|
||||
print('OK')
|
||||
|
||||
def test_generate_image(self):
|
||||
for test in tests:
|
||||
print(f'test {tests.index(test) + 1} generating image..')
|
||||
module = Module(test)
|
||||
im_black, im_colour = module.generate_image()
|
||||
print('OK')
|
||||
if Config.USE_PREVIEW:
|
||||
preview(merge(im_black, im_colour))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
logger = logging.getLogger()
|
||||
logger.level = logging.DEBUG
|
||||
logger.addHandler(logging.StreamHandler(sys.stdout))
|
||||
|
||||
unittest.main()
|
@@ -1,128 +0,0 @@
|
||||
#!python3
|
||||
|
||||
"""
|
||||
inkycal_image unittest
|
||||
"""
|
||||
import logging
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
import requests
|
||||
from PIL import Image
|
||||
|
||||
from inkycal.modules import Inkyimage as Module
|
||||
|
||||
from inkycal.modules.inky_image import Inkyimage
|
||||
from inkycal.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"
|
||||
|
||||
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 module_test(unittest.TestCase):
|
||||
def test_get_config(self):
|
||||
print('getting data for web-ui...', end="")
|
||||
Module.get_config()
|
||||
print('OK')
|
||||
|
||||
def test_generate_image(self):
|
||||
for test in tests:
|
||||
print(f'test {tests.index(test) + 1} generating image..')
|
||||
module = Module(test)
|
||||
im_black, im_colour = module.generate_image()
|
||||
print('OK')
|
||||
if Config.USE_PREVIEW:
|
||||
preview(merge(im_black, im_colour))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
logger = logging.getLogger()
|
||||
logger.level = logging.DEBUG
|
||||
logger.addHandler(logging.StreamHandler(sys.stdout))
|
||||
|
||||
unittest.main()
|
@@ -1,70 +0,0 @@
|
||||
#!python3
|
||||
"""
|
||||
inkycal_jokes unittest
|
||||
"""
|
||||
import logging
|
||||
import sys
|
||||
import unittest
|
||||
from inkycal.modules import Jokes as Module
|
||||
from inkycal.modules.inky_image import Inkyimage
|
||||
from inkycal.tests import Config
|
||||
|
||||
preview = Inkyimage.preview
|
||||
merge = Inkyimage.merge
|
||||
|
||||
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 module_test(unittest.TestCase):
|
||||
def test_get_config(self):
|
||||
print('getting data for web-ui...', end="")
|
||||
Module.get_config()
|
||||
print('OK')
|
||||
|
||||
def test_generate_image(self):
|
||||
for test in tests:
|
||||
print(f'test {tests.index(test) + 1} generating image..')
|
||||
module = Module(test)
|
||||
im_black, im_colour = module.generate_image()
|
||||
print('OK')
|
||||
if Config.USE_PREVIEW:
|
||||
preview(merge(im_black, im_colour))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
logger = logging.getLogger()
|
||||
logger.level = logging.DEBUG
|
||||
logger.addHandler(logging.StreamHandler(sys.stdout))
|
||||
|
||||
unittest.main()
|
@@ -1,175 +0,0 @@
|
||||
#!python3
|
||||
|
||||
"""
|
||||
Slideshow test (inkycal_slideshow)
|
||||
"""
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
import requests
|
||||
from PIL import Image
|
||||
|
||||
from inkycal.modules import Slideshow as Module
|
||||
from inkycal.modules.inky_image import Inkyimage
|
||||
from inkycal.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"
|
||||
|
||||
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 module_test(unittest.TestCase):
|
||||
def test_get_config(self):
|
||||
print('getting data for web-ui...', end="")
|
||||
Module.get_config()
|
||||
print('OK')
|
||||
|
||||
def test_generate_image(self):
|
||||
for test in tests:
|
||||
print(f'test {tests.index(test) + 1} generating image..')
|
||||
module = Module(test)
|
||||
im_black, im_colour = module.generate_image()
|
||||
print('OK')
|
||||
if Config.USE_PREVIEW:
|
||||
preview(merge(im_black, im_colour))
|
||||
|
||||
def test_switch_to_next_image(self):
|
||||
print(f'testing switching to next images..')
|
||||
module = Module(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))
|
||||
|
||||
print('OK')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
logger = logging.getLogger()
|
||||
logger.level = logging.DEBUG
|
||||
logger.addHandler(logging.StreamHandler(sys.stdout))
|
||||
|
||||
unittest.main()
|
@@ -1,75 +0,0 @@
|
||||
import unittest
|
||||
from inkycal.modules import Stocks as Module
|
||||
|
||||
tests = [
|
||||
{
|
||||
"position": 1,
|
||||
"name": "Stocks",
|
||||
"config": {
|
||||
"size": [528, 20],
|
||||
"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": [528, 20],
|
||||
"tickers": [],
|
||||
"padding_x": 10, "padding_y": 10, "fontsize": 12, "language": "en"
|
||||
}
|
||||
},
|
||||
{
|
||||
"position": 1,
|
||||
"name": "Stocks",
|
||||
"config": {
|
||||
"size": [528, 200],
|
||||
"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": [528, 800],
|
||||
"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": [528, 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": [528, 400],
|
||||
"tickers": ['TSLA', 'AMD', 'NVDA', '^DJI', 'BTC-USD', 'EURUSD=X'],
|
||||
"padding_x": 10, "padding_y": 10, "fontsize": 14, "language": "en"
|
||||
}
|
||||
},
|
||||
]
|
||||
|
||||
class module_test(unittest.TestCase):
|
||||
def test_get_config(self):
|
||||
print('getting data for web-ui...', end = "")
|
||||
Module.get_config()
|
||||
print('OK')
|
||||
|
||||
def test_generate_image(self):
|
||||
for test in tests:
|
||||
print(f'test {tests.index(test)+1} generating image..')
|
||||
module = Module(test)
|
||||
module.generate_image()
|
||||
print('OK')
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
@@ -1,117 +0,0 @@
|
||||
#!python3
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
from inkycal.modules import TextToDisplay as Module
|
||||
from inkycal.modules.inky_image import Inkyimage
|
||||
from inkycal.tests import Config
|
||||
|
||||
preview = Inkyimage.preview
|
||||
merge = Inkyimage.merge
|
||||
|
||||
|
||||
temp_path = f"{Config.TEMP_PATH}/temp.txt"
|
||||
|
||||
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):
|
||||
print("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_get_config(self):
|
||||
print('getting data for web-ui...', end="")
|
||||
Module.get_config()
|
||||
print('OK')
|
||||
|
||||
def test_generate_image(self):
|
||||
for test in tests:
|
||||
print(f'test {tests.index(test) + 1} generating image..')
|
||||
module = Module(test)
|
||||
im_black, im_colour = module.generate_image()
|
||||
print('OK')
|
||||
if Config.USE_PREVIEW:
|
||||
preview(merge(im_black, im_colour))
|
||||
|
||||
def tearDown(self):
|
||||
if os.path.exists(self.temp_path):
|
||||
print("deleting temporary file.")
|
||||
os.remove(self.temp_path)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
logger = logging.getLogger()
|
||||
logger.level = logging.DEBUG
|
||||
logger.addHandler(logging.StreamHandler(sys.stdout))
|
||||
|
||||
unittest.main()
|
@@ -1,58 +0,0 @@
|
||||
#!python3
|
||||
"""
|
||||
inkycal_todoist unittest
|
||||
"""
|
||||
import logging
|
||||
import sys
|
||||
import unittest
|
||||
from inkycal.modules import Todoist as Module
|
||||
|
||||
from inkycal.modules.inky_image import Inkyimage
|
||||
from inkycal.tests import Config
|
||||
preview = Inkyimage.preview
|
||||
merge = Inkyimage.merge
|
||||
|
||||
api_key = Config.TODOIST_API_KEY
|
||||
|
||||
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 module_test(unittest.TestCase):
|
||||
|
||||
def test_get_config(self):
|
||||
print('getting data for web-ui...', end="")
|
||||
Module.get_config()
|
||||
print('OK')
|
||||
|
||||
def test_generate_image(self):
|
||||
if api_key:
|
||||
for test in tests:
|
||||
print(f'test {tests.index(test) + 1} generating image..')
|
||||
module = Module(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')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
logger = logging.getLogger()
|
||||
logger.level = logging.DEBUG
|
||||
logger.addHandler(logging.StreamHandler(sys.stdout))
|
||||
|
||||
unittest.main()
|
@@ -1,197 +0,0 @@
|
||||
#!python3
|
||||
"""
|
||||
inkycal_weather unittest
|
||||
"""
|
||||
import logging
|
||||
import sys
|
||||
import unittest
|
||||
from inkycal.modules import Weather as Module
|
||||
|
||||
from inkycal.modules.inky_image import Inkyimage
|
||||
from inkycal.tests import Config
|
||||
preview = Inkyimage.preview
|
||||
merge = Inkyimage.merge
|
||||
|
||||
owm_api_key = Config.OPENWEATHERMAP_API_KEY
|
||||
location = '2825297'
|
||||
|
||||
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 module_test(unittest.TestCase):
|
||||
def test_get_config(self):
|
||||
print('getting data for web-ui...', end="")
|
||||
Module.get_config()
|
||||
print('OK')
|
||||
|
||||
def test_generate_image(self):
|
||||
for test in tests:
|
||||
print(f'test {tests.index(test) + 1} generating image..')
|
||||
module = Module(test)
|
||||
im_black, im_colour = module.generate_image()
|
||||
print('OK')
|
||||
if Config.USE_PREVIEW:
|
||||
merged = merge(im_black, im_colour)
|
||||
preview(merged)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
logger = logging.getLogger()
|
||||
logger.level = logging.DEBUG
|
||||
logger.addHandler(logging.StreamHandler(sys.stdout))
|
||||
|
||||
unittest.main()
|
Reference in New Issue
Block a user