tests best practices

This commit is contained in:
Ace 2023-11-21 15:18:19 +01:00
parent 96a972e31f
commit 59c59e80f5
18 changed files with 177 additions and 304 deletions

2
.gitignore vendored
View File

@ -146,7 +146,7 @@ dmypy.json
/logs /logs
# inkycal tests # inkycal tests
/inkycal/tests/tmp/ /tests/tmp/
!/inkycal/tests/*.py !/inkycal/tests/*.py
/docsource/._build/ /docsource/._build/

View File

@ -83,12 +83,11 @@ class Inkyimage:
@staticmethod @staticmethod
def preview(image): def preview(image):
""""Previews an image on gpicview (only works on Rapsbian with Desktop). """Previews an image on gpicview (only works on Rapsbian with Desktop)."""
""" path = '~/temp'
path = '/home/pi/Desktop/' image.save(path + '/temp.png')
image.save(path + 'temp.png') os.system("gpicview " + path + '/temp.png')
os.system("gpicview " + path + 'temp.png') os.system('rm ' + path + '/temp.png')
os.system('rm ' + path + 'temp.png')
def _image_loaded(self): def _image_loaded(self):
"""returns True if image was loaded""" """returns True if image was loaded"""

View File

@ -1,5 +1,3 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
""" """
Stocks Module for Inkycal Project Stocks Module for Inkycal Project
@ -15,6 +13,7 @@ import logging
import os import os
from PIL import Image from PIL import Image
from matplotlib import pyplot
from inkycal.custom import write, internet_available from inkycal.custom import write, internet_available
from inkycal.modules.template import inkycal_module 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') im_colour = Image.new('RGB', size=im_size, color='white')
# Create tmp path # 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) 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 # Check if internet is available
if internet_available() == True: if internet_available():
logger.info('Connection test passed') logger.info('Connection test passed')
else: else:
raise Exception('Network could not be reached :/') raise Exception('Network could not be reached :/')
@ -89,7 +85,7 @@ class Stocks(inkycal_module):
# Set some parameters for formatting feeds # Set some parameters for formatting feeds
line_spacing = 1 line_spacing = 1
text_bbox = self.font.getbbox("hg") 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 line_width = im_width
max_lines = (im_height // (line_height + line_spacing)) max_lines = (im_height // (line_height + line_spacing))
@ -204,7 +200,7 @@ class Stocks(inkycal_module):
else: else:
parsed_tickers_colour.append("") parsed_tickers_colour.append("")
if (_ < len(tickerCount)): if _ < len(tickerCount):
parsed_tickers.append("") parsed_tickers.append("")
parsed_tickers_colour.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'chartSpace is...{im_width} {im_height}')
logger.info(f'open chart ...{chartPath}') logger.info(f'open chart ...{chartPath}')
chartImage = Image.open(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 * _ chartPasteY = line_height * 5 * _
logger.info(f'pasting chart image with index {_} to...{chartPasteX} {chartPasteY}') 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 # Save image of black and colour channel in image-folder
return im_black, im_colour return im_black, im_colour
if __name__ == '__main__':
print('running module in standalone/debug mode')

View File

@ -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()

View File

@ -1,4 +1,3 @@
#!python
""" """
Tests config Tests config
""" """

View File

@ -1,56 +1,50 @@
#!python3
""" """
iCalendar parser test (ical_parser) iCalendar parser test (ical_parser)
""" """
import logging import logging
import os import os
import sys
import unittest import unittest
from urllib.request import urlopen from urllib.request import urlopen
import arrow import arrow
from inkycal.modules.ical_parser import iCalendar from inkycal.modules.ical_parser import iCalendar
from inkycal.tests import Config from tests import Config
ical = iCalendar() ical = iCalendar()
test_ical = Config.TEST_ICAL_URL test_ical = Config.TEST_ICAL_URL
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)
class ical_parser_test(unittest.TestCase):
class TestIcalendar(unittest.TestCase):
def test_load_url(self): def test_load_url(self):
print('testing loading via URL...', end="") logger.info('testing loading via URL...')
ical.load_url(test_ical) ical.load_url(test_ical)
print('OK') logger.info('OK')
def test_get_events(self): def test_get_events(self):
print('testing parsing of events...', end="") logger.info('testing parsing of events...')
ical.get_events(arrow.now(), arrow.now().shift(weeks=30)) ical.get_events(arrow.now(), arrow.now().shift(weeks=30))
print('OK') logger.info('OK')
def test_sorting(self): def test_sorting(self):
print('testing sorting of events...', end="") logger.info('testing sorting of events...')
ical.sort() ical.sort()
print('OK') logger.info('OK')
def test_show_events(self): def test_show_events(self):
print('testing if events can be shown...', end="") logger.info('testing if events can be shown...')
ical.show_events() ical.show_events()
print('OK') logger.info('OK')
def test_laod_from_file(self): def test_laod_from_file(self):
print('testing loading from file...', end="") logger.info('testing loading from file...')
dummy = str(urlopen(test_ical, timeout=10).read().decode()) dummy = str(urlopen(test_ical, timeout=10).read().decode())
with open('dummy.ical', mode="w", encoding="utf-8") as file: with open('dummy.ical', mode="w", encoding="utf-8") as file:
file.write(dummy) file.write(dummy)
ical.load_from_file('dummy.ical') ical.load_from_file('dummy.ical')
print('OK') logger.info('OK')
os.remove('dummy.ical') 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,17 +1,19 @@
#!python3
""" """
inkycal_agenda unittest inkycal_agenda unittest
""" """
import logging import logging
import sys
import unittest import unittest
from inkycal.modules import Agenda as Module
from inkycal.modules import Agenda
from inkycal.modules.inky_image import Inkyimage from inkycal.modules.inky_image import Inkyimage
from inkycal.tests import Config from tests import Config
preview = Inkyimage.preview preview = Inkyimage.preview
merge = Inkyimage.merge merge = Inkyimage.merge
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)
sample_url = Config.SAMPLE_ICAL_URL sample_url = Config.SAMPLE_ICAL_URL
tests = [ tests = [
@ -61,25 +63,13 @@ tests = [
] ]
class module_test(unittest.TestCase): class TestAgenda(unittest.TestCase):
def test_get_config(self):
print('getting data for web-ui...', end="")
Module.get_config()
print('OK')
def test_generate_image(self): def test_generate_image(self):
for test in tests: for test in tests:
print(f'test {tests.index(test) + 1} generating image..') logger.info(f'test {tests.index(test) + 1} generating image..')
module = Module(test) module = Agenda(test)
im_black, im_colour = module.generate_image() im_black, im_colour = module.generate_image()
print('OK') logger.info('OK')
if Config.USE_PREVIEW: if Config.USE_PREVIEW:
preview(merge(im_black, im_colour)) 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,20 +1,21 @@
#!python3
""" """
inkycal_calendar unittest inkycal_calendar unittest
""" """
import logging import logging
import sys
import unittest import unittest
from inkycal.modules import Calendar as Module from inkycal.modules import Calendar
from inkycal.modules.inky_image import Inkyimage from inkycal.modules.inky_image import Inkyimage
from inkycal.tests import Config from tests import Config
preview = Inkyimage.preview preview = Inkyimage.preview
merge = Inkyimage.merge merge = Inkyimage.merge
sample_url = Config.SAMPLE_ICAL_URL sample_url = Config.SAMPLE_ICAL_URL
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)
tests = [ tests = [
{ {
"name": "Calendar", "name": "Calendar",
@ -67,25 +68,13 @@ tests = [
] ]
class module_test(unittest.TestCase): class TestCalendar(unittest.TestCase):
def test_get_config(self):
print('getting data for web-ui...', end="")
Module.get_config()
print('OK')
def test_generate_image(self): def test_generate_image(self):
for test in tests: for test in tests:
print(f'test {tests.index(test) + 1} generating image..', end="") print(f'test {tests.index(test) + 1} generating image..', end="")
module = Module(test) module = Calendar(test)
im_black, im_colour = module.generate_image() im_black, im_colour = module.generate_image()
print('OK') print('OK')
if Config.USE_PREVIEW: if Config.USE_PREVIEW:
preview(merge(im_black, im_colour)) 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,17 +1,18 @@
#!python3
""" """
inkycal_feeds unittest inkycal_feeds unittest
""" """
import logging import logging
import sys
import unittest import unittest
from inkycal.modules import Feeds as Module from inkycal.modules import Feeds
from inkycal.modules.inky_image import Inkyimage from inkycal.modules.inky_image import Inkyimage
from inkycal.tests import Config from tests import Config
preview = Inkyimage.preview preview = Inkyimage.preview
merge = Inkyimage.merge merge = Inkyimage.merge
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)
tests = [ tests = [
{ {
"name": "Feeds", "name": "Feeds",
@ -43,25 +44,14 @@ tests = [
] ]
class module_test(unittest.TestCase): class TestFeeds(unittest.TestCase):
def test_get_config(self):
print('getting data for web-ui...', end="")
Module.get_config()
print('OK')
def test_generate_image(self): def test_generate_image(self):
for test in tests: for test in tests:
print(f'test {tests.index(test) + 1} generating image..') logger.info(f'test {tests.index(test) + 1} generating image..')
module = Module(test) module = Feeds(test)
im_black, im_colour = module.generate_image() im_black, im_colour = module.generate_image()
print('OK') logger.info('OK')
if Config.USE_PREVIEW: if Config.USE_PREVIEW:
preview(merge(im_black, im_colour)) 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,19 +1,16 @@
#!python3
""" """
inkycal_image unittest inkycal_image unittest
""" """
import logging import logging
import sys
import unittest import unittest
import requests import requests
from PIL import Image from PIL import Image
from inkycal.modules import Inkyimage as Module from inkycal.modules import Inkyimage as Module
from inkycal.modules.inky_image import Inkyimage from inkycal.modules.inky_image import Inkyimage
from inkycal.tests import Config from tests import Config
preview = Inkyimage.preview preview = Inkyimage.preview
merge = Inkyimage.merge merge = Inkyimage.merge
@ -23,6 +20,9 @@ im = Image.open(requests.get(url, stream=True).raw)
im.save("test.png", "PNG") im.save("test.png", "PNG")
test_path = "test.png" test_path = "test.png"
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)
tests = [ tests = [
{ {
"name": "Inkyimage", "name": "Inkyimage",
@ -104,25 +104,13 @@ tests = [
] ]
class module_test(unittest.TestCase): class TestInkyImage(unittest.TestCase):
def test_get_config(self):
print('getting data for web-ui...', end="")
Module.get_config()
print('OK')
def test_generate_image(self): def test_generate_image(self):
for test in tests: for test in tests:
print(f'test {tests.index(test) + 1} generating image..') logger.info(f'test {tests.index(test) + 1} generating image..')
module = Module(test) module = Module(test)
im_black, im_colour = module.generate_image() im_black, im_colour = module.generate_image()
print('OK') logger.info('OK')
if Config.USE_PREVIEW: if Config.USE_PREVIEW:
preview(merge(im_black, im_colour)) 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,17 +1,19 @@
#!python3
""" """
inkycal_jokes unittest inkycal_jokes unittest
""" """
import logging import logging
import sys
import unittest import unittest
from inkycal.modules import Jokes as Module
from inkycal.modules import Jokes
from inkycal.modules.inky_image import Inkyimage from inkycal.modules.inky_image import Inkyimage
from inkycal.tests import Config from tests import Config
preview = Inkyimage.preview preview = Inkyimage.preview
merge = Inkyimage.merge merge = Inkyimage.merge
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)
tests = [ tests = [
{ {
"name": "Jokes", "name": "Jokes",
@ -46,25 +48,13 @@ tests = [
] ]
class module_test(unittest.TestCase): class TestJokes(unittest.TestCase):
def test_get_config(self):
print('getting data for web-ui...', end="")
Module.get_config()
print('OK')
def test_generate_image(self): def test_generate_image(self):
for test in tests: for test in tests:
print(f'test {tests.index(test) + 1} generating image..') logger.info(f'test {tests.index(test) + 1} generating image..')
module = Module(test) module = Jokes(test)
im_black, im_colour = module.generate_image() im_black, im_colour = module.generate_image()
print('OK') logger.info('OK')
if Config.USE_PREVIEW: if Config.USE_PREVIEW:
preview(merge(im_black, im_colour)) 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,18 +1,16 @@
#!python3
""" """
Slideshow test (inkycal_slideshow) Slideshow test (inkycal_slideshow)
""" """
import logging import logging
import os import os
import sys
import unittest import unittest
import requests import requests
from PIL import Image from PIL import Image
from inkycal.modules import Slideshow as Module from inkycal.modules import Slideshow
from inkycal.modules.inky_image import Inkyimage from inkycal.modules.inky_image import Inkyimage
from inkycal.tests import Config from tests import Config
preview = Inkyimage.preview preview = Inkyimage.preview
merge = Inkyimage.merge merge = Inkyimage.merge
@ -31,6 +29,9 @@ for count, url in enumerate(im_urls):
test_path = "tmp" test_path = "tmp"
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)
tests = [ tests = [
{ {
"name": "Slideshow", "name": "Slideshow",
@ -134,24 +135,20 @@ tests = [
] ]
class module_test(unittest.TestCase): class TestSlideshow(unittest.TestCase):
def test_get_config(self):
print('getting data for web-ui...', end="")
Module.get_config()
print('OK')
def test_generate_image(self): def test_generate_image(self):
for test in tests: for test in tests:
print(f'test {tests.index(test) + 1} generating image..') logger.info(f'test {tests.index(test) + 1} generating image..')
module = Module(test) module = Slideshow(test)
im_black, im_colour = module.generate_image() im_black, im_colour = module.generate_image()
print('OK') logger.info('OK')
if Config.USE_PREVIEW: if Config.USE_PREVIEW:
preview(merge(im_black, im_colour)) preview(merge(im_black, im_colour))
def test_switch_to_next_image(self): def test_switch_to_next_image(self):
print(f'testing switching to next images..') logger.info(f'testing switching to next images..')
module = Module(tests[0]) module = Slideshow(tests[0])
im_black, im_colour = module.generate_image() im_black, im_colour = module.generate_image()
if Config.USE_PREVIEW: if Config.USE_PREVIEW:
preview(merge(im_black, im_colour)) preview(merge(im_black, im_colour))
@ -164,12 +161,4 @@ class module_test(unittest.TestCase):
if Config.USE_PREVIEW: if Config.USE_PREVIEW:
preview(merge(im_black, im_colour)) preview(merge(im_black, im_colour))
print('OK') logger.info('OK')
if __name__ == '__main__':
logger = logging.getLogger()
logger.level = logging.DEBUG
logger.addHandler(logging.StreamHandler(sys.stdout))
unittest.main()

57
tests/test_inkycal_stocks.py Executable file
View 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')

View File

@ -1,19 +1,23 @@
#!python3 """
Inkycal Text module
"""
import logging import logging
import os import os
import sys
import unittest import unittest
from inkycal.modules import TextToDisplay as Module from inkycal.modules import TextToDisplay
from inkycal.modules.inky_image import Inkyimage from inkycal.modules.inky_image import Inkyimage
from inkycal.tests import Config from tests import Config
preview = Inkyimage.preview preview = Inkyimage.preview
merge = Inkyimage.merge merge = Inkyimage.merge
temp_path = f"{Config.TEMP_PATH}/temp.txt" temp_path = f"{Config.TEMP_PATH}/temp.txt"
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)
dummy_data = [ dummy_data = [
'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', ' Donec feugiat facilisis neque vel blandit.', '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.', 'Integer viverra dolor risus.', ' Etiam neque tellus, sollicitudin at nisi a, mollis ornare enim.',
@ -85,33 +89,20 @@ class TestTextToDisplay(unittest.TestCase):
def setUp(self): def setUp(self):
self.temp_path = temp_path self.temp_path = temp_path
if not os.path.exists(self.temp_path): if not os.path.exists(self.temp_path):
print("could not find temporary file, creating now.") logger.info("could not find temporary file, creating now.")
with open(self.temp_path, encoding="utf-8", mode="w") as file: with open(self.temp_path, encoding="utf-8", mode="w") as file:
file.writelines(dummy_data) 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): def test_generate_image(self):
for test in tests: for test in tests:
print(f'test {tests.index(test) + 1} generating image..') logger.info(f'test {tests.index(test) + 1} generating image..')
module = Module(test) module = TextToDisplay(test)
im_black, im_colour = module.generate_image() im_black, im_colour = module.generate_image()
print('OK') logger.info('OK')
if Config.USE_PREVIEW: if Config.USE_PREVIEW:
preview(merge(im_black, im_colour)) preview(merge(im_black, im_colour))
def tearDown(self): def tearDown(self):
if os.path.exists(self.temp_path): if os.path.exists(self.temp_path):
print("deleting temporary file.") logger.info("deleting temporary file.")
os.remove(self.temp_path) os.remove(self.temp_path)
if __name__ == '__main__':
logger = logging.getLogger()
logger.level = logging.DEBUG
logger.addHandler(logging.StreamHandler(sys.stdout))
unittest.main()

View File

@ -1,19 +1,21 @@
#!python3
""" """
inkycal_todoist unittest inkycal_todoist unittest
""" """
import logging import logging
import sys import sys
import unittest import unittest
from inkycal.modules import Todoist as Module from inkycal.modules import Todoist
from inkycal.modules.inky_image import Inkyimage from inkycal.modules.inky_image import Inkyimage
from inkycal.tests import Config from tests import Config
preview = Inkyimage.preview preview = Inkyimage.preview
merge = Inkyimage.merge merge = Inkyimage.merge
api_key = Config.TODOIST_API_KEY api_key = Config.TODOIST_API_KEY
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)
tests = [ tests = [
{ {
"name": "Todoist", "name": "Todoist",
@ -30,29 +32,16 @@ tests = [
] ]
class module_test(unittest.TestCase): class TestTodoist(unittest.TestCase):
def test_get_config(self):
print('getting data for web-ui...', end="")
Module.get_config()
print('OK')
def test_generate_image(self): def test_generate_image(self):
if api_key: if api_key:
for test in tests: for test in tests:
print(f'test {tests.index(test) + 1} generating image..') print(f'test {tests.index(test) + 1} generating image..')
module = Module(test) module = Todoist(test)
im_black, im_colour = module.generate_image() im_black, im_colour = module.generate_image()
print('OK') print('OK')
if Config.USE_PREVIEW: if Config.USE_PREVIEW:
preview(merge(im_black, im_colour)) preview(merge(im_black, im_colour))
else: else:
print('No api key given, omitting test') 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()

View File

@ -1,20 +1,22 @@
#!python3
""" """
inkycal_weather unittest inkycal_weather unittest
""" """
import logging import logging
import sys
import unittest import unittest
from inkycal.modules import Weather as Module
from inkycal.modules import Weather
from inkycal.modules.inky_image import Inkyimage from inkycal.modules.inky_image import Inkyimage
from inkycal.tests import Config from tests import Config
preview = Inkyimage.preview preview = Inkyimage.preview
merge = Inkyimage.merge merge = Inkyimage.merge
owm_api_key = Config.OPENWEATHERMAP_API_KEY owm_api_key = Config.OPENWEATHERMAP_API_KEY
location = '2825297' location = '2825297'
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)
tests = [ tests = [
{ {
"position": 1, "position": 1,
@ -171,27 +173,14 @@ tests = [
] ]
class module_test(unittest.TestCase): class TestWeather(unittest.TestCase):
def test_get_config(self):
print('getting data for web-ui...', end="")
Module.get_config()
print('OK')
def test_generate_image(self): def test_generate_image(self):
for test in tests: for test in tests:
print(f'test {tests.index(test) + 1} generating image..') logger.info(f'test {tests.index(test) + 1} generating image..')
module = Module(test) module = Weather(test)
im_black, im_colour = module.generate_image() im_black, im_colour = module.generate_image()
print('OK') logger.info('OK')
if Config.USE_PREVIEW: if Config.USE_PREVIEW:
merged = merge(im_black, im_colour) merged = merge(im_black, im_colour)
preview(merged) preview(merged)
if __name__ == '__main__':
logger = logging.getLogger()
logger.level = logging.DEBUG
logger.addHandler(logging.StreamHandler(sys.stdout))
unittest.main()