Skip to content

Commit

Permalink
Update tests and format code
Browse files Browse the repository at this point in the history
  • Loading branch information
VirajP1002 committed Aug 2, 2024
1 parent 23f3703 commit 0d2533e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 17 deletions.
6 changes: 4 additions & 2 deletions scripts/visualise_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def plot_data(dataframes, number_of_days_to_plot):
for i in range(len(dataframes)):
plt.subplot(1, 2, i + 1)
if (
number_of_days_to_plot and number_of_days_to_plot <= 45
number_of_days_to_plot and number_of_days_to_plot <= 45
): # To make the chart still easily digestible
dataframes[i].plot.line(marker="o", markersize=8, ax=axes[i])
plt.grid(True, axis="both", alpha=0.3)
Expand All @@ -30,7 +30,9 @@ def plot_data(dataframes, number_of_days_to_plot):

plt.margins(0.03, 0.07)
plt.legend(frameon=True, prop={"size": 10})
plt.xticks(dataframes[i].index, dataframes[i]["DATE"], size="small", rotation=90)
plt.xticks(
dataframes[i].index, dataframes[i]["DATE"], size="small", rotation=90
)
plt.yticks(size="small")
plt.ylabel("Average Response Time (ms)")
plt.xlabel("Run Date (YYYY-MM-DD)", labelpad=13)
Expand Down
48 changes: 33 additions & 15 deletions tests/test_visualise_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
from scripts.get_summary import get_results
from scripts.visualise_results import (
GraphGenerationFailed,
get_data_frame,
get_data_frame_session_pdf,
plot_additional_metrics,
plot_performance_data,
create_graph,
get_additional_metrics_data_frame,
get_performance_data_frame,
)

expected_data_frame = DataFrame.from_dict(
Expand Down Expand Up @@ -41,10 +40,10 @@
@pytest.mark.parametrize(
"results_file_fixture, data_frame_method, expected_result",
(
("get_results_single_file", get_data_frame, expected_data_frame),
("get_results_single_file", get_performance_data_frame, expected_data_frame),
(
"get_results_single_file_with_pdf_endpoint",
get_data_frame_session_pdf,
get_additional_metrics_data_frame,
expected_data_frame_session_pdf,
),
),
Expand All @@ -64,15 +63,15 @@ def test_get_data_frame_single_file(
"./tests/mock_stats/2024-02-07T03:09:41",
"./tests/mock_stats/2024-02-06T03:09:41",
],
get_data_frame,
get_performance_data_frame,
expected_data_frame_multiple_files,
),
(
[
"./tests/mock_stats/2024-07-25T03:09:41",
"./tests/mock_stats/2024-07-29T03:09:41",
],
get_data_frame_session_pdf,
get_additional_metrics_data_frame,
expected_data_frame_multiple_files_session_pdf,
),
),
Expand All @@ -84,7 +83,7 @@ def test_get_data_frame_multiple_files(folders, data_frame_method, expected_resu


def test_plot_data_df(mocker, get_results_single_file):
dataframe = get_data_frame(get_results_single_file)
dataframe = get_performance_data_frame(get_results_single_file)

mock_plot_data = mocker.patch("scripts.visualise_results.plot_data")
mock_plot_data(dataframe, 1)
Expand All @@ -94,20 +93,22 @@ def test_plot_data_df(mocker, get_results_single_file):


def test_plot_performance_data(mocker, get_results_single_file):
dataframe = get_data_frame(get_results_single_file)
dataframe = get_performance_data_frame(get_results_single_file)
try:
graph_output = mocker.patch("matplotlib.pyplot.savefig")
plot_performance_data(dataframe, 1)
create_graph([dataframe], 1, "performance_graph.png")
assert graph_output.call_count == 1
except GraphGenerationFailed:
pytest.fail("Graph generation failed")


def test_plot_additional_metrics(mocker, get_results_single_file_with_pdf_endpoint):
dataframe = get_data_frame(get_results_single_file_with_pdf_endpoint)
dataframe = get_additional_metrics_data_frame(
get_results_single_file_with_pdf_endpoint
)
try:
graph_output = mocker.patch("matplotlib.pyplot.savefig")
plot_additional_metrics(dataframe, 1)
create_graph([dataframe], 1, "additional_metrics.png")
assert graph_output.call_count == 1
except GraphGenerationFailed:
pytest.fail("Graph generation failed")
Expand All @@ -116,10 +117,27 @@ def test_plot_additional_metrics(mocker, get_results_single_file_with_pdf_endpoi
def test_plot_performance_data_failed():
dataframe = DataFrame.from_dict({})
with pytest.raises(GraphGenerationFailed):
plot_performance_data(dataframe, 1)
create_graph([dataframe], 1, "performance_graph.png")


def test_plot_additional_metrics_failed():
dataframe = DataFrame.from_dict({})
with pytest.raises(GraphGenerationFailed):
plot_additional_metrics(dataframe, 1)
create_graph([dataframe], 1, "additional_metrics.png")


def test_create_graph(
mocker, get_results_single_file_with_pdf_endpoint, get_results_single_file
):
metrics_dataframe = get_additional_metrics_data_frame(
get_results_single_file_with_pdf_endpoint
)
performance_data_frame = get_performance_data_frame(get_results_single_file)
try:
graph_output = mocker.patch("matplotlib.pyplot.savefig")
create_graph(
[metrics_dataframe, performance_data_frame], 1, "additional_metrics.png"
)
assert graph_output.call_count == 1
except GraphGenerationFailed:
pytest.fail("Graph generation failed")

0 comments on commit 0d2533e

Please sign in to comment.