Inkycal/inkycal/tests/inkycal_weather_test.py

196 lines
5.2 KiB
Python
Raw Normal View History

2022-04-02 01:30:17 +02:00
#!python3
2022-09-08 22:25:50 +02:00
import os
import unittest
from inkycal.modules import Weather as Module
from helper_functions import *
2022-09-08 22:25:50 +02:00
environment = get_environment()
# Set to True to preview images. Only works on Raspberry Pi OS with Desktop
use_preview = False
2022-09-08 22:25:50 +02:00
secret_key = os.environ["OPENWEATHERMAP_API_KEY"] or ""
location = 'Stuttgart, DE'
tests = [
2022-09-08 22:25:50 +02:00
{
"position": 1,
"name": "Weather",
"config": {
"size": [500, 100],
"api_key": secret_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": secret_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": secret_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": secret_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": secret_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": secret_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": secret_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": secret_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"
}
},
]
2022-09-08 22:25:50 +02:00
class module_test(unittest.TestCase):
def test_get_config(self):
print('getting data for web-ui...', end="")
Module.get_config()
print('OK')
2022-09-08 22:25:50 +02:00
def test_generate_image(self):
if secret_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')
2022-10-03 02:56:04 +02:00
if use_preview and environment == 'Raspberry':
2022-09-08 22:25:50 +02:00
preview(merge(im_black, im_colour))
else:
print('No key given, omitted testing')
if __name__ == '__main__':
2022-09-08 22:25:50 +02:00
logger = logging.getLogger()
logger.level = logging.DEBUG
logger.addHandler(logging.StreamHandler(sys.stdout))
2022-09-08 22:25:50 +02:00
unittest.main()