generated from SABS-R3/software-engineering-projects-pk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test file to test if the plot_data function defined in plot_function.…
…py raises any errors, plots a figure object and the axes labels are correct.
- Loading branch information
1 parent
e40d5eb
commit 5433190
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Test file for the plots.py plot_data function | ||
import pytest | ||
import matplotlib.pyplot as plt | ||
|
||
from pkmodel.plot_function import plot_data | ||
|
||
#Define a fixture to set up sample data for the following tests | ||
|
||
|
||
def test_no_error_raised(): | ||
#Test the plot runs without an error" | ||
|
||
t = range(0, 10) | ||
qp = range(10, 20) | ||
qc = range(20, 30) | ||
|
||
#Run the plot function, test no exceptions (errors) raised | ||
try: | ||
fig = plot_data(t, qp, qc) | ||
except Exception as e: | ||
pytest.fail(f"plot_data raised an exception: {e}") | ||
|
||
|
||
def test_figure_returned(): | ||
#Test plot_data produces a figure | ||
|
||
t = range(0, 10) | ||
qp = range(10, 20) | ||
qc = range(20, 30) | ||
|
||
#Run the plot function and assert if return is a figure object | ||
fig = plot_data(t, qp, qc) | ||
assert isinstance(fig, plt.Figure), "plot_data did not return a Figure object" | ||
|
||
|
||
|
||
def test_labels_correct(): | ||
#Test the figure axes are correctly labelled | ||
|
||
t = range(0, 10) | ||
qp = range(10, 20) | ||
qc = range(20, 30) | ||
|
||
xlabel = "time [h]" | ||
ylabel = "drug mass [ng]" | ||
|
||
fig = plot_data(t, qp, qc) | ||
|
||
#extract axis object | ||
ax = fig.gca() | ||
|
||
#assert the labels are correct | ||
assert ax.get_xlabel() == xlabel | ||
assert ax.get_ylabel() == ylabel | ||
|
||
|