From 59c59e80f511f48095be9c911e721757c3169b25 Mon Sep 17 00:00:00 2001 From: Ace <saadnaseer63@yahoo.de> Date: Tue, 21 Nov 2023 15:18:19 +0100 Subject: [PATCH] tests best practices --- .gitignore | 2 +- inkycal/modules/inky_image.py | 11 ++- inkycal/modules/inkycal_stocks.py | 26 +++---- inkycal/tests/test_inkycal_stocks.py | 75 ------------------- {inkycal/tests => tests}/__init__.py | 0 {inkycal/tests => tests}/config.py | 1 - {inkycal/tests => tests}/settings.json | 0 {inkycal/tests => tests}/test_ical_parser.py | 36 ++++----- .../tests => tests}/test_inkycal_agenda.py | 30 +++----- .../tests => tests}/test_inkycal_calendar.py | 27 ++----- .../tests => tests}/test_inkycal_feeds.py | 28 +++---- .../tests => tests}/test_inkycal_image.py | 28 ++----- .../tests => tests}/test_inkycal_jokes.py | 30 +++----- .../tests => tests}/test_inkycal_slideshow.py | 37 ++++----- tests/test_inkycal_stocks.py | 57 ++++++++++++++ .../test_inkycal_textfile_to_display.py | 37 ++++----- .../tests => tests}/test_inkycal_todoist.py | 25 ++----- .../tests => tests}/test_inkycal_weather.py | 31 +++----- 18 files changed, 177 insertions(+), 304 deletions(-) delete mode 100755 inkycal/tests/test_inkycal_stocks.py rename {inkycal/tests => tests}/__init__.py (100%) rename {inkycal/tests => tests}/config.py (98%) rename {inkycal/tests => tests}/settings.json (100%) rename {inkycal/tests => tests}/test_ical_parser.py (55%) rename {inkycal/tests => tests}/test_inkycal_agenda.py (73%) rename {inkycal/tests => tests}/test_inkycal_calendar.py (81%) rename {inkycal/tests => tests}/test_inkycal_feeds.py (69%) rename {inkycal/tests => tests}/test_inkycal_image.py (85%) rename {inkycal/tests => tests}/test_inkycal_jokes.py (64%) rename {inkycal/tests => tests}/test_inkycal_slideshow.py (84%) create mode 100755 tests/test_inkycal_stocks.py rename {inkycal/tests => tests}/test_inkycal_textfile_to_display.py (87%) rename {inkycal/tests => tests}/test_inkycal_todoist.py (66%) rename {inkycal/tests => tests}/test_inkycal_weather.py (89%) diff --git a/.gitignore b/.gitignore index c338aec..73b644a 100644 --- a/.gitignore +++ b/.gitignore @@ -146,7 +146,7 @@ dmypy.json /logs # inkycal tests -/inkycal/tests/tmp/ +/tests/tmp/ !/inkycal/tests/*.py /docsource/._build/ diff --git a/inkycal/modules/inky_image.py b/inkycal/modules/inky_image.py index e069114..fb6df4e 100755 --- a/inkycal/modules/inky_image.py +++ b/inkycal/modules/inky_image.py @@ -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""" diff --git a/inkycal/modules/inkycal_stocks.py b/inkycal/modules/inkycal_stocks.py index a18ed34..cf58a41 100755 --- a/inkycal/modules/inkycal_stocks.py +++ b/inkycal/modules/inkycal_stocks.py @@ -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') diff --git a/inkycal/tests/test_inkycal_stocks.py b/inkycal/tests/test_inkycal_stocks.py deleted file mode 100755 index 6ed6334..0000000 --- a/inkycal/tests/test_inkycal_stocks.py +++ /dev/null @@ -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() diff --git a/inkycal/tests/__init__.py b/tests/__init__.py similarity index 100% rename from inkycal/tests/__init__.py rename to tests/__init__.py diff --git a/inkycal/tests/config.py b/tests/config.py similarity index 98% rename from inkycal/tests/config.py rename to tests/config.py index 3b846fc..e7ba725 100644 --- a/inkycal/tests/config.py +++ b/tests/config.py @@ -1,4 +1,3 @@ -#!python """ Tests config """ diff --git a/inkycal/tests/settings.json b/tests/settings.json similarity index 100% rename from inkycal/tests/settings.json rename to tests/settings.json diff --git a/inkycal/tests/test_ical_parser.py b/tests/test_ical_parser.py similarity index 55% rename from inkycal/tests/test_ical_parser.py rename to tests/test_ical_parser.py index f92c06a..b57b23a 100755 --- a/inkycal/tests/test_ical_parser.py +++ b/tests/test_ical_parser.py @@ -1,56 +1,50 @@ -#!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 +from tests import Config ical = iCalendar() 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): - print('testing loading via URL...', end="") + logger.info('testing loading via URL...') ical.load_url(test_ical) - print('OK') + logger.info('OK') 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)) - print('OK') + logger.info('OK') def test_sorting(self): - print('testing sorting of events...', end="") + logger.info('testing sorting of events...') ical.sort() - print('OK') + logger.info('OK') def test_show_events(self): - print('testing if events can be shown...', end="") + logger.info('testing if events can be shown...') ical.show_events() - print('OK') + logger.info('OK') 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()) with open('dummy.ical', mode="w", encoding="utf-8") as file: file.write(dummy) ical.load_from_file('dummy.ical') - print('OK') + logger.info('OK') os.remove('dummy.ical') - -if __name__ == '__main__': - logger = logging.getLogger() - logger.level = logging.DEBUG - logger.addHandler(logging.StreamHandler(sys.stdout)) - - unittest.main() diff --git a/inkycal/tests/test_inkycal_agenda.py b/tests/test_inkycal_agenda.py similarity index 73% rename from inkycal/tests/test_inkycal_agenda.py rename to tests/test_inkycal_agenda.py index 7bfeacf..af002ec 100755 --- a/inkycal/tests/test_inkycal_agenda.py +++ b/tests/test_inkycal_agenda.py @@ -1,17 +1,19 @@ -#!python3 """ inkycal_agenda unittest """ import logging -import sys import unittest -from inkycal.modules import Agenda as Module +from inkycal.modules import Agenda from inkycal.modules.inky_image import Inkyimage -from inkycal.tests import Config +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 = [ @@ -61,25 +63,13 @@ tests = [ ] -class module_test(unittest.TestCase): - def test_get_config(self): - print('getting data for web-ui...', end="") - Module.get_config() - print('OK') +class TestAgenda(unittest.TestCase): def test_generate_image(self): for test in tests: - print(f'test {tests.index(test) + 1} generating image..') - module = Module(test) + logger.info(f'test {tests.index(test) + 1} generating image..') + module = Agenda(test) im_black, im_colour = module.generate_image() - print('OK') + logger.info('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() diff --git a/inkycal/tests/test_inkycal_calendar.py b/tests/test_inkycal_calendar.py similarity index 81% rename from inkycal/tests/test_inkycal_calendar.py rename to tests/test_inkycal_calendar.py index a8438f8..cb28b9a 100755 --- a/inkycal/tests/test_inkycal_calendar.py +++ b/tests/test_inkycal_calendar.py @@ -1,20 +1,21 @@ -#!python3 """ inkycal_calendar unittest """ import logging -import sys import unittest -from inkycal.modules import Calendar as Module - +from inkycal.modules import Calendar from inkycal.modules.inky_image import Inkyimage -from inkycal.tests import Config +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", @@ -67,25 +68,13 @@ tests = [ ] -class module_test(unittest.TestCase): - def test_get_config(self): - print('getting data for web-ui...', end="") - Module.get_config() - print('OK') +class TestCalendar(unittest.TestCase): def test_generate_image(self): for test in tests: print(f'test {tests.index(test) + 1} generating image..', end="") - module = Module(test) + module = Calendar(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() diff --git a/inkycal/tests/test_inkycal_feeds.py b/tests/test_inkycal_feeds.py similarity index 69% rename from inkycal/tests/test_inkycal_feeds.py rename to tests/test_inkycal_feeds.py index 30f9613..ccf4481 100755 --- a/inkycal/tests/test_inkycal_feeds.py +++ b/tests/test_inkycal_feeds.py @@ -1,17 +1,18 @@ -#!python3 """ inkycal_feeds unittest """ import logging -import sys import unittest -from inkycal.modules import Feeds as Module +from inkycal.modules import Feeds from inkycal.modules.inky_image import Inkyimage -from inkycal.tests import Config +from tests import Config preview = Inkyimage.preview merge = Inkyimage.merge +logger = logging.getLogger(__name__) +logging.basicConfig(level=logging.DEBUG) + tests = [ { "name": "Feeds", @@ -43,25 +44,14 @@ tests = [ ] -class module_test(unittest.TestCase): - def test_get_config(self): - print('getting data for web-ui...', end="") - Module.get_config() - print('OK') +class TestFeeds(unittest.TestCase): def test_generate_image(self): for test in tests: - print(f'test {tests.index(test) + 1} generating image..') - module = Module(test) + logger.info(f'test {tests.index(test) + 1} generating image..') + module = Feeds(test) im_black, im_colour = module.generate_image() - print('OK') + logger.info('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() diff --git a/inkycal/tests/test_inkycal_image.py b/tests/test_inkycal_image.py similarity index 85% rename from inkycal/tests/test_inkycal_image.py rename to tests/test_inkycal_image.py index 873d604..4ee3e49 100755 --- a/inkycal/tests/test_inkycal_image.py +++ b/tests/test_inkycal_image.py @@ -1,19 +1,16 @@ -#!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 +from tests import Config + preview = Inkyimage.preview merge = Inkyimage.merge @@ -23,6 +20,9 @@ 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", @@ -104,25 +104,13 @@ tests = [ ] -class module_test(unittest.TestCase): - def test_get_config(self): - print('getting data for web-ui...', end="") - Module.get_config() - print('OK') +class TestInkyImage(unittest.TestCase): def test_generate_image(self): 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) im_black, im_colour = module.generate_image() - print('OK') + logger.info('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() diff --git a/inkycal/tests/test_inkycal_jokes.py b/tests/test_inkycal_jokes.py similarity index 64% rename from inkycal/tests/test_inkycal_jokes.py rename to tests/test_inkycal_jokes.py index 547f12f..a4455ef 100755 --- a/inkycal/tests/test_inkycal_jokes.py +++ b/tests/test_inkycal_jokes.py @@ -1,17 +1,19 @@ -#!python3 """ inkycal_jokes unittest """ import logging -import sys import unittest -from inkycal.modules import Jokes as Module + +from inkycal.modules import Jokes from inkycal.modules.inky_image import Inkyimage -from inkycal.tests import Config +from tests import Config preview = Inkyimage.preview merge = Inkyimage.merge +logger = logging.getLogger(__name__) +logging.basicConfig(level=logging.DEBUG) + tests = [ { "name": "Jokes", @@ -46,25 +48,13 @@ tests = [ ] -class module_test(unittest.TestCase): - def test_get_config(self): - print('getting data for web-ui...', end="") - Module.get_config() - print('OK') +class TestJokes(unittest.TestCase): def test_generate_image(self): for test in tests: - print(f'test {tests.index(test) + 1} generating image..') - module = Module(test) + logger.info(f'test {tests.index(test) + 1} generating image..') + module = Jokes(test) im_black, im_colour = module.generate_image() - print('OK') + logger.info('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() diff --git a/inkycal/tests/test_inkycal_slideshow.py b/tests/test_inkycal_slideshow.py similarity index 84% rename from inkycal/tests/test_inkycal_slideshow.py rename to tests/test_inkycal_slideshow.py index 834f406..9c811b9 100755 --- a/inkycal/tests/test_inkycal_slideshow.py +++ b/tests/test_inkycal_slideshow.py @@ -1,18 +1,16 @@ -#!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 import Slideshow from inkycal.modules.inky_image import Inkyimage -from inkycal.tests import Config +from tests import Config preview = Inkyimage.preview merge = Inkyimage.merge @@ -31,6 +29,9 @@ for count, url in enumerate(im_urls): test_path = "tmp" +logger = logging.getLogger(__name__) +logging.basicConfig(level=logging.DEBUG) + tests = [ { "name": "Slideshow", @@ -134,24 +135,20 @@ tests = [ ] -class module_test(unittest.TestCase): - def test_get_config(self): - print('getting data for web-ui...', end="") - Module.get_config() - print('OK') +class TestSlideshow(unittest.TestCase): def test_generate_image(self): for test in tests: - print(f'test {tests.index(test) + 1} generating image..') - module = Module(test) + logger.info(f'test {tests.index(test) + 1} generating image..') + module = Slideshow(test) im_black, im_colour = module.generate_image() - print('OK') + logger.info('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]) + 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)) @@ -164,12 +161,4 @@ class module_test(unittest.TestCase): 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() + logger.info('OK') diff --git a/tests/test_inkycal_stocks.py b/tests/test_inkycal_stocks.py new file mode 100755 index 0000000..6a6b224 --- /dev/null +++ b/tests/test_inkycal_stocks.py @@ -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') + diff --git a/inkycal/tests/test_inkycal_textfile_to_display.py b/tests/test_inkycal_textfile_to_display.py similarity index 87% rename from inkycal/tests/test_inkycal_textfile_to_display.py rename to tests/test_inkycal_textfile_to_display.py index a667af1..223e9a5 100644 --- a/inkycal/tests/test_inkycal_textfile_to_display.py +++ b/tests/test_inkycal_textfile_to_display.py @@ -1,19 +1,23 @@ -#!python3 +""" +Inkycal Text module +""" + import logging import os -import sys import unittest -from inkycal.modules import TextToDisplay as Module +from inkycal.modules import TextToDisplay from inkycal.modules.inky_image import Inkyimage -from inkycal.tests import Config +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.', @@ -85,33 +89,20 @@ 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.") + 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_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) + logger.info(f'test {tests.index(test) + 1} generating image..') + module = TextToDisplay(test) im_black, im_colour = module.generate_image() - print('OK') + logger.info('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.") + logger.info("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() diff --git a/inkycal/tests/test_inkycal_todoist.py b/tests/test_inkycal_todoist.py similarity index 66% rename from inkycal/tests/test_inkycal_todoist.py rename to tests/test_inkycal_todoist.py index bf87caf..44c3041 100644 --- a/inkycal/tests/test_inkycal_todoist.py +++ b/tests/test_inkycal_todoist.py @@ -1,19 +1,21 @@ -#!python3 """ inkycal_todoist unittest """ import logging import sys import unittest -from inkycal.modules import Todoist as Module +from inkycal.modules import Todoist from inkycal.modules.inky_image import Inkyimage -from inkycal.tests import Config +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", @@ -30,29 +32,16 @@ tests = [ ] -class module_test(unittest.TestCase): - - def test_get_config(self): - print('getting data for web-ui...', end="") - Module.get_config() - print('OK') +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 = Module(test) + 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') - - -if __name__ == '__main__': - logger = logging.getLogger() - logger.level = logging.DEBUG - logger.addHandler(logging.StreamHandler(sys.stdout)) - - unittest.main() diff --git a/inkycal/tests/test_inkycal_weather.py b/tests/test_inkycal_weather.py similarity index 89% rename from inkycal/tests/test_inkycal_weather.py rename to tests/test_inkycal_weather.py index b6bde42..bcc50ce 100755 --- a/inkycal/tests/test_inkycal_weather.py +++ b/tests/test_inkycal_weather.py @@ -1,20 +1,22 @@ -#!python3 """ inkycal_weather unittest """ import logging -import sys import unittest -from inkycal.modules import Weather as Module +from inkycal.modules import Weather from inkycal.modules.inky_image import Inkyimage -from inkycal.tests import Config +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, @@ -171,27 +173,14 @@ tests = [ ] -class module_test(unittest.TestCase): - def test_get_config(self): - print('getting data for web-ui...', end="") - Module.get_config() - print('OK') +class TestWeather(unittest.TestCase): def test_generate_image(self): for test in tests: - print(f'test {tests.index(test) + 1} generating image..') - module = Module(test) + logger.info(f'test {tests.index(test) + 1} generating image..') + module = Weather(test) im_black, im_colour = module.generate_image() - print('OK') + logger.info('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()