-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f66ad15
commit 6892a25
Showing
1 changed file
with
26 additions
and
21 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 |
---|---|---|
@@ -1,38 +1,43 @@ | ||
"""Test transect.""" | ||
|
||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from gliderpy.fetchers import GliderDataFetcher | ||
import matplotlib.pyplot as plt | ||
from pathlib import Path | ||
from gliderpy.plotting import plot_track, plot_transect | ||
from gliderpy.fetchers import GliderDataFetcher | ||
|
||
root = Path(__file__).parent | ||
|
||
|
||
@pytest.mark.mpl_image_compare(baseline_dir=root.joinpath("baseline/")) | ||
def test_plot_track(): | ||
"""Image comparison test for plot_track.""" | ||
@pytest.fixture | ||
def glider_data(): | ||
glider_grab = GliderDataFetcher() | ||
|
||
glider_grab.fetcher.dataset_id = "whoi_406-20160902T1700" | ||
df = glider_grab.to_pandas() | ||
# Generate the plot | ||
fig, ax = plot_track(df) | ||
return df | ||
|
||
@pytest.mark.mpl_image_compare(baseline_dir=root.joinpath("baseline/")) | ||
def test_plot_track(glider_data): | ||
# Generate the plot | ||
fig, ax = plot_track(glider_data) | ||
# Return the figure for pytest-mpl to compare | ||
return fig | ||
|
||
|
||
@pytest.mark.mpl_image_compare(baseline_dir=root.joinpath("baseline/")) | ||
def test_plot_transect(): | ||
"""Image comparison test for plot_transect.""" | ||
glider_grab = GliderDataFetcher() | ||
|
||
glider_grab.fetcher.dataset_id = "whoi_406-20160902T1700" | ||
df = glider_grab.to_pandas() | ||
def test_plot_transect(glider_data): | ||
# Generate the plot | ||
fig, ax = plot_transect(df, "temperature") | ||
fig, ax = plot_transect(glider_data, 'temperature') | ||
# Return the figure for pytest-mpl to compare | ||
return fig | ||
|
||
@pytest.mark.mpl_image_compare(baseline_dir=root.joinpath("baseline/")) | ||
def test_plot_transect_multiple_figures(glider_data): | ||
# Generate the plot with multiple figures | ||
fig, (ax0, ax1) = plt.subplots(figsize=(15, 9), nrows=2, sharex=True, sharey=True) | ||
glider_data.plot_transect(var="temperature", ax=ax0) | ||
glider_data.plot_transect(var="salinity", ax=ax1, cmap='cividis') | ||
# Return the figure for pytest-mpl to compare | ||
return fig | ||
|
||
def test_plot_transect_size(glider_data): | ||
# Generate the plot with a specific size | ||
fig, ax = plt.subplots(figsize=(15, 9)) | ||
glider_data.plot_transect(var="temperature", ax=ax) | ||
assert fig.get_size_inches() == pytest.approx([15., 9.]) |