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

Skip to content

Commit 3cad3e0

Browse files
committed
PEP8 fixes on the tests of the dates module
1 parent 81086b3 commit 3cad3e0

File tree

1 file changed

+70
-52
lines changed

1 file changed

+70
-52
lines changed

lib/matplotlib/tests/test_dates.py

Lines changed: 70 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,98 @@
11
from __future__ import print_function
22
import datetime
3-
import numpy as np
4-
from matplotlib.testing.decorators import image_comparison, knownfailureif, cleanup
3+
from matplotlib.testing.decorators import image_comparison
4+
from matplotlib.testing.decorators import knownfailureif, cleanup
55
import matplotlib.pyplot as plt
66
from nose.tools import assert_raises, assert_equal
77
import warnings
88

9+
910
@image_comparison(baseline_images=['date_empty'])
1011
def test_date_empty():
1112
# make sure mpl does the right thing when told to plot dates even
1213
# if no date data has been presented, cf
1314
# http://sourceforge.net/tracker/?func=detail&aid=2850075&group_id=80706&atid=560720
1415
fig = plt.figure()
15-
ax = fig.add_subplot(1,1,1)
16+
ax = fig.add_subplot(1, 1, 1)
1617
ax.xaxis_date()
1718

19+
1820
@image_comparison(baseline_images=['date_axhspan'])
1921
def test_date_axhspan():
2022
# test ax hspan with date inputs
2123
t0 = datetime.datetime(2009, 1, 20)
2224
tf = datetime.datetime(2009, 1, 21)
2325
fig = plt.figure()
24-
ax = fig.add_subplot(1,1,1)
25-
ax.axhspan( t0, tf, facecolor="blue", alpha=0.25 )
26-
ax.set_ylim(t0-datetime.timedelta(days=5),
27-
tf+datetime.timedelta(days=5))
26+
ax = fig.add_subplot(1, 1, 1)
27+
ax.axhspan(t0, tf, facecolor="blue", alpha=0.25)
28+
ax.set_ylim(t0 - datetime.timedelta(days=5),
29+
tf + datetime.timedelta(days=5))
2830
fig.subplots_adjust(left=0.25)
2931

32+
3033
@image_comparison(baseline_images=['date_axvspan'])
3134
def test_date_axvspan():
3235
# test ax hspan with date inputs
3336
t0 = datetime.datetime(2000, 1, 20)
3437
tf = datetime.datetime(2010, 1, 21)
3538
fig = plt.figure()
36-
ax = fig.add_subplot(1,1,1)
37-
ax.axvspan( t0, tf, facecolor="blue", alpha=0.25 )
38-
ax.set_xlim(t0-datetime.timedelta(days=720),
39-
tf+datetime.timedelta(days=720))
39+
ax = fig.add_subplot(1, 1, 1)
40+
ax.axvspan(t0, tf, facecolor="blue", alpha=0.25)
41+
ax.set_xlim(t0 - datetime.timedelta(days=720),
42+
tf + datetime.timedelta(days=720))
4043
fig.autofmt_xdate()
4144

45+
4246
@image_comparison(baseline_images=['date_axhline'])
4347
def test_date_axhline():
4448
# test ax hline with date inputs
4549
t0 = datetime.datetime(2009, 1, 20)
4650
tf = datetime.datetime(2009, 1, 31)
4751
fig = plt.figure()
48-
ax = fig.add_subplot(1,1,1)
49-
ax.axhline( t0, color="blue", lw=3)
50-
ax.set_ylim(t0-datetime.timedelta(days=5),
51-
tf+datetime.timedelta(days=5))
52+
ax = fig.add_subplot(1, 1, 1)
53+
ax.axhline(t0, color="blue", lw=3)
54+
ax.set_ylim(t0 - datetime.timedelta(days=5),
55+
tf + datetime.timedelta(days=5))
5256
fig.subplots_adjust(left=0.25)
5357

58+
5459
@image_comparison(baseline_images=['date_axvline'])
5560
def test_date_axvline():
5661
# test ax hline with date inputs
5762
t0 = datetime.datetime(2000, 1, 20)
5863
tf = datetime.datetime(2000, 1, 21)
5964
fig = plt.figure()
60-
ax = fig.add_subplot(1,1,1)
61-
ax.axvline( t0, color="red", lw=3)
62-
ax.set_xlim(t0-datetime.timedelta(days=5),
63-
tf+datetime.timedelta(days=5))
65+
ax = fig.add_subplot(1, 1, 1)
66+
ax.axvline(t0, color="red", lw=3)
67+
ax.set_xlim(t0 - datetime.timedelta(days=5),
68+
tf + datetime.timedelta(days=5))
6469
fig.autofmt_xdate()
6570

71+
6672
@cleanup
6773
def test_too_many_date_ticks():
6874
# Attempt to test SF 2715172, see
6975
# https://sourceforge.net/tracker/?func=detail&aid=2715172&group_id=80706&atid=560720
7076
# setting equal datetimes triggers and expander call in
7177
# transforms.nonsingular which results in too many ticks in the
7278
# DayLocator. This should trigger a Locator.MAXTICKS RuntimeError
73-
warnings.filterwarnings('ignore',
74-
'Attempting to set identical left==right results\\nin singular transformations; automatically expanding.\\nleft=\d*\.\d*, right=\d*\.\d*',
79+
warnings.filterwarnings(
80+
'ignore',
81+
'Attempting to set identical left==right results\\nin singular '
82+
'transformations; automatically expanding.\\nleft=\d*\.\d*, '
83+
'right=\d*\.\d*',
7584
UserWarning, module='matplotlib.axes')
7685
t0 = datetime.datetime(2000, 1, 20)
7786
tf = datetime.datetime(2000, 1, 20)
7887
fig = plt.figure()
79-
ax = fig.add_subplot(1,1,1)
80-
ax.set_xlim((t0,tf), auto=True)
81-
ax.plot([],[])
82-
from matplotlib.dates import DayLocator, DateFormatter, HourLocator
88+
ax = fig.add_subplot(1, 1, 1)
89+
ax.set_xlim((t0, tf), auto=True)
90+
ax.plot([], [])
91+
from matplotlib.dates import DayLocator
8392
ax.xaxis.set_major_locator(DayLocator())
8493
assert_raises(RuntimeError, fig.savefig, 'junk.png')
8594

95+
8696
@image_comparison(baseline_images=['RRuleLocator_bounds'])
8797
def test_RRuleLocator():
8898
import pylab
@@ -95,22 +105,23 @@ def test_RRuleLocator():
95105
# This will cause the RRuleLocator to go out of bounds when it tries
96106
# to add padding to the limits, so we make sure it caps at the correct
97107
# boundary values.
98-
t0 = datetime( 1000, 1, 1 )
99-
tf = datetime( 6000, 1, 1 )
108+
t0 = datetime(1000, 1, 1)
109+
tf = datetime(6000, 1, 1)
100110

101111
fig = pylab.figure()
102-
ax = pylab.subplot( 111 )
103-
ax.set_autoscale_on( True )
104-
ax.plot( [t0, tf], [0.0, 1.0], marker='o' )
112+
ax = pylab.subplot(111)
113+
ax.set_autoscale_on(True)
114+
ax.plot([t0, tf], [0.0, 1.0], marker='o')
105115

106-
rrule = mpldates.rrulewrapper( dateutil.rrule.YEARLY, interval=500 )
107-
locator = mpldates.RRuleLocator( rrule )
108-
ax.xaxis.set_major_locator( locator )
109-
ax.xaxis.set_major_formatter( mpldates.AutoDateFormatter(locator) )
116+
rrule = mpldates.rrulewrapper(dateutil.rrule.YEARLY, interval=500)
117+
locator = mpldates.RRuleLocator(rrule)
118+
ax.xaxis.set_major_locator(locator)
119+
ax.xaxis.set_major_formatter(mpldates.AutoDateFormatter(locator))
110120

111121
ax.autoscale_view()
112122
fig.autofmt_xdate()
113123

124+
114125
@image_comparison(baseline_images=['DateFormatter_fractionalSeconds'])
115126
def test_DateFormatter():
116127
import pylab
@@ -121,13 +132,13 @@ def test_DateFormatter():
121132
# Lets make sure that DateFormatter will allow us to have tick marks
122133
# at intervals of fractional seconds.
123134

124-
t0 = datetime( 2001, 1, 1, 0, 0, 0 )
125-
tf = datetime( 2001, 1, 1, 0, 0, 1 )
135+
t0 = datetime(2001, 1, 1, 0, 0, 0)
136+
tf = datetime(2001, 1, 1, 0, 0, 1)
126137

127138
fig = pylab.figure()
128-
ax = pylab.subplot( 111 )
129-
ax.set_autoscale_on( True )
130-
ax.plot( [t0, tf], [0.0, 1.0], marker='o' )
139+
ax = pylab.subplot(111)
140+
ax.set_autoscale_on(True)
141+
ax.plot([t0, tf], [0.0, 1.0], marker='o')
131142

132143
# rrule = mpldates.rrulewrapper( dateutil.rrule.YEARLY, interval=500 )
133144
# locator = mpldates.RRuleLocator( rrule )
@@ -137,36 +148,42 @@ def test_DateFormatter():
137148
ax.autoscale_view()
138149
fig.autofmt_xdate()
139150

151+
140152
def test_drange():
141-
'''This test should check if drange works as expected, and if all the rounding errors
142-
are fixed'''
153+
"""
154+
This test should check if drange works as expected, and if all the
155+
rounding errors are fixed
156+
"""
143157
from matplotlib import dates
144-
start = datetime.datetime(2011, 1,1, tzinfo=dates.UTC)
158+
start = datetime.datetime(2011, 1, 1, tzinfo=dates.UTC)
145159
end = datetime.datetime(2011, 1, 2, tzinfo=dates.UTC)
146160
delta = datetime.timedelta(hours=1)
147-
#We expect 24 values in drange(start, end, delta), because drange returns dates from
148-
#an half open interval [start, end)
161+
# We expect 24 values in drange(start, end, delta), because drange returns
162+
# dates from an half open interval [start, end)
149163
assert_equal(24, len(dates.drange(start, end, delta)))
150164

151-
#if end is a little bit later, we expect the range to contain one element more
152-
end = end +datetime.timedelta(microseconds=1)
165+
# if end is a little bit later, we expect the range to contain one element
166+
# more
167+
end = end + datetime.timedelta(microseconds=1)
153168
assert_equal(25, len(dates.drange(start, end, delta)))
154169

155-
#reset end
170+
# reset end
156171
end = datetime.datetime(2011, 1, 2, tzinfo=dates.UTC)
157172

158-
#and tst drange with "complicated" floats:
173+
# and tst drange with "complicated" floats:
159174
# 4 hours = 1/6 day, this is an "dangerous" float
160175
delta = datetime.timedelta(hours=4)
161176
daterange = dates.drange(start, end, delta)
162177
assert_equal(6, len(daterange))
163-
assert_equal(dates.num2date(daterange[-1]), end-delta)
178+
assert_equal(dates.num2date(daterange[-1]), end - delta)
179+
164180

165181
#@image_comparison(baseline_images=['empty_date_bug'])
166182
@cleanup
167183
@knownfailureif(True)
168184
def test_empty_date_with_year_formatter():
169-
# exposes sf bug 2861426: https://sourceforge.net/tracker/?func=detail&aid=2861426&group_id=80706&atid=560720
185+
# exposes sf bug 2861426:
186+
# https://sourceforge.net/tracker/?func=detail&aid=2861426&group_id=80706&atid=560720
170187

171188
# update: I am no loner believe this is a bug, as I commented on
172189
# the tracker. The question is now: what to do with this test
@@ -181,6 +198,7 @@ def test_empty_date_with_year_formatter():
181198

182199
fig.savefig('empty_date_bug')
183200

184-
if __name__=='__main__':
201+
202+
if __name__ == '__main__':
185203
import nose
186-
nose.runmodule(argv=['-s','--with-doctest'], exit=False)
204+
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

0 commit comments

Comments
 (0)