diff --git a/.coveragerc b/.coveragerc index 6e1c1622..c135d532 100644 --- a/.coveragerc +++ b/.coveragerc @@ -2,4 +2,4 @@ include = scripts/* [report] -fail_under = 10 +fail_under = 80 diff --git a/Makefile b/Makefile index fec0ffb1..46e0d153 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ flake8: pipenv run flake8 --max-complexity 10 --count format: + pipenv run isort . pipenv run black . run: diff --git a/Pipfile b/Pipfile index c424b849..9ac3cc7b 100644 --- a/Pipfile +++ b/Pipfile @@ -6,6 +6,7 @@ name = "pypi" [dev-packages] black = "*" "flake8" = "*" +isort = "*" [packages] haralyzer = "*" diff --git a/Pipfile.lock b/Pipfile.lock index 94684c45..6fed104d 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "6ece805f0428e49ad7f89de9aacdd30cc0dae06d08fcd671945a9a655d849587" + "sha256": "bdbf862417c21dff32567aed2eef4245a1d3cb98b0e9e50d8dac0f5b3d756e28" }, "pipfile-spec": 6, "requires": { @@ -1092,7 +1092,7 @@ "sha256:fd096eb7ffef17c456cfa587523c5f92321ae02427ff955bebe9e3c63bc9f0da", "sha256:fe754d231288e1e64323cfad462fcee8f0288654c10bdf4f603a39ed923bef33" ], - "markers": "platform_python_implementation == 'CPython' and python_version < '3.11'", + "markers": "python_version < '3.11' and platform_python_implementation == 'CPython'", "version": "==3.0.3" }, "haralyzer": { @@ -1255,12 +1255,12 @@ }, "locust": { "hashes": [ - "sha256:35ae933cf5692af07f1e7c210633c9dc8b0e4c0d1bbf3b4f7382110ac4dedc78", - "sha256:b8132159bc527825d5f8f0869e17b0014258b927b57d8e184a2badb596ba5e6f" + "sha256:6cc729729e5ebf5852fc9d845302cfcf0ab0132f198e68b3eb0c88b438b6a863", + "sha256:96013a460a4b4d6d4fd46c70e6ff1fd2b6e03b48ddb1b48d1513d3134ba2cecf" ], "index": "pypi", "markers": "python_version >= '3.8'", - "version": "==2.22.0" + "version": "==2.23.1" }, "markupsafe": { "hashes": [ @@ -1791,7 +1791,7 @@ "sha256:0123cacc1627ae19ddf3c27a5de5bd67ee4586fbdd6440d9748f8abb483d3e86", "sha256:961d03dc3453ebbc59dbdea9e4e11c5651520a876d0f4db161e8674aae935da9" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2'", + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==2.8.2" }, "pytz": { @@ -1989,18 +1989,18 @@ }, "setuptools": { "hashes": [ - "sha256:385eb4edd9c9d5c17540511303e39a147ce2fc04bc55289c322b9e5904fe2c05", - "sha256:be1af57fc409f93647f2e8e4573a142ed38724b8cdd389706a867bb4efcf1e78" + "sha256:850894c4195f09c4ed30dba56213bf7c3f21d86ed6bdaafb5df5972593bfc401", + "sha256:c054629b81b946d63a9c6e732bc8b2513a7c3ea645f11d0139a2191d735c60c6" ], "markers": "python_version >= '3.8'", - "version": "==69.0.3" + "version": "==69.1.0" }, "six": { "hashes": [ "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926", "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2'", + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==1.16.0" }, "slackclient": { @@ -2030,11 +2030,11 @@ }, "tzdata": { "hashes": [ - "sha256:aa3ace4329eeacda5b7beb7ea08ece826c28d761cda36e747cfbf97996d39bf3", - "sha256:dd54c94f294765522c77399649b4fefd95522479a664a0cec87f41bebc6148c9" + "sha256:2674120f8d891909751c38abcdfd386ac0a5a1127954fbc332af6b5ceae07efd", + "sha256:9068bc196136463f5245e51efda838afa15aaeca9903f49050dfa2679db4d252" ], "markers": "python_version >= '2'", - "version": "==2023.4" + "version": "==2024.1" }, "urllib3": { "hashes": [ @@ -2247,6 +2247,15 @@ "markers": "python_full_version >= '3.8.1'", "version": "==7.0.0" }, + "isort": { + "hashes": [ + "sha256:48fdfcb9face5d58a4f6dde2e72a1fb8dcaf8ab26f95ab49fab84c2ddefb0109", + "sha256:8ca5e72a8d85860d5a3fa69b8745237f2939afe12dbf656afbcb47fe72d947a6" + ], + "index": "pypi", + "markers": "python_full_version >= '3.8.0'", + "version": "==5.13.2" + }, "mccabe": { "hashes": [ "sha256:348e0240c33b60bbdf4e523192ef919f28cb2c3d7d5c7794f74009290f236325", diff --git a/locustfile.py b/locustfile.py index 2400de0f..5d045b68 100644 --- a/locustfile.py +++ b/locustfile.py @@ -1,6 +1,6 @@ import os -from locust import constant, HttpUser +from locust import HttpUser, constant from runner_benchmark.taskset import SurveyRunnerTaskSet diff --git a/runner_benchmark/taskset.py b/runner_benchmark/taskset.py index baa2df82..763bc777 100644 --- a/runner_benchmark/taskset.py +++ b/runner_benchmark/taskset.py @@ -6,9 +6,9 @@ from locust import TaskSet, task -from .utils import parse_params_from_location from .questionnaire_mixins import QuestionnaireMixins from .token_generator import create_token +from .utils import parse_params_from_location r = random.Random() diff --git a/runner_benchmark/token_generator.py b/runner_benchmark/token_generator.py index 2e6714b6..5c3addb1 100644 --- a/runner_benchmark/token_generator.py +++ b/runner_benchmark/token_generator.py @@ -1,7 +1,8 @@ import os import time -from uuid import uuid4 from datetime import datetime, timedelta, timezone +from uuid import uuid4 + from sdc.crypto.encrypter import encrypt from sdc.crypto.key_store import KeyStore diff --git a/runner_benchmark/utils.py b/runner_benchmark/utils.py index ea7050cd..b4bf20c8 100644 --- a/runner_benchmark/utils.py +++ b/runner_benchmark/utils.py @@ -1,4 +1,4 @@ -from urllib.parse import urlparse, parse_qs +from urllib.parse import parse_qs, urlparse def parse_params_from_location(url, route): diff --git a/scripts/get_aggregated_summary.py b/scripts/get_aggregated_summary.py index 85edf6bf..04509987 100644 --- a/scripts/get_aggregated_summary.py +++ b/scripts/get_aggregated_summary.py @@ -1,6 +1,6 @@ -from glob import glob import os import sys +from glob import glob from typing import List from scripts.benchmark_stats import BenchmarkStats diff --git a/scripts/get_benchmark_results.py b/scripts/get_benchmark_results.py index 94be1bcd..befedcc7 100644 --- a/scripts/get_benchmark_results.py +++ b/scripts/get_benchmark_results.py @@ -1,7 +1,7 @@ import os import sys - from datetime import datetime, timedelta + from dateutil.tz import tzutc from scripts.get_summary import parse_environment_variables diff --git a/scripts/google_cloud_storage.py b/scripts/google_cloud_storage.py index c5db24cb..8ac5c4a5 100644 --- a/scripts/google_cloud_storage.py +++ b/scripts/google_cloud_storage.py @@ -1,5 +1,5 @@ -import os import json +import os from google.cloud import storage diff --git a/scripts/visualise_results.py b/scripts/visualise_results.py index e0bf99dd..94a07ac8 100644 --- a/scripts/visualise_results.py +++ b/scripts/visualise_results.py @@ -8,26 +8,33 @@ PERCENTILES_TO_GRAPH = (50, 90, 95, 99) +class GraphGenerationFailed(Exception): + pass + + def plot_data(df, number_of_days_to_plot): - plt.style.use('fast') - - if ( - number_of_days_to_plot and number_of_days_to_plot <= 45 - ): # To make the chart still easily digestible - df.plot.line(marker="o", markersize=8) - plt.grid(True, axis="both", alpha=0.3) - else: - df.plot.line() - - plt.margins(0.03, 0.07) - plt.legend(frameon=True, prop={"size": 17}) - plt.xticks(df.index, df["DATE"], size="small", rotation=90) - plt.yticks(size="small") - plt.ylabel("Average Response Time (ms)") - plt.xlabel("Run Date (YYYY-MM-DD)", labelpad=13) - - plt.savefig('performance_graph.png', bbox_inches="tight") - print("Graph saved as performance_graph.png") + try: + plt.style.use('fast') + + if ( + number_of_days_to_plot and number_of_days_to_plot <= 45 + ): # To make the chart still easily digestible + df.plot.line(marker="o", markersize=8) + # plt.grid(True, axis="both", alpha=0.3) + else: + df.plot.line() + + plt.margins(0.03, 0.07) + plt.legend(frameon=True, prop={"size": 17}) + plt.xticks(df.index, df["DATE"], size="small", rotation=90) + plt.yticks(size="small") + plt.ylabel("Average Response Time (ms)") + plt.xlabel("Run Date (YYYY-MM-DD)", labelpad=13) + + plt.savefig('performance_graph.png', bbox_inches="tight") + print("Graph saved as performance_graph.png") + except Exception as e: + raise GraphGenerationFailed from e def get_data_frame(results): diff --git a/tests/test_benchmark_stats.py b/tests/test_benchmark_stats.py index 012bdcb2..43fc67c7 100644 --- a/tests/test_benchmark_stats.py +++ b/tests/test_benchmark_stats.py @@ -2,8 +2,8 @@ from scripts.benchmark_stats import BenchmarkStats from tests.conftest import ( - EXPECTED_OUTPUT_SINGLE_FOLDER, EXPECTED_OUTPUT_MULTIPLE_FOLDERS, + EXPECTED_OUTPUT_SINGLE_FOLDER, ) diff --git a/tests/test_get_aggregated_summary.py b/tests/test_get_aggregated_summary.py index 6d4f4f4f..48a93268 100644 --- a/tests/test_get_aggregated_summary.py +++ b/tests/test_get_aggregated_summary.py @@ -1,7 +1,7 @@ from scripts.get_aggregated_summary import get_results from tests.conftest import ( - EXPECTED_OUTPUT_SINGLE_FOLDER, EXPECTED_OUTPUT_MULTIPLE_FOLDERS, + EXPECTED_OUTPUT_SINGLE_FOLDER, ) diff --git a/tests/test_get_summary.py b/tests/test_get_summary.py index 22fb7d4a..83dd3207 100644 --- a/tests/test_get_summary.py +++ b/tests/test_get_summary.py @@ -1,8 +1,8 @@ import pytest +from freezegun import freeze_time from scripts.get_summary import get_results, parse_environment_variables from tests.conftest import EXPECTED_OUTPUT_SINGLE_FOLDER -from freezegun import freeze_time EXPECTED_OUTPUT_20240206_FOLDER = ( '---\n' diff --git a/tests/test_visualise_results.py b/tests/test_visualise_results.py index 06659f4b..f7cc2ae0 100644 --- a/tests/test_visualise_results.py +++ b/tests/test_visualise_results.py @@ -1,7 +1,9 @@ +import pytest from pandas import DataFrame from pandas.testing import assert_frame_equal + from scripts.get_summary import get_results -from scripts.visualise_results import get_data_frame +from scripts.visualise_results import GraphGenerationFailed, get_data_frame, plot_data expected_data_frame = DataFrame.from_dict( {"DATE": ["2024-02-07"], "50th": [58], "90th": [96], "95th": [173], "99th": [301]} @@ -34,7 +36,7 @@ def test_get_data_frame_multiple_files(): assert_frame_equal(dataframe, expected_data_frame_multiple_files) -def test_plot_data(mocker, get_results_single_file): +def test_plot_data_df(mocker, get_results_single_file): dataframe = get_data_frame(get_results_single_file) mock_plot_data = mocker.patch("scripts.visualise_results.plot_data") @@ -42,3 +44,11 @@ def test_plot_data(mocker, get_results_single_file): assert mock_plot_data.call_count == 1 assert_frame_equal(mock_plot_data.call_args[0][0], expected_data_frame) + + +def test_plot_data(get_results_single_file): + dataframe = get_data_frame(get_results_single_file) + try: + plot_data(dataframe, 1) + except GraphGenerationFailed: + pytest.fail("Graph generation failed")