Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added skip to handle tests that need matplotlib and/or pydocstyle when not installed #1062

Merged
merged 6 commits into from
Apr 30, 2024
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions dymos/examples/brachistochrone/doc/test_doc_brachistochrone.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import os
import unittest

import matplotlib
import matplotlib.pyplot as plt

from openmdao.utils.testing_utils import use_tempdirs, require_pyoptsparse
try:
import matplotlib
import matplotlib.pyplot as plt

matplotlib.use('Agg')
plt.style.use('ggplot')
except ImportError:
matplotlib = None

matplotlib.use('Agg')
plt.style.use('ggplot')
from openmdao.utils.testing_utils import use_tempdirs, require_pyoptsparse


@use_tempdirs
@@ -47,6 +49,7 @@ def test_brachistochrone_partials(self):
cpd = p.check_partials(method='cs', compact_print=True)
assert_check_partials(cpd)

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_brachistochrone_for_docs_gauss_lobatto(self):
import openmdao.api as om
from openmdao.utils.assert_utils import assert_near_equal
@@ -129,6 +132,7 @@ def test_brachistochrone_for_docs_gauss_lobatto(self):

plt.show()

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_brachistochrone_for_docs_radau(self):
import openmdao.api as om
from openmdao.utils.assert_utils import assert_near_equal
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import os
import unittest

import matplotlib
import matplotlib.pyplot as plt
try:
import matplotlib
import matplotlib.pyplot as plt

from openmdao.utils.testing_utils import use_tempdirs
matplotlib.use('Agg')
plt.style.use('ggplot')
except ImportError:
matplotlib = None


matplotlib.use('Agg')
plt.style.use('ggplot')
from openmdao.utils.testing_utils import use_tempdirs


@use_tempdirs
@@ -47,6 +50,7 @@ def test_brachistochrone_partials(self):
cpd = p.check_partials(method='cs', compact_print=True)
assert_check_partials(cpd)

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_brachistochrone_static_gravity(self):
import openmdao.api as om
from openmdao.utils.assert_utils import assert_near_equal
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import unittest

try:
import matplotlib
except ImportError:
matplotlib = None

import numpy as np
import openmdao.api as om
from openmdao.utils.testing_utils import use_tempdirs, require_pyoptsparse
@@ -47,6 +52,7 @@ def compute_partials(self, inputs, jacobian):
class TestBrachistochroneTandemPhases(unittest.TestCase):

@require_pyoptsparse(optimizer='SLSQP')
@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_brachistochrone_tandem_phases(self):
from dymos.examples.brachistochrone.brachistochrone_ode import BrachistochroneODE

Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import unittest

try:
import matplotlib
except ImportError:
matplotlib = None

from openmdao.utils.testing_utils import use_tempdirs


@use_tempdirs
class TestBrachistochroneUpstreamControl(unittest.TestCase):

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_brachistochrone_upstream_control(self):
import numpy as np
import openmdao.api as om
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import unittest

try:
import matplotlib
except ImportError:
matplotlib = None

from openmdao.utils.testing_utils import use_tempdirs


@use_tempdirs
class TestBrachistochroneUpstreamState(unittest.TestCase):

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_brachistochrone_upstream_state(self):
import openmdao.api as om
from openmdao.utils.assert_utils import assert_near_equal
Original file line number Diff line number Diff line change
@@ -2,6 +2,11 @@

import numpy as np

try:
import matplotlib
except ImportError:
matplotlib = None

import openmdao.api as om
from openmdao.utils.testing_utils import use_tempdirs

@@ -110,6 +115,7 @@ def compute_partials(self, inputs, partials):
@use_tempdirs
class TestBrachistochroneControlRateTargets(unittest.TestCase):

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_brachistochrone_control_rate_targets_gauss_lobatto(self):
import matplotlib.pyplot as plt
plt.switch_backend('Agg')
@@ -206,6 +212,7 @@ def test_brachistochrone_control_rate_targets_gauss_lobatto(self):

plt.show()

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_brachistochrone_control_rate_targets_radau(self):
import matplotlib.pyplot as plt
plt.switch_backend('Agg')
@@ -303,6 +310,7 @@ def test_brachistochrone_control_rate_targets_radau(self):
@use_tempdirs
class TestBrachistochroneExplicitControlRateTargets(unittest.TestCase):

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_brachistochrone_control_rate_targets_gauss_lobatto(self):
import matplotlib.pyplot as plt
plt.switch_backend('Agg')
@@ -396,6 +404,7 @@ def test_brachistochrone_control_rate_targets_gauss_lobatto(self):

plt.show()

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_brachistochrone_control_rate_targets_radau(self):
import matplotlib.pyplot as plt
plt.switch_backend('Agg')
@@ -494,6 +503,7 @@ def test_brachistochrone_control_rate_targets_radau(self):
@use_tempdirs
class TestBrachistochronePolynomialControlRateTargets(unittest.TestCase):

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_brachistochrone_polynomial_control_rate_targets_gauss_lobatto(self):
import matplotlib.pyplot as plt
plt.switch_backend('Agg')
@@ -587,6 +597,7 @@ def test_brachistochrone_polynomial_control_rate_targets_gauss_lobatto(self):

plt.show()

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_brachistochrone_polynomial_control_rate_targets_radau(self):
import matplotlib.pyplot as plt
plt.switch_backend('Agg')
@@ -685,6 +696,7 @@ def test_brachistochrone_polynomial_control_rate_targets_radau(self):
@use_tempdirs
class TestBrachistochronePolynomialControlExplicitRateTargets(unittest.TestCase):

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_brachistochrone_polynomial_control_rate_targets_gauss_lobatto(self):
import matplotlib.pyplot as plt
plt.switch_backend('Agg')
@@ -778,6 +790,7 @@ def test_brachistochrone_polynomial_control_rate_targets_gauss_lobatto(self):

plt.show()

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_brachistochrone_polynomial_control_rate_targets_radau(self):
import matplotlib.pyplot as plt
plt.switch_backend('Agg')
@@ -876,6 +889,7 @@ def test_brachistochrone_polynomial_control_rate_targets_radau(self):
@use_tempdirs
class TestBrachistochronePolynomialControlExplicitRate2Targets(unittest.TestCase):

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_brachistochrone_polynomial_control_rate_targets_gauss_lobatto(self):
import matplotlib.pyplot as plt
plt.switch_backend('Agg')
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import unittest

try:
import matplotlib
except ImportError:
matplotlib = None

from openmdao.utils.testing_utils import use_tempdirs


@use_tempdirs
class TestBrachistochroneExternalControl(unittest.TestCase):

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_brachistochrone_external_control(self):
import numpy as np
import openmdao.api as om
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import os
import unittest

try:
import matplotlib
except ImportError:
matplotlib = None

from openmdao.utils.testing_utils import use_tempdirs


@@ -13,6 +18,7 @@ def tearDownClass(cls):
if os.path.exists(filename):
os.remove(filename)

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_brachistochrone_recording(self):
import matplotlib
matplotlib.use('Agg')
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import os
import unittest

import matplotlib
import openmdao.api as om
import matplotlib.pyplot as plt
import dymos as dm

from openmdao.utils.testing_utils import use_tempdirs
from openmdao.utils.assert_utils import assert_near_equal
from dymos.examples.brachistochrone.brachistochrone_ode import BrachistochroneODE

matplotlib.use('Agg')
plt.style.use('ggplot')


@use_tempdirs
class TestBrachistochroneExprPathConstraint(unittest.TestCase):
Original file line number Diff line number Diff line change
@@ -2,6 +2,11 @@

import numpy as np

try:
import matplotlib
except ImportError:
matplotlib = None

import openmdao.api as om
from openmdao.utils.testing_utils import use_tempdirs

@@ -65,6 +70,7 @@ def compute_partials(self, inputs, jacobian):
@use_tempdirs
class TestBrachistochroneQuickStart(unittest.TestCase):

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_brachistochrone_quick_start(self):
import numpy as np
import openmdao.api as om
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
import os
import unittest

import matplotlib
import matplotlib.pyplot as plt

from openmdao.utils.testing_utils import use_tempdirs

import openmdao.api as om
import dymos as dm
from dymos.examples.brachistochrone.brachistochrone_ode import BrachistochroneODE


matplotlib.use('Agg')
plt.style.use('ggplot')


@use_tempdirs
class TestBrachistochroneStaticGravity(unittest.TestCase):

Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import unittest

import matplotlib
import matplotlib.pyplot as plt

import openmdao.api as om
from openmdao.utils.assert_utils import assert_near_equal
from openmdao.utils.testing_utils import use_tempdirs
@@ -12,10 +9,6 @@
import BrachistochroneVectorStatesODE


SHOW_PLOTS = True
matplotlib.use('Agg')


@use_tempdirs
class TestBrachistochroneVectorBoundaryConstraints(unittest.TestCase):

Original file line number Diff line number Diff line change
@@ -2,8 +2,6 @@

import numpy as np

import matplotlib.pyplot as plt

import openmdao.api as om
from openmdao.utils.assert_utils import assert_near_equal
from openmdao.utils.testing_utils import use_tempdirs
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import unittest

try:
import matplotlib
except ImportError:
matplotlib = None

from openmdao.utils.testing_utils import use_tempdirs


@use_tempdirs
class TestBrachistochronePolynomialControl(unittest.TestCase):

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_brachistochrone_polynomial_control_gauss_lobatto(self):
import matplotlib
matplotlib.use('Agg')
@@ -91,6 +97,7 @@ def test_brachistochrone_polynomial_control_gauss_lobatto(self):

plt.show()

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_brachistochrone_polynomial_control_radau(self):
import numpy as np
import matplotlib
@@ -177,6 +184,7 @@ def test_brachistochrone_polynomial_control_radau(self):

plt.show()

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_brachistochrone_polynomial_control_birkhoff(self):
import numpy as np
import matplotlib
@@ -274,6 +282,7 @@ def test_brachistochrone_polynomial_control_birkhoff(self):
@use_tempdirs
class TestBrachistochronePolynomialControlBoundaryConstrained(unittest.TestCase):

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_brachistochrone_polynomial_control_gauss_lobatto(self):
import matplotlib
matplotlib.use('Agg')
@@ -362,6 +371,7 @@ def test_brachistochrone_polynomial_control_gauss_lobatto(self):

plt.show()

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_brachistochrone_polynomial_control_radau(self):
import matplotlib
matplotlib.use('Agg')
@@ -450,6 +460,7 @@ def test_brachistochrone_polynomial_control_radau(self):

plt.show()

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_brachistochrone_polynomial_control_birkhoff(self):
import numpy as np
import matplotlib
@@ -550,6 +561,7 @@ def test_brachistochrone_polynomial_control_birkhoff(self):
@use_tempdirs
class TestBrachistochronePolynomialControlPathConstrained(unittest.TestCase):

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_brachistochrone_polynomial_control_gauss_lobatto(self):
import matplotlib.pyplot as plt
plt.switch_backend('Agg')
@@ -636,6 +648,7 @@ def test_brachistochrone_polynomial_control_gauss_lobatto(self):

plt.show()

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_brachistochrone_polynomial_control_radau(self):
import matplotlib.pyplot as plt
plt.switch_backend('Agg')
@@ -722,6 +735,7 @@ def test_brachistochrone_polynomial_control_radau(self):

plt.show()

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_brachistochrone_polynomial_control_birkhoff(self):
import numpy as np
import matplotlib
@@ -821,6 +835,7 @@ def test_brachistochrone_polynomial_control_birkhoff(self):
@use_tempdirs
class TestBrachistochronePolynomialControlRatePathConstrained(unittest.TestCase):

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_brachistochrone_polynomial_control_gauss_lobatto(self):
import numpy as np
import matplotlib
@@ -909,6 +924,7 @@ def test_brachistochrone_polynomial_control_gauss_lobatto(self):

plt.show()

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_brachistochrone_polynomial_control_radau(self):
import numpy as np
import matplotlib
@@ -997,6 +1013,7 @@ def test_brachistochrone_polynomial_control_radau(self):

plt.show()

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_brachistochrone_polynomial_control_birkhoff(self):
import numpy as np
import matplotlib
@@ -1096,6 +1113,7 @@ def test_brachistochrone_polynomial_control_birkhoff(self):
@use_tempdirs
class TestBrachistochronePolynomialControlRate2PathConstrained(unittest.TestCase):

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_brachistochrone_polynomial_control_gauss_lobatto(self):
import numpy as np
import matplotlib
@@ -1184,6 +1202,7 @@ def test_brachistochrone_polynomial_control_gauss_lobatto(self):

plt.show()

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_brachistochrone_polynomial_control_radau(self):
import numpy as np
import matplotlib
@@ -1272,6 +1291,7 @@ def test_brachistochrone_polynomial_control_radau(self):

plt.show()

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_brachistochrone_polynomial_control_birkhoff(self):
import numpy as np
import matplotlib
@@ -1485,6 +1505,7 @@ def test_brachistochrone_polynomial_control_radau(self):
assert_near_equal(theta_exp[0], theta_imp[0])
assert_near_equal(theta_exp[-1], theta_imp[-1])

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_brachistochrone_polynomial_control_birkhoff(self):
import numpy as np
import matplotlib
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import unittest
import matplotlib.pyplot as plt

try:
import matplotlib.pyplot as plt
plt.switch_backend('Agg')
except ImportError:
plt = None

from openmdao.utils.testing_utils import use_tempdirs
import openmdao.api as om
@@ -10,9 +15,6 @@
from dymos.examples.cannonball.cannonball_ode import CannonballODE


plt.switch_backend('Agg')


@use_tempdirs
class TestCannonballConnectedInitialStates(unittest.TestCase):

Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import unittest
import matplotlib.pyplot as plt

try:
import matplotlib.pyplot as plt
plt.switch_backend('Agg')
except ImportError:
plt = None

from openmdao.utils.testing_utils import use_tempdirs
import openmdao.api as om
@@ -10,9 +15,6 @@
from dymos.examples.cannonball.cannonball_ode import CannonballODE


plt.switch_backend('Agg')


@use_tempdirs
class TestCannonballBoundaryConstraint(unittest.TestCase):

10 changes: 6 additions & 4 deletions dymos/examples/cannonball/test/test_phase_linkage_compliance.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import unittest

import matplotlib.pyplot as plt
from openmdao.utils.testing_utils import use_tempdirs, require_pyoptsparse

try:
import matplotlib.pyplot as plt
plt.switch_backend('Agg')
except ImportError:
plt = None

plt.switch_backend('Agg')
from openmdao.utils.testing_utils import use_tempdirs, require_pyoptsparse


@use_tempdirs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import unittest

import matplotlib.pyplot as plt

from openmdao.utils.testing_utils import use_tempdirs, require_pyoptsparse

#
# plt.switch_backend('Agg')
import numpy as np
from scipy.interpolate import interp1d

Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import unittest

import matplotlib.pyplot as plt
from openmdao.utils.testing_utils import use_tempdirs, require_pyoptsparse

try:
import matplotlib.pyplot as plt
plt.switch_backend('Agg')
except ImportError:
plt = None

plt.switch_backend('Agg')
from openmdao.utils.testing_utils import use_tempdirs, require_pyoptsparse


@use_tempdirs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import os
import unittest

import matplotlib
import matplotlib.pyplot as plt

from openmdao.utils.testing_utils import use_tempdirs, require_pyoptsparse
try:
import matplotlib
import matplotlib.pyplot as plt

matplotlib.use('Agg')
plt.style.use('ggplot')
except ImportError:
matplotlib = None

matplotlib.use('Agg')
plt.style.use('ggplot')
from openmdao.utils.testing_utils import use_tempdirs, require_pyoptsparse


@use_tempdirs
@@ -21,6 +23,7 @@ def tearDownClass(cls):
os.remove(filename)

@require_pyoptsparse(optimizer='SLSQP')
@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_double_integrator_for_docs(self):
import matplotlib.pyplot as plt
import openmdao.api as om
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import unittest

import matplotlib.pyplot as plt

from openmdao.utils.testing_utils import use_tempdirs, require_pyoptsparse
try:
import matplotlib.pyplot as plt

plt.switch_backend('Agg')
plt.style.use('ggplot')
except ImportError:
plt = None

plt.switch_backend('Agg')
plt.style.use('ggplot')
from openmdao.utils.testing_utils import use_tempdirs, require_pyoptsparse


@use_tempdirs
class TestFiniteBurnOrbitRaise(unittest.TestCase):

@require_pyoptsparse(optimizer='IPOPT')
@unittest.skipIf(plt is None, "This test requires matplotlib")
def test_finite_burn_orbit_raise(self):
import numpy as np
import matplotlib.pyplot as plt
Original file line number Diff line number Diff line change
@@ -6,6 +6,11 @@

import numpy as np

try:
import matplotlib
except ImportError:
matplotlib = None

import openmdao.api as om
from openmdao.utils.testing_utils import require_pyoptsparse
from openmdao.utils.general_utils import set_pyoptsparse_opt
@@ -217,6 +222,7 @@ def test_bokeh_plots(self):
html_file = pathlib.Path(_get_reports_dir(p)) / 'traj_results_report.html'
self.assertTrue(html_file.exists(), msg=f'{html_file} does not exist!')

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_mpl_plots(self):
dm.options['plots'] = 'matplotlib'

Original file line number Diff line number Diff line change
@@ -4,8 +4,11 @@
from openmdao.utils.testing_utils import use_tempdirs, require_pyoptsparse
from dymos.utils.introspection import get_promoted_vars

import matplotlib.pyplot as plt
plt.switch_backend('Agg')
try:
import matplotlib.pyplot as plt
plt.switch_backend('Agg')
except ImportError:
plt = None


@require_pyoptsparse(optimizer='IPOPT')
@@ -235,6 +238,7 @@ def test_two_burn_orbit_raise_gl_radau_gl_equivalent_units_error(self):

p.setup(check=True, force_alloc_complex=True)

@unittest.skipIf(plt is None, "This test requires matplotlib")
def test_two_burn_orbit_raise_gl_radau_gl_constrained(self):
import numpy as np

@@ -453,6 +457,7 @@ def test_two_burn_orbit_raise_gl_radau_gl_constrained(self):

plt.show()

@unittest.skipIf(plt is None, "This test requires matplotlib")
def test_two_burn_orbit_raise_link_control_to_param(self):
import numpy as np

@@ -633,6 +638,7 @@ def test_two_burn_orbit_raise_link_control_to_param(self):
assert_near_equal(coast_u1_final - burn2_u1_initial, 0.0, 1e-12)

@use_tempdirs
@unittest.skipIf(plt is None, "This test requires matplotlib")
def test_two_burn_orbit_raise_gl_list_add_timeseries_output(self):
import numpy as np

Original file line number Diff line number Diff line change
@@ -3,13 +3,17 @@
import unittest
import os

try:
import matplotlib
SHOW_PLOTS = True
except ImportError:
SHOW_PLOTS = False

from openmdao.utils.assert_utils import assert_near_equal, assert_check_partials
from openmdao.utils.testing_utils import use_tempdirs, require_pyoptsparse

from dymos.examples.goddard_rocket_problem import RocketODE

SHOW_PLOTS = True


@require_pyoptsparse(optimizer='IPOPT')
def goddard_rocket_direct_collocation(grid_type='lgl'):
27 changes: 16 additions & 11 deletions dymos/examples/hyper_sensitive/doc/test_doc_hyper_sensitive.py
Original file line number Diff line number Diff line change
@@ -4,14 +4,18 @@
import unittest
import numpy as np

import matplotlib
import matplotlib.pyplot as plt
try:
import matplotlib
import matplotlib.pyplot as plt

matplotlib.use('Agg')
plt.style.use('ggplot')
except ImportError:
matplotlib = None

from openmdao.utils.testing_utils import use_tempdirs, require_pyoptsparse


matplotlib.use('Agg')
plt.style.use('ggplot')
tf = 10.0


@@ -103,14 +107,15 @@ def test_hyper_sensitive_for_docs(self):
#
exp_out = traj.simulate()

plot_results([('traj.phase0.timeseries.time', 'traj.phase0.timeseries.x',
'time (s)', 'x $(m)$'),
('traj.phase0.timeseries.time', 'traj.phase0.timeseries.u',
'time (s)', 'u $(m/s^2)$')],
title='Hyper Sensitive Problem Solution\nRadau Pseudospectral Method',
p_sol=p, p_sim=exp_out)
if matplotlib is not None:
plot_results([('traj.phase0.timeseries.time', 'traj.phase0.timeseries.x',
'time (s)', 'x $(m)$'),
('traj.phase0.timeseries.time', 'traj.phase0.timeseries.u',
'time (s)', 'u $(m/s^2)$')],
title='Hyper Sensitive Problem Solution\nRadau Pseudospectral Method',
p_sol=p, p_sim=exp_out)

plt.show()
plt.show()


if __name__ == "__main__":
Original file line number Diff line number Diff line change
@@ -4,11 +4,12 @@

from openmdao.utils.testing_utils import use_tempdirs

import matplotlib
matplotlib.use('Agg')


SHOW_PLOTS = True
try:
import matplotlib
matplotlib.use('Agg')
SHOW_PLOTS = True
except ImportError:
SHOW_PLOTS = False


@use_tempdirs
@@ -17,7 +18,6 @@ class TestLengthConstrainedBrachistochrone(unittest.TestCase):
def test_length_constrained_brachistochrone(self):
import openmdao.api as om
import dymos as dm
import matplotlib.pyplot as plt
from dymos.examples.brachistochrone.brachistochrone_ode import BrachistochroneODE
from dymos.examples.length_constrained_brachistochrone.arc_length_comp import ArcLengthComp

@@ -92,6 +92,8 @@ def test_length_constrained_brachistochrone(self):

# Plot results
if SHOW_PLOTS:
import matplotlib.pyplot as plt

# Generate the explicitly simulated trajectory
exp_out = traj.simulate()

12 changes: 7 additions & 5 deletions dymos/examples/min_time_climb/aero/test/test_cd0_comp.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import unittest

import numpy as np
import matplotlib

try:
import matplotlib
matplotlib.use('Agg')
SHOW_PLOTS = True
except ImportError:
SHOW_PLOTS = False

import openmdao.api as om
from dymos.utils.testing_utils import assert_check_partials

from dymos.examples.min_time_climb.aero.cd0_comp import CD0Comp


matplotlib.use('Agg')
SHOW_PLOTS = True


class TestCD0Comp(unittest.TestCase):
@unittest.skipIf(not SHOW_PLOTS, 'this test is for visual confirmation, requires plotting')
def test_visual_inspection(self):
12 changes: 7 additions & 5 deletions dymos/examples/min_time_climb/aero/test/test_cla_comp.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import unittest

import numpy as np
import matplotlib

try:
import matplotlib
matplotlib.use('Agg')
SHOW_PLOTS = True
except ImportError:
SHOW_PLOTS = False

import openmdao.api as om
from dymos.utils.testing_utils import assert_check_partials

from dymos.examples.min_time_climb.aero.cla_comp import CLaComp


matplotlib.use('Agg')
SHOW_PLOTS = True


class TestCLaComp(unittest.TestCase):

@unittest.skipIf(not SHOW_PLOTS, 'this test is for visual confirmation, requires plotting')
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import unittest

import matplotlib
import matplotlib.pyplot as plt

from openmdao.utils.testing_utils import use_tempdirs, require_pyoptsparse
try:
import matplotlib
import matplotlib.pyplot as plt

matplotlib.use('Agg')
plt.style.use('ggplot')
except ImportError:
matplotlib = None

matplotlib.use('Agg')
plt.style.use('ggplot')
from openmdao.utils.testing_utils import use_tempdirs, require_pyoptsparse


@use_tempdirs
7 changes: 5 additions & 2 deletions dymos/examples/min_time_climb/test/test_ex_min_time_climb.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import unittest
import numpy as np
from numpy.polynomial import Polynomial as P
import matplotlib.pyplot as plt
import matplotlib.cm as cm
try:
import matplotlib.pyplot as plt
import matplotlib.cm as cm
except ImportError:
matpoltlib = None

import openmdao.api as om
from openmdao.utils.assert_utils import assert_near_equal
11 changes: 11 additions & 0 deletions dymos/examples/oscillator/test/test_oscillator.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import unittest
from openmdao.utils.testing_utils import use_tempdirs

try:
import matplotlib
except ImportError:
matplotlib = None


@use_tempdirs
class TestDocOscillator(unittest.TestCase):

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_ivp(self):
import openmdao.api as om
import dymos as dm
@@ -70,6 +76,7 @@ def test_ivp(self):
plt.tight_layout()
plt.show()

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_ivp_solver(self):
import openmdao.api as om
import dymos as dm
@@ -134,6 +141,7 @@ def test_ivp_solver(self):
plt.tight_layout()
plt.show()

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_ivp_driver(self):
import openmdao.api as om
import dymos as dm
@@ -209,6 +217,7 @@ def test_ivp_driver(self):
plt.tight_layout()
plt.show()

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_ivp_driver_10_segs(self):
import openmdao.api as om
import dymos as dm
@@ -284,6 +293,7 @@ def test_ivp_driver_10_segs(self):
plt.tight_layout()
plt.show()

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_ivp_driver_4_segs_7_order(self):
import openmdao.api as om
import dymos as dm
@@ -359,6 +369,7 @@ def test_ivp_driver_4_segs_7_order(self):
plt.tight_layout()
plt.show()

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_ivp_driver_run_problem(self):
import openmdao.api as om
import dymos as dm
6 changes: 6 additions & 0 deletions dymos/examples/racecar/test/test_racecar.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import unittest

try:
import matplotlib
except ImportError:
matplotlib = None

from openmdao.utils.testing_utils import use_tempdirs, require_pyoptsparse
from openmdao.utils.assert_utils import assert_near_equal

@@ -8,6 +13,7 @@
class TestRaceCarForDocs(unittest.TestCase):

@require_pyoptsparse(optimizer='IPOPT')
@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_racecar_for_docs(self):
import numpy as np
import openmdao.api as om
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import unittest

import matplotlib
import matplotlib.pyplot as plt
try:
import matplotlib
import matplotlib.pyplot as plt

matplotlib.use('Agg')
plt.style.use('ggplot')
except ImportError:
matplotlib = None

from openmdao.utils.testing_utils import use_tempdirs
from dymos.examples.robertson_problem.doc.robertson_ode import RobertsonODE


matplotlib.use('Agg')
plt.style.use('ggplot')


@use_tempdirs
class TestRobertsonProblemForDocs(unittest.TestCase):

@@ -59,6 +61,7 @@ def robertson_problem(self, t_final=1.0):

return p

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_robertson_problem_for_docs(self):

import openmdao.api as om
12 changes: 8 additions & 4 deletions dymos/examples/robot_arm/test/test_robot_arm.py
Original file line number Diff line number Diff line change
@@ -2,7 +2,14 @@
import unittest

import numpy as np
import matplotlib.pyplot as plt

try:
import matplotlib.pyplot as plt
plt.switch_backend('Agg')
show_plots = True
except ImportError:
show_plots = False

import openmdao.api as om
import dymos as dm

@@ -12,9 +19,6 @@

from dymos.examples.robot_arm.robot_arm_ode import RobotArmODE

plt.switch_backend('Agg')
show_plots = True


@use_tempdirs
@require_pyoptsparse(optimizer='SLSQP')
13 changes: 8 additions & 5 deletions dymos/examples/shuttle_reentry/doc/test_doc_reentry.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import os
import unittest
import matplotlib.pyplot as plt

try:
import matplotlib.pyplot as plt
plt.switch_backend('Agg')
plt.style.use('ggplot')
except ImportError:
plt = None

import numpy as np

from openmdao.utils.testing_utils import use_tempdirs, require_pyoptsparse


plt.switch_backend('Agg')
plt.style.use('ggplot')


@use_tempdirs
class TestReentryForDocs(unittest.TestCase):

@@ -20,6 +22,7 @@ def tearDown(self):
os.remove(filename)

@require_pyoptsparse(optimizer='SLSQP')
@unittest.skipIf(plt is None, "This test requires matplotlib")
def test_reentry(self):
import openmdao.api as om
from openmdao.utils.assert_utils import assert_near_equal
5 changes: 5 additions & 0 deletions dymos/examples/ssto/doc/test_doc_ssto_earth.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import unittest

try:
import matplotlib
except ImportError:
matplotlib = None

from openmdao.utils.assert_utils import assert_near_equal
from openmdao.utils.testing_utils import use_tempdirs, require_pyoptsparse
@@ -9,6 +13,7 @@
class TestDocSSTOEarth(unittest.TestCase):

@require_pyoptsparse(optimizer='SLSQP')
@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_doc_ssto_earth(self):
import matplotlib.pyplot as plt
import openmdao.api as om
15 changes: 9 additions & 6 deletions dymos/examples/ssto/doc/test_doc_ssto_linear_tangent_guidance.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import unittest

import matplotlib
import matplotlib.pyplot as plt

from openmdao.utils.testing_utils import use_tempdirs, require_pyoptsparse
try:
import matplotlib
import matplotlib.pyplot as plt

matplotlib.use('Agg')
plt.style.use('ggplot')
except ImportError:
matplotlib = None

matplotlib.use('Agg')
plt.style.use('ggplot')
from openmdao.utils.testing_utils import use_tempdirs, require_pyoptsparse


@use_tempdirs
class TestDocSSTOLinearTangentGuidance(unittest.TestCase):

@require_pyoptsparse(optimizer='SLSQP')
@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_doc_ssto_linear_tangent_guidance(self):
import numpy as np
import matplotlib.pyplot as plt
15 changes: 9 additions & 6 deletions dymos/examples/ssto/doc/test_doc_ssto_polynomial_control.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import unittest

import matplotlib
import matplotlib.pyplot as plt

from openmdao.utils.testing_utils import use_tempdirs, require_pyoptsparse
try:
import matplotlib
import matplotlib.pyplot as plt

matplotlib.use('Agg')
plt.style.use('ggplot')
except ImportError:
matplotlib = None

matplotlib.use('Agg')
plt.style.use('ggplot')
from openmdao.utils.testing_utils import use_tempdirs, require_pyoptsparse


@use_tempdirs
class TestDocSSTOPolynomialControl(unittest.TestCase):

@require_pyoptsparse(optimizer='SLSQP')
@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_doc_ssto_polynomial_control(self):
import numpy as np
import matplotlib.pyplot as plt
14 changes: 9 additions & 5 deletions dymos/examples/ssto/test/test_simulate_root_trajectory.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import unittest

import matplotlib
import matplotlib.pyplot as plt
from openmdao.utils.testing_utils import use_tempdirs, require_pyoptsparse
try:
import matplotlib
import matplotlib.pyplot as plt

matplotlib.use('Agg')
plt.style.use('ggplot')
except ImportError:
matplotlib = None

matplotlib.use('Agg')
plt.style.use('ggplot')
from openmdao.utils.testing_utils import use_tempdirs, require_pyoptsparse


@use_tempdirs
class TestSSTOSimulateRootTrajectory(unittest.TestCase):

@require_pyoptsparse(optimizer='SLSQP')
@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_ssto_simulate_root_trajectory(self):
"""
Tests that we can properly simulate a trajectory even if the trajectory is the root
10 changes: 8 additions & 2 deletions dymos/examples/water_rocket/test/test_water_rocket.py
Original file line number Diff line number Diff line change
@@ -2,8 +2,12 @@
from collections import namedtuple

import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt

try:
import matplotlib as mpl
import matplotlib.pyplot as plt
except ImportError:
mpl = None

import openmdao.api as om
from openmdao.utils.assert_utils import assert_near_equal
@@ -17,6 +21,7 @@
@use_tempdirs
class TestWaterRocketForDocs(unittest.TestCase):

@unittest.skipIf(mpl is None, "This test requires matplotlib")
def test_water_rocket_height_for_docs(self):
import dymos as dm
p = om.Problem(model=om.Group())
@@ -57,6 +62,7 @@ def test_water_rocket_height_for_docs(self):
assert_near_equal(summary['Water volume'].value, 0.98, 0.01)
assert_near_equal(summary['Maximum height'].value, 53.5, 0.01)

@unittest.skipIf(mpl is None, "This test requires matplotlib")
def test_water_rocket_range_for_docs(self):
p = om.Problem(model=om.Group())

7 changes: 5 additions & 2 deletions dymos/phase/test/test_phase.py
Original file line number Diff line number Diff line change
@@ -9,8 +9,11 @@
from dymos.examples.brachistochrone.brachistochrone_ode import BrachistochroneODE


import matplotlib.pyplot as plt
plt.switch_backend('Agg')
try:
import matplotlib.pyplot as plt
plt.switch_backend('Agg')
except ImportError:
plt = None


OPTIMIZER = 'SLSQP'
7 changes: 5 additions & 2 deletions dymos/test/test_pycodestyle.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import os
import sys
import unittest
from io import StringIO

import pycodestyle
try:
import pycodestyle
except ImportError:
pycodestyle = None

import dymos

@@ -31,6 +33,7 @@ def _discover_python_files(path):
return python_files


@unittest.skipIf(pycodestyle is None, "This test requires pycodestyle")
class TestPyCodeStyle(unittest.TestCase):

def test_pycodestyle(self):
9 changes: 9 additions & 0 deletions dymos/test/test_run_problem.py
Original file line number Diff line number Diff line change
@@ -6,6 +6,11 @@
import numpy as np
from numpy.testing import assert_almost_equal

try:
import matplotlib
except ImportError:
matplotlib = None

import openmdao
import openmdao.api as om
from openmdao.utils.assert_utils import assert_near_equal
@@ -676,6 +681,7 @@ def setUp(self):

self.p = p

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_run_brachistochrone_problem_make_plots(self):
plots_cache = dm.options['plots']
dm.options['plots'] = 'matplotlib'
@@ -688,6 +694,7 @@ def test_run_brachistochrone_problem_make_plots(self):
msg=f'{varname}.png' + ' does not exist.')
dm.options['plots'] = plots_cache

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_run_brachistochrone_problem_make_plots_set_plot_dir(self):
_cache = dm.options['plots']
dm.options['plots'] = 'matplotlib'
@@ -722,6 +729,7 @@ def test_run_brachistochrone_problem_set_solution_record_file(self):

self.assertTrue(os.path.exists(solution_record_file))

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_run_brachistochrone_problem_plot_simulation(self):
plots_cache = dm.options['plots']
dm.options['plots'] = 'matplotlib'
@@ -735,6 +743,7 @@ def test_run_brachistochrone_problem_plot_simulation(self):
self.assertTrue(plotfile.exists(), msg=f'plot file {plotfile} does not exist!')
dm.options['plots'] = plots_cache

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_run_brachistochrone_problem_plot_no_simulation_record_file_given(self):
plots_cache = dm.options['plots']
dm.options['plots'] = 'matplotlib'
13 changes: 12 additions & 1 deletion dymos/visualization/test/test_timeseries_plots.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import os
import unittest
import pathlib

import numpy as np

try:
import matplotlib
except ImportError:
matplotlib = None

import openmdao.api as om
from openmdao.utils.testing_utils import use_tempdirs, require_pyoptsparse

@@ -80,6 +84,7 @@ def setUp(self):

self.p = p

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_brachistochrone_timeseries_plots(self):
with dm.options.temporary(plots='matplotlib'):
dm.run_problem(self.p, make_plots=False)
@@ -94,6 +99,7 @@ def test_brachistochrone_timeseries_plots(self):
self.assertTrue(plot_dir.joinpath('theta_rate.png').exists())
self.assertTrue(plot_dir.joinpath('theta_rate2.png').exists())

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_brachistochrone_timeseries_plots_solution_only_set_solution_record_file(self):
temp = dm.options['plots']
dm.options['plots'] = 'matplotlib'
@@ -113,6 +119,7 @@ def test_brachistochrone_timeseries_plots_solution_only_set_solution_record_file

dm.options['plots'] = temp

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_brachistochrone_timeseries_plots_solution_and_simulation(self):
temp = dm.options['plots']
dm.options['plots'] = 'matplotlib'
@@ -132,6 +139,7 @@ def test_brachistochrone_timeseries_plots_solution_and_simulation(self):

dm.options['plots'] = temp

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_brachistochrone_timeseries_plots_set_plot_dir(self):

temp = dm.options['plots']
@@ -156,6 +164,7 @@ def test_brachistochrone_timeseries_plots_set_plot_dir(self):
class TestTimeSeriesPlotsMultiPhase(unittest.TestCase):

@require_pyoptsparse(optimizer='IPOPT')
@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_trajectory_linked_phases_make_plot(self):
temp = dm.options['plots']

@@ -312,6 +321,7 @@ def test_trajectory_linked_phases_make_plot(self):

dm.options['plots'] = temp

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_overlapping_phases_make_plot(self):

_temp = dm.options['plots']
@@ -409,6 +419,7 @@ def test_overlapping_phases_make_plot(self):
dm.options['plots'] = _temp

@require_pyoptsparse(optimizer='IPOPT')
@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_trajectory_linked_phases_make_plot_missing_data(self):
"""
Test that plots are still generated even if the phases don't share the exact same
7 changes: 7 additions & 0 deletions joss/test/test_brachistochrone_for_joss.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import unittest

try:
import matplotlib
except ImportError:
matplotlib = None

from openmdao.utils.testing_utils import use_tempdirs
from openmdao.utils.assert_utils import assert_near_equal


@use_tempdirs
class TestBrachistochroneForJOSS(unittest.TestCase):

@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_results(self):

# Begin code for paper
5 changes: 5 additions & 0 deletions joss/test/test_cannonball_for_joss.py
Original file line number Diff line number Diff line change
@@ -2,11 +2,16 @@
from openmdao.utils.testing_utils import use_tempdirs, require_pyoptsparse
from openmdao.utils.assert_utils import assert_near_equal

try:
import matplotlib
except ImportError:
matplotlib = None

@use_tempdirs
class TestCannonballForJOSS(unittest.TestCase):

@require_pyoptsparse(optimizer='SLSQP')
@unittest.skipIf(matplotlib is None, "This test requires matplotlib")
def test_results(self):
# begin code for paper
import numpy as np