Skip to content

Commit

Permalink
close figure plots after tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jdebacker committed Sep 1, 2024
1 parent 94ddb84 commit b6997b6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ogcore/parameter_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def plot_imm_rates(
"""
# create line styles to cycle through
fig, ax = plt.subplots(layout="constrained")
fig, ax = plt.subplots()
for y in years_to_plot:
i = start_year - y
plt.plot(imm_rates[i, :], c="blue", label="Year " + str(y))
Expand All @@ -49,7 +49,7 @@ def plot_imm_rates(
"Source: " + source,
fontsize=9,
)
# plt.tight_layout(rect=(0, 0.035, 1, 1))
plt.tight_layout(rect=(0, 0.035, 1, 1))
if include_title:
plt.title("Immigration Rates")
# Save or return figure
Expand Down
17 changes: 17 additions & 0 deletions tests/test_parameter_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import os
import sys
import numpy as np
import matplotlib.pyplot as plt
import scipy.interpolate as si
import matplotlib.image as mpimg
from ogcore import utils, parameter_plots, Specifications
Expand Down Expand Up @@ -74,13 +75,15 @@ def test_plot_imm_rates_save_fig(tmpdir):
def test_plot_mort_rates():
fig = parameter_plots.plot_mort_rates([base_params], include_title=True)
assert fig
plt.close()


def test_plot_surv_rates():
fig = parameter_plots.plot_mort_rates(
[base_params], survival_rates=True, include_title=True
)
assert fig
plt.close()


def test_plot_mort_rates_save_fig(tmpdir):
Expand All @@ -104,6 +107,7 @@ def test_plot_pop_growth():
base_params, start_year=int(base_params.start_year), include_title=True
)
assert fig
plt.close()


def test_plot_pop_growth_rates_save_fig(tmpdir):
Expand All @@ -119,6 +123,7 @@ def test_plot_ability_profiles():
p = Specifications()
fig = parameter_plots.plot_ability_profiles(p, p2=p, include_title=True)
assert fig
plt.close()


def test_plot_log_ability_profiles():
Expand All @@ -127,6 +132,7 @@ def test_plot_log_ability_profiles():
p, p2=p, log_scale=True, include_title=True
)
assert fig
plt.close()


def test_plot_ability_profiles_save_fig(tmpdir):
Expand All @@ -144,6 +150,7 @@ def test_plot_elliptical_u():
)
assert fig1
assert fig2
plt.close()


def test_plot_elliptical_u_save_fig(tmpdir):
Expand All @@ -157,6 +164,7 @@ def test_plot_chi_n():
p = Specifications()
fig = parameter_plots.plot_chi_n([p], include_title=True)
assert fig
plt.close()


def test_plot_chi_n_save_fig(tmpdir):
Expand All @@ -177,6 +185,7 @@ def test_plot_population(years_to_plot):
base_params, years_to_plot=years_to_plot, include_title=True
)
assert fig
plt.close()


def test_plot_population_save_fig(tmpdir):
Expand Down Expand Up @@ -215,6 +224,7 @@ def test_plot_fert_rates():
fert_rates = np.random.uniform(size=totpers).reshape((1, totpers))
fig = parameter_plots.plot_fert_rates([fert_rates], include_title=True)
assert fig
plt.close()


def test_plot_fert_rates_save_fig(tmpdir):
Expand Down Expand Up @@ -258,6 +268,7 @@ def test_plot_g_n():
p = Specifications()
fig = parameter_plots.plot_g_n([p], include_title=True)
assert fig
plt.close()


def test_plot_g_n_savefig(tmpdir):
Expand All @@ -276,6 +287,7 @@ def test_plot_mort_rates_data():
path=None,
)
assert fig
plt.close()


def test_plot_mort_rates_data_save_fig(tmpdir):
Expand All @@ -300,6 +312,7 @@ def test_plot_omega_fixed():
age_per_EpS, omega_SS_orig, omega_SSfx, E, S
)
assert fig
plt.close()


def test_plot_omega_fixed_save_fig(tmpdir):
Expand All @@ -326,6 +339,7 @@ def test_plot_imm_fixed():
age_per_EpS, imm_rates_orig, imm_rates_adj, E, S
)
assert fig
plt.close()


def test_plot_imm_fixed_save_fig(tmpdir):
Expand Down Expand Up @@ -360,6 +374,7 @@ def test_plot_population_path():
S,
)
assert fig
plt.close()


def test_plot_population_path_save_fig(tmpdir):
Expand Down Expand Up @@ -398,6 +413,7 @@ def test_plot_income_data():
fig = parameter_plots.plot_income_data(ages, abil_midp, abil_pcts, emat)

assert fig
plt.close()


def test_plot_income_data_save_fig(tmpdir):
Expand Down Expand Up @@ -481,6 +497,7 @@ def test_plot_2D_taxfunc(
)

assert fig
plt.close()
else:
assert True

Expand Down

0 comments on commit b6997b6

Please sign in to comment.