Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 252e016

Browse files
committed
fix test_dates to chek for RuntimeError on identical date lim test
svn path=/trunk/matplotlib/; revision=7678
1 parent 252c123 commit 252e016

2 files changed

Lines changed: 11 additions & 12 deletions

File tree

lib/matplotlib/axes.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2033,6 +2033,8 @@ def set_xlim(self, xmin=None, xmax=None, emit=True, **kwargs):
20332033
if xmin is None: xmin = old_xmin
20342034
if xmax is None: xmax = old_xmax
20352035

2036+
if xmin==xmax:
2037+
warnings.warn('Attempting to set identical xmin==xmax results in singular transformations; automatically expanding. xmin=%s, xmax=%s'%(xmin, xmax))
20362038
xmin, xmax = mtransforms.nonsingular(xmin, xmax, increasing=False)
20372039
xmin, xmax = self.xaxis.limit_range_for_scale(xmin, xmax)
20382040

@@ -2205,6 +2207,9 @@ def set_ylim(self, ymin=None, ymax=None, emit=True, **kwargs):
22052207
if ymin is None: ymin = old_ymin
22062208
if ymax is None: ymax = old_ymax
22072209

2210+
if ymin==ymax:
2211+
warnings.warn('Attempting to set identical ymin==ymax results in singular transformations; automatically expanding. ymin=%s, ymax=%s'%(ymin, ymax))
2212+
22082213
ymin, ymax = mtransforms.nonsingular(ymin, ymax, increasing=False)
22092214
ymin, ymax = self.yaxis.limit_range_for_scale(ymin, ymax)
22102215
self.viewLim.intervaly = (ymin, ymax)

lib/matplotlib/tests/test_dates.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import numpy as np
33
from matplotlib.testing.decorators import image_comparison, knownfailureif
44
import matplotlib.pyplot as plt
5+
from nose.tools import assert_raises
56

67
@image_comparison(baseline_images=['date_empty'])
78
def test_date_empty():
@@ -66,13 +67,12 @@ def test_date_axvline():
6667
fig.autofmt_xdate()
6768
fig.savefig('date_axvline')
6869

69-
# we want to test that this method raises a RuntimeError -- what is
70-
# the rightway to do this in the current framework
71-
@knownfailureif(True)
72-
#@image_comparison(baseline_images=['date_xlim_empty'])
73-
def test_set_xlim_and_unexpected_handling():
70+
def test_too_many_date_ticks():
7471
# Attempt to test SF 2715172, see
7572
# https://sourceforge.net/tracker/?func=detail&aid=2715172&group_id=80706&atid=560720
73+
# setting equal datetimes triggers and expander call in
74+
# transforms.nonsingular which results in too many ticks in the
75+
# DayLocator. This should trigger a Locator.MAXTICKS RuntimeError
7676
t0 = datetime.datetime(2000, 1, 20)
7777
tf = datetime.datetime(2000, 1, 20)
7878
fig = plt.figure()
@@ -81,13 +81,7 @@ def test_set_xlim_and_unexpected_handling():
8181
ax.plot([],[])
8282
from matplotlib.dates import DayLocator, DateFormatter, HourLocator
8383
ax.xaxis.set_major_locator(DayLocator())
84-
ax.xaxis.set_major_formatter(DateFormatter("%m/%d/%y, %I:%M%p"))
85-
ax.xaxis.set_minor_locator(HourLocator())
86-
if 0:
87-
# this seems to cause an ininite loop.
88-
from nose.plugins.skip import SkipTest
89-
raise SkipTest('avoiding never-ending drawing')
90-
fig.savefig('date_xlim_empty')
84+
assert_raises(RuntimeError, fig.savefig, 'junk.png')
9185

9286
if __name__=='__main__':
9387
import nose

0 commit comments

Comments
 (0)