From 90da27aa2667a607ae6ca9077331f909190ae09d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20Gilli=C3=9Fen?= Date: Wed, 1 Jan 2025 14:00:15 +0100 Subject: [PATCH 1/7] build: add pytest to dev dependencies --- Pipfile | 1 + Pipfile.lock | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/Pipfile b/Pipfile index 759a706..07b8017 100644 --- a/Pipfile +++ b/Pipfile @@ -11,6 +11,7 @@ playwright = "*" [dev-packages] ruff = "*" +pytest = "*" [requires] python_version = "3.11" diff --git a/Pipfile.lock b/Pipfile.lock index c4b76c2..dda351b 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "b358f25a10840ae00c59ef4a4b0eeb501c9d0b19383f513ebc967bc2df82c810" + "sha256": "6ca86b615fd19fbd7fec64b4943c04ebdef109b0227014712e70c532d77ee314" }, "pipfile-spec": 6, "requires": { @@ -326,6 +326,39 @@ } }, "develop": { + "iniconfig": { + "hashes": [ + "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3", + "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374" + ], + "markers": "python_version >= '3.7'", + "version": "==2.0.0" + }, + "packaging": { + "hashes": [ + "sha256:09abb1bccd265c01f4a3aa3f7a7db064b36514d2cba19a2f694fe6150451a759", + "sha256:c228a6dc5e932d346bc5739379109d49e8853dd8223571c7c5b55260edc0b97f" + ], + "markers": "python_version >= '3.8'", + "version": "==24.2" + }, + "pluggy": { + "hashes": [ + "sha256:2cffa88e94fdc978c4c574f15f9e59b7f4201d439195c3715ca9e2486f1d0cf1", + "sha256:44e1ad92c8ca002de6377e165f3e0f1be63266ab4d554740532335b9d75ea669" + ], + "markers": "python_version >= '3.8'", + "version": "==1.5.0" + }, + "pytest": { + "hashes": [ + "sha256:50e16d954148559c9a74109af1eaf0c945ba2d8f30f0a3d3335edde19788b6f6", + "sha256:965370d062bce11e73868e0335abac31b4d3de0e82f4007408d242b4f8610761" + ], + "index": "pypi", + "markers": "python_version >= '3.8'", + "version": "==8.3.4" + }, "ruff": { "hashes": [ "sha256:0d5f89f254836799af1615798caa5f80b7f935d7a670fad66c5007928e57ace8", From 3e6235c29586afe0b8b56ac30a997e461227472f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20Gilli=C3=9Fen?= Date: Wed, 1 Jan 2025 14:00:40 +0100 Subject: [PATCH 2/7] dev: configure pytest to run with debug level logger --- pytest.ini | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 pytest.ini diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..14e9480 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,4 @@ +[pytest] +log_format = %(asctime)s %(levelname)s %(message)s +log_date_format = %Y-%m-%d %H:%M:%S +log_level = DEBUG \ No newline at end of file From b72de28dcf060b0e483eead26ad31d87bc7daad1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20Gilli=C3=9Fen?= Date: Wed, 1 Jan 2025 14:01:54 +0100 Subject: [PATCH 3/7] bug: fixes #26 when threshold is exceeded at the end of the day refactor time slot determination to separate function add tests for time slot determination fix open slots --- euemastobot.py | 40 +++++++++++++++++++++++----------- test_time_slots.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 12 deletions(-) create mode 100644 test_time_slots.py diff --git a/euemastobot.py b/euemastobot.py index 1340fa8..5ccf31e 100644 --- a/euemastobot.py +++ b/euemastobot.py @@ -11,17 +11,7 @@ mastodon = None -def get_time_slots(): - api_url = "https://api.energy-charts.info/ren_share_forecast?country=de" - headers = { - "accept": "application/json", - "User-Agent": "Erneuerbare Energien Überschuss Mastobot", - } - r = requests.get(api_url, headers=headers) - r.raise_for_status() - logger.info("got the forecast data") - forecast = r.json() - +def get_slots_from_forecast(forecast): i = 0 filter_above_threshold = [] for row in forecast["ren_share"]: @@ -30,22 +20,48 @@ def get_time_slots(): else: filter_above_threshold.append(0) i += 1 - + logging.debug("Above threshold: ") + logging.debug(filter_above_threshold) + start = 0 previous = 0 slots = [] i = 0 + added = True for time_slice in filter_above_threshold: if time_slice != previous: previous = time_slice if time_slice == 1: start = forecast["unix_seconds"][i] + added = False elif time_slice == 0: end = forecast["unix_seconds"][i - 1] start_text = datetime.fromtimestamp(start).strftime("%H:%M") end_text = datetime.fromtimestamp(end).strftime("%H:%M") slots.append((start_text, end_text)) + added = True i += 1 + # If the threshold was exceeded at the end, has it been added to the array yet? + if not added: + start_text = datetime.fromtimestamp(start).strftime("%H:%M") + end_text = "0:00" + slots.append((start_text, end_text)) + return slots + + +def get_time_slots(): + api_url = "https://api.energy-charts.info/ren_share_forecast?country=de" + headers = { + "accept": "application/json", + "User-Agent": "Erneuerbare Energien Überschuss Mastobot", + } + r = requests.get(api_url, headers=headers) + r.raise_for_status() + logger.info("got the forecast data") + forecast = r.json() + + slots = get_slots_from_forecast(forecast) + return slots diff --git a/test_time_slots.py b/test_time_slots.py new file mode 100644 index 0000000..a76183e --- /dev/null +++ b/test_time_slots.py @@ -0,0 +1,54 @@ +import euemastobot as bot + +def test_timeslot_without_threshold(): + forecast = _create_forecast_object([50, 60, 30]) + result = bot.get_slots_from_forecast(forecast) + assert len(result) == 0 + +def test_timeslot_with_threshold(): + forecast = _create_forecast_object([50, 110, 30]) + result = bot.get_slots_from_forecast(forecast) + print(result) + assert len(result) == 1 + +def test_timeslot_with_threshold_100(): + forecast = _create_forecast_object([50, 100, 30]) + result = bot.get_slots_from_forecast(forecast) + print(result) + assert len(result) == 0 + +def test_timeslot_with_two_slots(): + forecast = _create_forecast_object([50, 110, 20, 130, 30]) + result = bot.get_slots_from_forecast(forecast) + print(result) + assert len(result) == 2 + +def test_timeslot_with_threshold_at_start(): + forecast = _create_forecast_object([110, 20, 30, 30]) + result = bot.get_slots_from_forecast(forecast) + print(result) + assert len(result) == 1 + +def test_timeslot_with_threshold_at_end(): + forecast = _create_forecast_object([30, 20, 30, 30, 110]) + result = bot.get_slots_from_forecast(forecast) + print(result) + assert len(result) == 1 + +def test_timeslot_with_threshold_at_start_and_end(): + forecast = _create_forecast_object([110, 20, 30, 30, 110]) + result = bot.get_slots_from_forecast(forecast) + print(result) + assert len(result) == 2 + +def _create_forecast_object(percentages): + # skipping objects solar_share, wind_onshore_share and wind_offshore_share + # Unix seconds resolution is 900 + timestamp_start = 1734735600 + result = { + "unix_seconds": [ x*900 + timestamp_start for x in range(0,len(percentages))], + "ren_share": percentages, + "substitute": False, + "deprecated": False + } + return result \ No newline at end of file From b22ead10844c119fe9b446276f9e84d58b97a760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20Gilli=C3=9Fen?= Date: Wed, 1 Jan 2025 14:12:05 +0100 Subject: [PATCH 4/7] test: add tests for time slot determination from real API results --- test_data/two_slots_ending_the_day.json | 465 +++++++++++++++++++++++ test_data/whole_day_above_threshold.json | 465 +++++++++++++++++++++++ test_time_slots.py | 14 + 3 files changed, 944 insertions(+) create mode 100644 test_data/two_slots_ending_the_day.json create mode 100644 test_data/whole_day_above_threshold.json diff --git a/test_data/two_slots_ending_the_day.json b/test_data/two_slots_ending_the_day.json new file mode 100644 index 0000000..52005a6 --- /dev/null +++ b/test_data/two_slots_ending_the_day.json @@ -0,0 +1,465 @@ +{ + "unix_seconds": [ + 1734735600, + 1734736500, + 1734737400, + 1734738300, + 1734739200, + 1734740100, + 1734741000, + 1734741900, + 1734742800, + 1734743700, + 1734744600, + 1734745500, + 1734746400, + 1734747300, + 1734748200, + 1734749100, + 1734750000, + 1734750900, + 1734751800, + 1734752700, + 1734753600, + 1734754500, + 1734755400, + 1734756300, + 1734757200, + 1734758100, + 1734759000, + 1734759900, + 1734760800, + 1734761700, + 1734762600, + 1734763500, + 1734764400, + 1734765300, + 1734766200, + 1734767100, + 1734768000, + 1734768900, + 1734769800, + 1734770700, + 1734771600, + 1734772500, + 1734773400, + 1734774300, + 1734775200, + 1734776100, + 1734777000, + 1734777900, + 1734778800, + 1734779700, + 1734780600, + 1734781500, + 1734782400, + 1734783300, + 1734784200, + 1734785100, + 1734786000, + 1734786900, + 1734787800, + 1734788700, + 1734789600, + 1734790500, + 1734791400, + 1734792300, + 1734793200, + 1734794100, + 1734795000, + 1734795900, + 1734796800, + 1734797700, + 1734798600, + 1734799500, + 1734800400, + 1734801300, + 1734802200, + 1734803100, + 1734804000, + 1734804900, + 1734805800, + 1734806700, + 1734807600, + 1734808500, + 1734809400, + 1734810300, + 1734811200, + 1734812100, + 1734813000, + 1734813900, + 1734814800, + 1734815700, + 1734816600, + 1734817500, + 1734818400, + 1734819300, + 1734820200, + 1734821100 + ], + "ren_share": [ + 89.2, + 90.8, + 92.6, + 93.4, + 94.7, + 95.8, + 97.1, + 97.9, + 98.4, + 99.1, + 101, + 101.4, + 102.6, + 102.7, + 103.9, + 104, + 103.7, + 103.1, + 102.6, + 101.7, + 101, + 100.8, + 101.6, + 101.1, + 102.1, + 101.5, + 100.2, + 98.8, + 96.7, + 95, + 92.9, + 91.5, + 89.5, + 88.2, + 87.4, + 87.2, + 86.6, + 86.3, + 86.4, + 86.8, + 87.7, + 88.5, + 88.9, + 89.8, + 90.2, + 90.5, + 90.4, + 90.7, + 90.4, + 91, + 91.1, + 91.3, + 90.9, + 91.2, + 90.9, + 90.8, + 90.2, + 88.5, + 91.1, + 91.1, + 90.7, + 91, + 91.5, + 91.9, + 91.8, + 92.5, + 92.6, + 92.5, + 92.7, + 93.3, + 93.9, + 94.5, + 95, + 96, + 96.8, + 98, + 98.7, + 100.9, + 102.2, + 103.5, + 105.4, + 107.8, + 109.8, + 111.3, + 112.4, + 113.6, + 114.3, + 114.6, + 113.1, + 113.8, + 114.8, + 115.7, + 117.6, + 118, + 119.3, + 120.4 + ], + "solar_share": [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0.1, + 0.5, + 1.3, + 2.3, + 3.5, + 4.7, + 5.9, + 7.1, + 8.2, + 9.2, + 10, + 10.6, + 11.2, + 11.5, + 11.6, + 11.5, + 11.3, + 11.2, + 10.8, + 10.2, + 8.9, + 8.3, + 7.5, + 6.7, + 5.9, + 4.9, + 4.2, + 3.4, + 2.6, + 1.9, + 1.3, + 0.7, + 0.3, + 0.1, + 0.1 + ], + "wind_onshore_share": [ + 63.8, + 65.1, + 66.5, + 67.7, + 69, + 69.9, + 71, + 71.7, + 72.3, + 73.1, + 74.8, + 75.6, + 77, + 77.4, + 78.5, + 78.7, + 78.7, + 78.4, + 78.1, + 77.8, + 77.3, + 77, + 77.5, + 76.8, + 77.8, + 77.1, + 75.7, + 74.3, + 72.4, + 70.8, + 69.1, + 67.9, + 66.2, + 64.9, + 63.5, + 62.5, + 61.2, + 60.2, + 59.3, + 58.8, + 58.6, + 58.5, + 58.4, + 58.7, + 58.9, + 59, + 59, + 59.3, + 59.5, + 60.2, + 60.7, + 61.5, + 62.2, + 63, + 63.3, + 63.9, + 64.2, + 63.9, + 66.7, + 67.5, + 68.1, + 69.1, + 70.1, + 71, + 71.5, + 72.5, + 72.9, + 73.1, + 73.5, + 74.2, + 75, + 75.7, + 76.3, + 77.3, + 78.1, + 79.2, + 79.9, + 81.7, + 82.9, + 84, + 85.6, + 87.5, + 89.2, + 90.3, + 91.2, + 91.9, + 92.4, + 92.6, + 90.9, + 91.5, + 92.1, + 92.8, + 94.3, + 94.6, + 95.5, + 96.4 + ], + "wind_offshore_share": [ + 12.8, + 12.9, + 13.1, + 12.7, + 12.5, + 12.6, + 12.7, + 12.6, + 12.6, + 12.3, + 12.5, + 12.2, + 11.9, + 11.7, + 11.7, + 11.7, + 11.5, + 11.3, + 11.1, + 10.7, + 10.5, + 10.7, + 10.9, + 11.1, + 11.2, + 11.4, + 11.5, + 11.7, + 11.7, + 11.7, + 11.6, + 11.6, + 11.4, + 11.3, + 11.2, + 11.1, + 11, + 10.7, + 10.5, + 10.4, + 10.4, + 10.3, + 10.2, + 10.2, + 9.8, + 9.7, + 9.6, + 9.8, + 9.4, + 9.4, + 9.4, + 9.3, + 9.5, + 9.6, + 9.6, + 9.6, + 9.6, + 9.4, + 9.6, + 9.6, + 9.4, + 9.4, + 9.4, + 9.4, + 9.3, + 9.2, + 9.1, + 8.9, + 8.8, + 8.7, + 8.7, + 8.6, + 8.5, + 8.5, + 8.5, + 8.5, + 8.5, + 8.7, + 8.8, + 8.9, + 9, + 9.2, + 9.4, + 9.6, + 9.7, + 10, + 10.2, + 10.2, + 10.4, + 10.5, + 10.6, + 10.7, + 10.9, + 11, + 11.1, + 11.3 + ], + "substitute": false, + "deprecated": false + } \ No newline at end of file diff --git a/test_data/whole_day_above_threshold.json b/test_data/whole_day_above_threshold.json new file mode 100644 index 0000000..91cb726 --- /dev/null +++ b/test_data/whole_day_above_threshold.json @@ -0,0 +1,465 @@ +{ + "unix_seconds": [ + 1735686000, + 1735686900, + 1735687800, + 1735688700, + 1735689600, + 1735690500, + 1735691400, + 1735692300, + 1735693200, + 1735694100, + 1735695000, + 1735695900, + 1735696800, + 1735697700, + 1735698600, + 1735699500, + 1735700400, + 1735701300, + 1735702200, + 1735703100, + 1735704000, + 1735704900, + 1735705800, + 1735706700, + 1735707600, + 1735708500, + 1735709400, + 1735710300, + 1735711200, + 1735712100, + 1735713000, + 1735713900, + 1735714800, + 1735715700, + 1735716600, + 1735717500, + 1735718400, + 1735719300, + 1735720200, + 1735721100, + 1735722000, + 1735722900, + 1735723800, + 1735724700, + 1735725600, + 1735726500, + 1735727400, + 1735728300, + 1735729200, + 1735730100, + 1735731000, + 1735731900, + 1735732800, + 1735733700, + 1735734600, + 1735735500, + 1735736400, + 1735737300, + 1735738200, + 1735739100, + 1735740000, + 1735740900, + 1735741800, + 1735742700, + 1735743600, + 1735744500, + 1735745400, + 1735746300, + 1735747200, + 1735748100, + 1735749000, + 1735749900, + 1735750800, + 1735751700, + 1735752600, + 1735753500, + 1735754400, + 1735755300, + 1735756200, + 1735757100, + 1735758000, + 1735758900, + 1735759800, + 1735760700, + 1735761600, + 1735762500, + 1735763400, + 1735764300, + 1735765200, + 1735766100, + 1735767000, + 1735767900, + 1735768800, + 1735769700, + 1735770600, + 1735771500 + ], + "ren_share": [ + 100.7, + 102.5, + 105.2, + 107.3, + 109.6, + 110.9, + 112.3, + 114.1, + 115.4, + 117, + 117.6, + 117.7, + 116.4, + 116.1, + 117.1, + 117.2, + 118.1, + 119, + 118.7, + 118.1, + 117.3, + 116.7, + 118.8, + 118.6, + 121.3, + 120.8, + 119.9, + 119, + 117.6, + 116.2, + 114.9, + 113.2, + 111.5, + 111, + 109.5, + 110.2, + 108.4, + 108.4, + 109.3, + 110.9, + 111.6, + 112.7, + 114.8, + 115.8, + 116.3, + 116.3, + 117.1, + 118.3, + 119.3, + 120.5, + 120.6, + 121, + 121, + 122, + 121.8, + 121.5, + 120.1, + 119.4, + 118.5, + 117.4, + 116.5, + 114.7, + 112.9, + 110.9, + 108.6, + 107.3, + 106.5, + 105.6, + 105.6, + 104.9, + 103.6, + 103.5, + 102.6, + 102, + 102, + 102.2, + 101.3, + 102.8, + 103.1, + 103.7, + 104.5, + 105.4, + 106.2, + 106.4, + 106.7, + 106.4, + 106.3, + 105.7, + 101.2, + 101.1, + 100.6, + 100.7, + 101.4, + 101.8, + 102, + 102.6 + ], + "solar_share": [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0.1, + 0.7, + 2.1, + 4.1, + 6.2, + 8.3, + 10.5, + 12.7, + 14.7, + 16.6, + 18.6, + 20.3, + 21.7, + 22.8, + 23.8, + 24.7, + 25.2, + 25.5, + 25.3, + 24.8, + 24, + 23.1, + 21.8, + 20.2, + 18.4, + 16.4, + 14.3, + 12, + 9.7, + 7.5, + 5.3, + 3.2, + 1.4, + 0.4, + 0.1 + ], + "wind_onshore_share": [ + 82.4, + 84.2, + 85.8, + 87.5, + 89.3, + 90.3, + 91.5, + 93, + 93.9, + 95.2, + 95.7, + 95.9, + 95.9, + 95.7, + 96.5, + 96.7, + 96.8, + 97.7, + 97.6, + 97.3, + 97, + 96.6, + 98.4, + 98.2, + 101.1, + 100.7, + 100.1, + 99.3, + 98.2, + 97.1, + 96.1, + 94.7, + 93.3, + 92.4, + 90.1, + 89.1, + 86, + 84.3, + 83.3, + 82.8, + 81.7, + 81, + 81.1, + 80.6, + 79.9, + 79, + 78.8, + 79.1, + 79.5, + 80.2, + 80.5, + 81.2, + 82, + 83.5, + 84.4, + 85.4, + 85.6, + 86.5, + 87.3, + 87.9, + 88.8, + 89.1, + 89.4, + 89.4, + 89.2, + 88.9, + 88.6, + 87.9, + 87.1, + 86.7, + 85.6, + 85.7, + 85, + 84.6, + 84.6, + 84.8, + 84.1, + 85.3, + 85.6, + 86, + 86.6, + 87.4, + 88.1, + 88.2, + 88.2, + 87.8, + 87.4, + 86.8, + 82.6, + 82.2, + 81.6, + 81.5, + 81.7, + 81.8, + 81.8, + 82 + ], + "wind_offshore_share": [ + 6, + 6.2, + 7.2, + 7.4, + 7.7, + 7.9, + 8, + 8.2, + 8.5, + 8.6, + 8.6, + 8.7, + 7.4, + 7.3, + 7.4, + 7.4, + 8.2, + 8.1, + 8, + 7.9, + 7.5, + 7.4, + 7.5, + 7.4, + 7.3, + 7.2, + 7.1, + 7, + 6.9, + 6.8, + 6.6, + 6.4, + 6.2, + 6.1, + 5.9, + 5.7, + 5.4, + 5.2, + 5.1, + 5, + 4.9, + 4.9, + 4.9, + 4.8, + 4.7, + 4.7, + 4.7, + 4.7, + 4.7, + 4.8, + 4.9, + 5, + 5.1, + 5.3, + 5.4, + 5.6, + 5.8, + 6.2, + 6.6, + 7.1, + 7.5, + 7.6, + 7.8, + 7.9, + 7.6, + 7.5, + 7.5, + 7.4, + 8.4, + 8.2, + 8.1, + 8, + 7.9, + 7.7, + 7.7, + 7.6, + 7.5, + 7.6, + 7.6, + 7.6, + 7.7, + 7.7, + 7.7, + 7.6, + 7.9, + 8, + 8.1, + 8.1, + 8, + 8.2, + 8.3, + 8.4, + 8.6, + 8.9, + 9, + 9.2 + ], + "substitute": false, + "deprecated": false + } \ No newline at end of file diff --git a/test_time_slots.py b/test_time_slots.py index a76183e..417a670 100644 --- a/test_time_slots.py +++ b/test_time_slots.py @@ -1,4 +1,5 @@ import euemastobot as bot +import json def test_timeslot_without_threshold(): forecast = _create_forecast_object([50, 60, 30]) @@ -40,6 +41,19 @@ def test_timeslot_with_threshold_at_start_and_end(): result = bot.get_slots_from_forecast(forecast) print(result) assert len(result) == 2 + + +def test_real_forecasts_from_api_whole_day(): + with open("test_data/whole_day_above_threshold.json", "r") as file: + forecast = json.load(file) + slots = bot.get_slots_from_forecast(forecast) + assert len(slots) == 1 + +def test_real_forecasts_from_api_two_slots(): + with open("test_data/two_slots_ending_the_day.json", "r") as file: + forecast = json.load(file) + slots = bot.get_slots_from_forecast(forecast) + assert len(slots) == 2 def _create_forecast_object(percentages): # skipping objects solar_share, wind_onshore_share and wind_offshore_share From 86e4e912ea3a45788aae96c2be71a77948ff8019 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20Gilli=C3=9Fen?= Date: Wed, 1 Jan 2025 14:12:50 +0100 Subject: [PATCH 5/7] ci: add pytest to CI build --- .github/workflows/python-app.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 8d17abc..b6869f7 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -31,3 +31,6 @@ jobs: - name: Lint with ruff run: pipenv run ruff check + + - name: Test with pytest + run: pipenv run pytest From be14830109c4342c32e64f8c180cd63fb7bae336 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20Gilli=C3=9Fen?= Date: Wed, 1 Jan 2025 14:13:18 +0100 Subject: [PATCH 6/7] style: reformatted test file --- test_time_slots.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/test_time_slots.py b/test_time_slots.py index 417a670..38110c8 100644 --- a/test_time_slots.py +++ b/test_time_slots.py @@ -1,47 +1,54 @@ import euemastobot as bot import json + def test_timeslot_without_threshold(): forecast = _create_forecast_object([50, 60, 30]) result = bot.get_slots_from_forecast(forecast) assert len(result) == 0 - + + def test_timeslot_with_threshold(): forecast = _create_forecast_object([50, 110, 30]) result = bot.get_slots_from_forecast(forecast) print(result) assert len(result) == 1 + def test_timeslot_with_threshold_100(): forecast = _create_forecast_object([50, 100, 30]) result = bot.get_slots_from_forecast(forecast) print(result) assert len(result) == 0 + def test_timeslot_with_two_slots(): forecast = _create_forecast_object([50, 110, 20, 130, 30]) result = bot.get_slots_from_forecast(forecast) print(result) assert len(result) == 2 + def test_timeslot_with_threshold_at_start(): forecast = _create_forecast_object([110, 20, 30, 30]) result = bot.get_slots_from_forecast(forecast) print(result) assert len(result) == 1 + def test_timeslot_with_threshold_at_end(): forecast = _create_forecast_object([30, 20, 30, 30, 110]) result = bot.get_slots_from_forecast(forecast) print(result) assert len(result) == 1 + def test_timeslot_with_threshold_at_start_and_end(): forecast = _create_forecast_object([110, 20, 30, 30, 110]) result = bot.get_slots_from_forecast(forecast) print(result) assert len(result) == 2 - + def test_real_forecasts_from_api_whole_day(): with open("test_data/whole_day_above_threshold.json", "r") as file: @@ -49,20 +56,22 @@ def test_real_forecasts_from_api_whole_day(): slots = bot.get_slots_from_forecast(forecast) assert len(slots) == 1 + def test_real_forecasts_from_api_two_slots(): with open("test_data/two_slots_ending_the_day.json", "r") as file: forecast = json.load(file) slots = bot.get_slots_from_forecast(forecast) assert len(slots) == 2 + def _create_forecast_object(percentages): # skipping objects solar_share, wind_onshore_share and wind_offshore_share # Unix seconds resolution is 900 timestamp_start = 1734735600 result = { - "unix_seconds": [ x*900 + timestamp_start for x in range(0,len(percentages))], + "unix_seconds": [x * 900 + timestamp_start for x in range(0, len(percentages))], "ren_share": percentages, "substitute": False, - "deprecated": False + "deprecated": False, } - return result \ No newline at end of file + return result From 8fcc2638d7aaa2db54ba9a77295e6abdc8611ba7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20Gilli=C3=9Fen?= Date: Wed, 1 Jan 2025 14:20:19 +0100 Subject: [PATCH 7/7] ci: only test against 3.11 and higher --- .github/workflows/python-app.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index b6869f7..c0bbe13 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -15,7 +15,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] + python-version: ["3.11", "3.12", "3.13"] steps: - uses: actions/checkout@v4