Improved testing method

Added shebangs, logging messages are now shown.
Running on an Rpi allows previewing the generated images.
This commit is contained in:
Ace 2020-12-05 00:16:07 +01:00
parent 7ba83fd50f
commit 697401f612
9 changed files with 253 additions and 61 deletions

View File

@ -0,0 +1,24 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
Helper functions for inkycal tests.
Copyright by aceisace
"""
import logging
import sys
from os.path import exists
from inkycal.modules.inky_image import Inkyimage
preview = Inkyimage.preview
merge = Inkyimage.merge
def get_environment():
# Check if this is running on the Raspberry Pi
environment = None
envir_path = '/sys/firmware/devicetree/base/model'
if exists(envir_path):
with open(envir_path) as file:
if 'Raspberry' in file.read():
environment = 'Raspberry'
return environment

View File

@ -1,8 +1,19 @@
import unittest
from inkycal.modules.ical_parser import iCalendar
from urllib.request import urlopen
import arrow
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
iCalendar parser test (ical_parser)
Copyright by aceisace
"""
import os
import arrow
import unittest
from urllib.request import urlopen
from inkycal.modules.ical_parser import iCalendar
from helper_functions import *
ical = iCalendar()
test_ical = 'https://calendar.google.com/calendar/ical/en.usa%23holiday%40group.v.calendar.google.com/public/basic.ics'
@ -39,4 +50,9 @@ class ical_parser_test(unittest.TestCase):
os.remove('dummy.ical')
if __name__ == '__main__':
logger = logging.getLogger()
logger.level = logging.DEBUG
logger.addHandler(logging.StreamHandler(sys.stdout))
unittest.main()

View File

@ -1,13 +1,55 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
Agenda test (inkycal_agenda)
Copyright by aceisace
"""
import unittest
from inkycal.modules import Agenda as Module
from helper_functions import *
environment = get_environment()
# Set to True to preview images. Only works on Raspberry Pi OS with Desktop
use_preview = False
sample_url = "https://www.officeholidays.com/ics-fed/usa"
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": [880,100],
"ical_urls": "https://www.officeholidays.com/ics-fed/usa",
"size": [300, 800],
"ical_urls": sample_url,
"ical_files": None,
"date_format": "ddd D MMM",
"time_format": "HH:mm",
@ -30,8 +72,15 @@ class module_test(unittest.TestCase):
for test in tests:
print(f'test {tests.index(test)+1} generating image..')
module = Module(test)
module.generate_image()
im_black, im_colour = module.generate_image()
print('OK')
if use_preview == True and environment == 'Raspberry':
preview(merge(im_black, im_colour))
if __name__ == '__main__':
logger = logging.getLogger()
logger.level = logging.DEBUG
logger.addHandler(logging.StreamHandler(sys.stdout))
unittest.main()

View File

@ -1,51 +1,60 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
Calendar test (inkycal_calendar)
Copyright by aceisace
"""
import unittest
from inkycal.modules import Calendar as Module
from helper_functions import *
environment = get_environment()
# Set to True to preview images. Only works on Raspberry Pi OS with Desktop
use_preview = False
sample_url = "https://www.officeholidays.com/ics-fed/usa"
tests = [
{
"position": 2,
"name": "Calendar",
"config": {
"size": [400, 800],
"size": [500, 500],
"week_starts_on": "Monday",
"show_events": True,
"ical_urls": "https://www.officeholidays.com/ics-fed/usa",
"ical_urls": sample_url,
"ical_files": None,
"date_format": "D MMM",
"time_format": "HH:mm",
"date_format": "D MMM", "time_format": "HH:mm",
"padding_x": 10,"padding_y": 10,"fontsize": 12,"language": "en"
}
},
{
"position": 2,
"name": "Calendar",
"config": {
"size": [400, 800],
"week_starts_on": "Sunday",
"show_events": True,
"ical_urls": "https://www.officeholidays.com/ics-fed/usa",
"ical_urls": sample_url,
"ical_files": None,
"date_format": "D MMM",
"time_format": "HH:mm",
"date_format": "D MMM", "time_format": "HH:mm",
"padding_x": 10,"padding_y": 10,"fontsize": 12,"language": "en"
}
},
{
"position": 2,
"name": "Calendar",
"config": {
"size": [400, 800],
"week_starts_on": "Monday",
"show_events": False,
"ical_urls": "https://www.officeholidays.com/ics-fed/usa",
"ical_urls": sample_url,
"ical_files": None,
"date_format": "D MMM",
"time_format": "HH:mm",
"date_format": "D MMM", "time_format": "HH:mm",
"padding_x": 10,"padding_y": 10,"fontsize": 12,"language": "en"
}
},
{
"position": 2,
"name": "Calendar",
"config": {
"size": [400, 800],
@ -53,8 +62,7 @@ tests = [
"show_events": True,
"ical_urls": None,
"ical_files": None,
"date_format": "D MMM",
"time_format": "HH:mm",
"date_format": "D MMM", "time_format": "HH:mm",
"padding_x": 10,"padding_y": 10,"fontsize": 12,"language": "en"
}
},
@ -70,8 +78,15 @@ class module_test(unittest.TestCase):
for test in tests:
print(f'test {tests.index(test)+1} generating image..', end="")
module = Module(test)
module.generate_image()
im_black, im_colour = module.generate_image()
print('OK')
if use_preview == True and environment == 'Raspberry':
preview(merge(im_black, im_colour))
if __name__ == '__main__':
logger = logging.getLogger()
logger.level = logging.DEBUG
logger.addHandler(logging.StreamHandler(sys.stdout))
unittest.main()

View File

@ -1,29 +1,39 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
Feeds test (inykcal_feeds)
Copyright by aceisace
"""
import unittest
from inkycal.modules import Feeds as Module
from helper_functions import *
environment = get_environment()
# Set to True to preview images. Only works on Raspberry Pi OS with Desktop
use_preview = False
tests = [
{
"position": 1,
"name": "Feeds",
"config": {
"size": [400,100],
"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"
}
},
{
"position": 1,
"name": "Feeds",
"config": {
"size": [400,100],
"feed_urls": "http://feeds.bbci.co.uk/news/world/rss.xml#",
"shuffle_feeds": False,
"padding_x": 10, "padding_y": 10, "fontsize": 12, "language": "en"
"padding_x": 10, "padding_y": 10, "fontsize": 14, "language": "en"
}
},
{
"position": 1,
"name": "Feeds",
"config": {
"size": [400,100],
@ -44,8 +54,16 @@ class module_test(unittest.TestCase):
for test in tests:
print(f'test {tests.index(test)+1} generating image..')
module = Module(test)
module.generate_image()
im_black, im_colour = module.generate_image()
print('OK')
if use_preview == True and environment == 'Raspberry':
preview(merge(im_black, im_colour))
if __name__ == '__main__':
logger = logging.getLogger()
logger.level = logging.DEBUG
logger.addHandler(logging.StreamHandler(sys.stdout))
unittest.main()

View File

@ -1,12 +1,25 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
Image test (inkycal_image)
Copyright by aceisace
"""
import unittest
from inkycal.modules import Inkyimage as Module
from inkycal.custom import top_level
from helper_functions import *
environment = get_environment()
# Set to True to preview images. Only works on Raspberry Pi OS with Desktop
use_preview = False
test_path = f'{top_level}/Gallery/coffee.png'
tests = [
{
"position": 1,
"name": "Inkyimage",
"config": {
"size": [400,200],
@ -18,7 +31,6 @@ tests = [
}
},
{
"position": 1,
"name": "Inkyimage",
"config": {
"size": [800,500],
@ -30,7 +42,6 @@ tests = [
}
},
{
"position": 1,
"name": "Inkyimage",
"config": {
"size": [400,100],
@ -42,7 +53,6 @@ tests = [
}
},
{
"position": 1,
"name": "Inkyimage",
"config": {
"size": [400,100],
@ -54,7 +64,6 @@ tests = [
}
},
{
"position": 1,
"name": "Inkyimage",
"config": {
"size": [400,100],
@ -66,7 +75,6 @@ tests = [
}
},
{
"position": 1,
"name": "Inkyimage",
"config": {
"size": [500, 800],
@ -78,7 +86,6 @@ tests = [
}
},
{
"position": 1,
"name": "Inkyimage",
"config": {
"size": [500, 800],
@ -101,8 +108,15 @@ class module_test(unittest.TestCase):
for test in tests:
print(f'test {tests.index(test)+1} generating image..')
module = Module(test)
module.generate_image()
im_black, im_colour = module.generate_image()
print('OK')
if use_preview == True and environment == 'Raspberry':
preview(merge(im_black, im_colour))
if __name__ == '__main__':
logger = logging.getLogger()
logger.level = logging.DEBUG
logger.addHandler(logging.StreamHandler(sys.stdout))
unittest.main()

View File

@ -1,9 +1,22 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
Jokes test (inkycal_jokes)
Copyright by aceisace
"""
import unittest
from inkycal.modules import Jokes as Module
from helper_functions import *
environment = get_environment()
# Set to True to preview images. Only works on Raspberry Pi OS with Desktop
use_preview = False
tests = [
{
"position": 1,
"name": "Jokes",
"config": {
"size": [300, 60],
@ -11,7 +24,6 @@ tests = [
}
},
{
"position": 1,
"name": "Jokes",
"config": {
"size": [300, 30],
@ -19,7 +31,6 @@ tests = [
}
},
{
"position": 1,
"name": "Jokes",
"config": {
"size": [100, 800],
@ -38,8 +49,15 @@ class module_test(unittest.TestCase):
for test in tests:
print(f'test {tests.index(test)+1} generating image..')
module = Module(test)
module.generate_image()
im_black, im_colour = module.generate_image()
print('OK')
if use_preview == True and environment == 'Raspberry':
preview(merge(im_black, im_colour))
if __name__ == '__main__':
logger = logging.getLogger()
logger.level = logging.DEBUG
logger.addHandler(logging.StreamHandler(sys.stdout))
unittest.main()

View File

@ -1,12 +1,24 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
Slideshow test (inkycal_slideshow)
Copyright by aceisace
"""
import unittest
from inkycal.modules import Slideshow as Module
from inkycal.custom import top_level
from helper_functions import *
environment = get_environment()
# Set to True to preview images. Only works on Raspberry Pi OS with Desktop
use_preview = False
test_path = f'{top_level}/Gallery'
tests = [
{
"position": 1,
"name": "Slideshow",
"config": {
"size": [400,200],
@ -18,7 +30,6 @@ tests = [
}
},
{
"position": 1,
"name": "Slideshow",
"config": {
"size": [800,500],
@ -30,7 +41,6 @@ tests = [
}
},
{
"position": 1,
"name": "Slideshow",
"config": {
"size": [400,100],
@ -42,7 +52,6 @@ tests = [
}
},
{
"position": 1,
"name": "Slideshow",
"config": {
"size": [400,100],
@ -54,7 +63,6 @@ tests = [
}
},
{
"position": 1,
"name": "Slideshow",
"config": {
"size": [400,100],
@ -66,7 +74,6 @@ tests = [
}
},
{
"position": 1,
"name": "Slideshow",
"config": {
"size": [500, 800],
@ -101,16 +108,32 @@ class module_test(unittest.TestCase):
for test in tests:
print(f'test {tests.index(test)+1} generating image..')
module = Module(test)
module.generate_image()
im_black, im_colour = module.generate_image()
print('OK')
if use_preview == True and environment == 'Raspberry':
preview(merge(im_black, im_colour))
def test_switch_to_next_image(self):
print(f'testing switching to next images..')
module = Module(tests[0])
module.generate_image()
module.generate_image()
module.generate_image()
im_black, im_colour = module.generate_image()
if use_preview == True and environment == 'Raspberry':
preview(merge(im_black, im_colour))
im_black, im_colour = module.generate_image()
if use_preview == True and environment == 'Raspberry':
preview(merge(im_black, im_colour))
im_black, im_colour = module.generate_image()
if use_preview == True and environment == 'Raspberry':
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()

View File

@ -1,27 +1,38 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
Stocks test (inkycal_stocks)
Copyright by aceisace
"""
import unittest
from inkycal.modules import Stocks as Module
from helper_functions import *
environment = get_environment()
# Set to True to preview images. Only works on Raspberry Pi OS with Desktop
use_preview = False
tests = [
{
"position": 1,
"name": "Stocks",
"config": {
"size": [528, 20],
"size": [528, 30],
"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],
"size": [528, 50],
"tickers": [],
"padding_x": 10, "padding_y": 10, "fontsize": 12, "language": "en"
}
},
{
"position": 1,
"name": "Stocks",
"config": {
"size": [528, 200],
@ -30,7 +41,6 @@ tests = [
}
},
{
"position": 1,
"name": "Stocks",
"config": {
"size": [528, 800],
@ -39,7 +49,6 @@ tests = [
}
},
{
"position": 1,
"name": "Stocks",
"config": {
"size": [528, 100],
@ -48,7 +57,6 @@ tests = [
}
},
{
"position": 1,
"name": "Stocks",
"config": {
"size": [528, 400],
@ -68,8 +76,15 @@ class module_test(unittest.TestCase):
for test in tests:
print(f'test {tests.index(test)+1} generating image..')
module = Module(test)
module.generate_image()
im_black, im_colour = module.generate_image()
print('OK')
if use_preview == True and environment == 'Raspberry':
preview(merge(im_black, im_colour))
if __name__ == '__main__':
logger = logging.getLogger()
logger.level = logging.DEBUG
logger.addHandler(logging.StreamHandler(sys.stdout))
unittest.main()