text-module enhancement
This allows an improved approach to load text from URL Also improved the function to check for a connection by attempting three times before giving up
This commit is contained in:
@@ -28,6 +28,8 @@ class Config:
|
||||
# inkycal_todoist_test
|
||||
TODOIST_API_KEY = get("TODOIST_API_KEY")
|
||||
|
||||
TEMP_PATH = f"{basedir}/tmp"
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -3,14 +3,16 @@ import logging
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
from inkycal.modules import TextToDisplay as Module
|
||||
|
||||
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
|
||||
|
||||
file_path = None
|
||||
|
||||
temp_path = f"{Config.TEMP_PATH}/temp.txt"
|
||||
|
||||
dummy_data = [
|
||||
'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', ' Donec feugiat facilisis neque vel blandit.',
|
||||
@@ -56,7 +58,7 @@ tests = [
|
||||
"name": "TextToFile",
|
||||
"config": {
|
||||
"size": [500, 100],
|
||||
"filepath": file_path,
|
||||
"filepath": temp_path,
|
||||
"padding_x": 10,
|
||||
"padding_y": 10,
|
||||
"fontsize": 12,
|
||||
@@ -68,7 +70,7 @@ tests = [
|
||||
"name": "TextToFile",
|
||||
"config": {
|
||||
"size": [500, 400],
|
||||
"filepath": file_path,
|
||||
"filepath": "https://de.wikipedia.org/wiki/Nationale_Rotkreuz-_und_Rothalbmond-Gesellschaft",
|
||||
"padding_x": 10,
|
||||
"padding_y": 10,
|
||||
"fontsize": 12,
|
||||
@@ -80,31 +82,19 @@ tests = [
|
||||
|
||||
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):
|
||||
delete_file_after_parse = False
|
||||
|
||||
if not file_path:
|
||||
delete_file_after_parse = True
|
||||
print("Filepath does not exist. Creating dummy file")
|
||||
|
||||
tmp_path = "tmp.txt"
|
||||
with open(tmp_path, mode="w", encoding="utf-8") as file:
|
||||
file.writelines(dummy_data)
|
||||
|
||||
# update tests with new temp path
|
||||
for test in tests:
|
||||
test["config"]["filepath"] = tmp_path
|
||||
|
||||
else:
|
||||
make_request = bool(file_path.startswith("https://"))
|
||||
if not make_request and not os.path.exists(file_path):
|
||||
raise FileNotFoundError("Your text file could not be found")
|
||||
|
||||
for test in tests:
|
||||
print(f'test {tests.index(test) + 1} generating image..')
|
||||
module = Module(test)
|
||||
@@ -113,9 +103,10 @@ class TestTextToDisplay(unittest.TestCase):
|
||||
if Config.USE_PREVIEW:
|
||||
preview(merge(im_black, im_colour))
|
||||
|
||||
if delete_file_after_parse:
|
||||
print("cleaning up temp file")
|
||||
os.remove("tmp.txt")
|
||||
def tearDown(self):
|
||||
if os.path.exists(self.temp_path):
|
||||
print("deleting temporary file.")
|
||||
os.remove(self.temp_path)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Reference in New Issue
Block a user