Skip to content

Commit

Permalink
Add test and isort
Browse files Browse the repository at this point in the history
  • Loading branch information
berroar committed Feb 12, 2024
1 parent 76a44a7 commit 8e2c2d1
Show file tree
Hide file tree
Showing 16 changed files with 74 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
include = scripts/*

[report]
fail_under = 10
fail_under = 80
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ flake8:
pipenv run flake8 --max-complexity 10 --count

format:
pipenv run isort .
pipenv run black .

run:
Expand Down
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ name = "pypi"
[dev-packages]
black = "*"
"flake8" = "*"
isort = "*"

[packages]
haralyzer = "*"
Expand Down
35 changes: 22 additions & 13 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion locustfile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

from locust import constant, HttpUser
from locust import HttpUser, constant

from runner_benchmark.taskset import SurveyRunnerTaskSet

Expand Down
2 changes: 1 addition & 1 deletion runner_benchmark/taskset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
3 changes: 2 additions & 1 deletion runner_benchmark/token_generator.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion runner_benchmark/utils.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
2 changes: 1 addition & 1 deletion scripts/get_aggregated_summary.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/get_benchmark_results.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/google_cloud_storage.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
import json
import os

from google.cloud import storage

Expand Down
45 changes: 26 additions & 19 deletions scripts/visualise_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_benchmark_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_get_aggregated_summary.py
Original file line number Diff line number Diff line change
@@ -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,
)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_get_summary.py
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
14 changes: 12 additions & 2 deletions tests/test_visualise_results.py
Original file line number Diff line number Diff line change
@@ -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]}
Expand Down Expand Up @@ -34,11 +36,19 @@ 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")
mock_plot_data(dataframe, 1)

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")

0 comments on commit 8e2c2d1

Please sign in to comment.