From ba4d740ce8b033af1d72be681f02385b6cd1a4b2 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Sun, 19 Apr 2020 17:41:23 +0200 Subject: [PATCH] Fix polar tests. The `numpy` import went away, breaking the tests. Also move them out of test_subplots.py given that they have nothing to do with subplots; we could move them to test_axes.py but a new test_polar.py seems better (we could also later move polar tests from test_axes to test_polar). Also some test refactoring and fix an error message. --- lib/matplotlib/projections/polar.py | 2 +- lib/matplotlib/tests/test_polar.py | 15 +++++++++++++++ lib/matplotlib/tests/test_subplots.py | 23 ----------------------- 3 files changed, 16 insertions(+), 24 deletions(-) create mode 100644 lib/matplotlib/tests/test_polar.py diff --git a/lib/matplotlib/projections/polar.py b/lib/matplotlib/projections/polar.py index dd6f5f0fadb6..f7c9c65ee958 100644 --- a/lib/matplotlib/projections/polar.py +++ b/lib/matplotlib/projections/polar.py @@ -1061,7 +1061,7 @@ def set_thetalim(self, *args, **kwargs): if thetamin is not None and thetamax is not None: if abs(thetamax - thetamin) > 2 * np.pi: - raise ValueError('The angle range must be<= 360 degrees') + raise ValueError('The angle range must be <= 360 degrees') return tuple(np.rad2deg(self.set_xlim(left=left, right=right, xmin=thetamin, xmax=thetamax))) diff --git a/lib/matplotlib/tests/test_polar.py b/lib/matplotlib/tests/test_polar.py new file mode 100644 index 000000000000..1fda14a0a3c8 --- /dev/null +++ b/lib/matplotlib/tests/test_polar.py @@ -0,0 +1,15 @@ +import numpy as np +import pytest + +from matplotlib import pyplot as plt + + +def test_thetalim_valid_invalid(): + ax = plt.subplot(projection='polar') + ax.set_thetalim(0, 2 * np.pi) # doesn't raise. + ax.set_thetalim(thetamin=800, thetamax=440) # doesn't raise. + with pytest.raises(ValueError, match='The angle range must be <= 2 pi'): + ax.set_thetalim(0, 3 * np.pi) + with pytest.raises(ValueError, + match='The angle range must be <= 360 degrees'): + ax.set_thetalim(thetamin=800, thetamax=400) diff --git a/lib/matplotlib/tests/test_subplots.py b/lib/matplotlib/tests/test_subplots.py index 0bb9143f0eba..72f72968d72b 100644 --- a/lib/matplotlib/tests/test_subplots.py +++ b/lib/matplotlib/tests/test_subplots.py @@ -173,26 +173,3 @@ def test_dont_mutate_kwargs(): gridspec_kw=gridspec_kw) assert subplot_kw == {'sharex': 'all'} assert gridspec_kw == {'width_ratios': [1, 2]} - - -def test_subplot_theta_min_max_raise(): - with pytest.raises(ValueError, match='The angle range ' + - 'must be<= 360 degrees'): - ax = plt.subplot(111, projection='polar') - ax.set_thetalim(thetamin=800, thetamax=400) - - -def test_subplot_theta_min_max_non_raise(): - ax = plt.subplot(111, projection='polar') - ax.set_thetalim(thetamin=800, thetamax=440) - - -def test_subplot_theta_range_raise(): - with pytest.raises(ValueError, match='The angle range must be <= 2 pi'): - ax = plt.subplot(111, projection='polar') - ax.set_thetalim(0, 3 * numpy.pi) - - -def test_subplot_theta_range_normal_non_raise(): - ax = plt.subplot(111, projection='polar') - ax.set_thetalim(0, 2 * numpy.pi)