Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jrob93 committed Nov 19, 2024
1 parent de749fa commit a7e0d47
Showing 1 changed file with 72 additions and 3 deletions.
75 changes: 72 additions & 3 deletions tests/adler/utilities/test_plotting_utilities.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import pytest
import matplotlib
import os
from numpy.testing import assert_array_almost_equal

from adler.objectdata.AdlerPlanetoid import AdlerPlanetoid
from adler.utilities.tests_utilities import get_test_data_filepath
Expand All @@ -13,17 +15,84 @@
)


def test_plot_errorbar_return(planetoid=test_planetoid, filt_list=["r"]):
def test_plot_errorbar_return():

# make the fig object
fig = plot_errorbar(planetoid, filt_list=filt_list)
fig = plot_errorbar(test_planetoid, filt_list=["r"])
print(isinstance(fig, matplotlib.figure.Figure))

# check that fig is of the correct type
assert isinstance(fig, matplotlib.figure.Figure)


def test_plot_errorbar_file(tmp_path):

# define a pytest tmp_path
filename = "{}/test_file.png".format(tmp_path)

# make the fig object
fig = plot_errorbar(test_planetoid, filt_list=["r"], filename=filename)
print(os.path.isfile(filename))

# check that the file exists
assert os.path.isfile(filename)


def test_plot_errorbar_xy_label():

# make the fig object
x_plot = "midPointMjdTai"
y_plot = "mag"
fig = plot_errorbar(test_planetoid, filt_list=["r"], y_plot=y_plot, x_plot=x_plot)

# check the labels have been set
assert fig.gca().get_xlabel() == x_plot
assert fig.gca().get_ylabel() == y_plot

# get the object data
obs_filt = test_planetoid.observations_in_filter("r")
x = getattr(obs_filt, x_plot)
y = getattr(obs_filt, y_plot)

# check the correct data has been plotted
x_fig = fig.gca().lines[0].get_xdata()
y_fig = fig.gca().lines[0].get_ydata()
assert_array_almost_equal(x_fig, x)
assert_array_almost_equal(y_fig, y)


def test_plot_errorbar_fig():

# make the fig object
fig = plot_errorbar(test_planetoid, filt_list=["r"])
# add to the first fig object
fig = plot_errorbar(test_planetoid, filt_list=["g"], fig=fig)
print(fig.gca().lines)
# check that there are two sets of data plotted
assert len(fig.gca().lines) == 2


def test_plot_errorbar_legend():

# make the fig object
fig = plot_errorbar(test_planetoid, filt_list=["r", "g"], label_list=["r", "g"])

# make the legend
ax1 = fig.gca()
ax1.legend()

# check the legend labels
assert ax1.get_legend_handles_labels()[1] == ["r", "g"]


# TODO: test no xerr_plot
# TODO: test col_list

if __name__ == "__main__":
print(test_planetoid.__dict__)

test_plot_errorbar_return()
# test_plot_errorbar_return()
# test_plot_errorbar_file(".")
# test_plot_errorbar_xy_label()
# test_plot_errorbar_fig()
test_plot_errorbar_legend()

0 comments on commit a7e0d47

Please sign in to comment.