8000 STY: Make numpy/lib/test/*.py PEP8 compliant. · juliantaylor/numpy@d2c44c5 · GitHub
[go: up one dir, main page]

Skip to content

Commit d2c44c5

Browse files
committed
STY: Make numpy/lib/test/*.py PEP8 compliant.
Run autopep8 over the test files in numpy/lib/test and make fixes to the result. Also remove Python5 workaround.
1 parent 57245e4 commit d2c44c5

19 files changed

+1246
-1086
lines changed

numpy/lib/tests/test__datasource.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from urlparse import urlparse
1818
from urllib2 import URLError
1919

20+
2021
def urlopen_stub(url, data=None):
2122
'''Stub to replace urlopen for testing.'''
2223
if url == valid_httpurl():
@@ -28,12 +29,14 @@ def urlopen_stub(url, data=None):
2829
# setup and teardown
2930
old_urlopen = None
3031

32+
3133
def setup():
3234
global old_urlopen
3335

3436
old_urlopen = urllib_request.urlopen
3537
urllib_request.urlopen = urlopen_stub
3638

39+
3740
def teardown():
3841
urllib_request.urlopen = old_urlopen
3942

@@ -57,31 +60,39 @@ def valid_textfile(filedir):
5760
os.close(fd)
5861
return path
5962

63+
6064
def invalid_textfile(filedir):
6165
# Generate and return an invalid filename.
6266
fd, path = mkstemp(suffix='.txt', prefix='dstmp_', dir=filedir)
6367
os.close(fd)
6468
os.remove(path)
6569
return path
6670

71+
6772
def valid_httpurl():
6873
return http_path+http_file
6974

75+
7076
def invalid_httpurl():
7177
return http_fakepath+http_fakefile
7278

79+
7380
def valid_baseurl():
7481
return http_path
7582

83+
7684
def invalid_baseurl():
7785
return http_fakepath
7886

87+
7988
def valid_httpfile():
8089
return http_file
8190

91+
8292
def invalid_httpfile():
8393
return http_fakefile
8494

95+
8596
class TestDataSourceOpen(TestCase):
8697
def setUp(self):
8798
self.tmpdir = mkdtemp()
@@ -259,7 +270,7 @@ def tearDown(self):
259270

260271
def test_ValidHTTP(self):
261272
scheme, netloc, upath, pms, qry, frg = urlparse(valid_httpurl())
262-
local_path = os.path.join(self.repos._destpath, netloc, \
273+
local_path = os.path.join(self.repos._destpath, netloc,
263274
upath.strip(os.sep).strip('/'))
264275
filepath = self.repos.abspath(valid_httpfile())
265276
self.assertEqual(local_path, filepath)
@@ -313,6 +324,7 @@ def test_CachedHTTPFile(self):
313324
tmpfile = valid_textfile(local_path)
314325
assert_(self.repos.exists(tmpfile))
315326

327+
316328
class TestOpenFunc(TestCase):
317329
def setUp(self):
318330
self.tmpdir = mkdtemp()

numpy/lib/tests/test__iotools.py

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@
55
from datetime import date
66

77
import numpy as np
8-
from numpy.lib._iotools import LineSplitter, NameValidator, StringConverter, \
9-
has_nested_fields, easy_dtype, flatten_dtype
8+
from numpy.lib._iotools import (
9+
LineSplitter, NameValidator, StringConverter,
10+
has_nested_fields, easy_dtype, flatten_dtype
11+
)
1012
from numpy.testing import *
1113
from numpy.compat import asbytes, asbytes_nested
1214

15+
1316
class TestLineSplitter(TestCase):
1417
"Tests the LineSplitter class."
15-
#
18+
1619
def test_no_delimiter(self):
1720
"Test LineSplitter w/o delimiter"
1821
strg = asbytes(" 1 2 3 4 5 # test")
@@ -71,11 +74,11 @@ def test_variable_fixed_width(self):
7174
test = LineSplitter((6, 6, 9))(strg)
7275
assert_equal(test, asbytes_nested(['1', '3 4', '5 6']))
7376

74-
7577
#-------------------------------------------------------------------------------
7678

79+
7780
class TestNameValidator(TestCase):
78-
#
81+
7982
def test_case_sensitivity(self):
8083
"Test case sensitivity"
8184
names = ['A', 'a', 'b', 'c']
@@ -87,14 +90,14 @@ def test_case_sensitivity(self):
8790
assert_equal(test, ['A', 'A_1', 'B', 'C'])
8891
test = NameValidator(case_sensitive='lower').validate(names)
8992
assert_equal(test, ['a', 'a_1', 'b', 'c'])
90-
#
93+
9194
def test_excludelist(self):
9295
"Test excludelist"
9396
names = ['dates', 'data', 'Other Data', 'mask']
9497
validator = NameValidator(excludelist=['dates', 'data', 'mask'])
9598
test = validator.validate(names)
9699
assert_equal(test, ['dates_', 'data_', 'Other_Data', 'mask_'])
97-
#
100+
98101
def test_missing_names(self):
99102
"Test validate missing names"
100103
namelist = ('a', 'b', 'c')
@@ -106,42 +109,41 @@ def test_missing_names(self):
106109
assert_equal(validator(namelist), ['a', 'b', 'f0'])
107110
namelist = ('', 'f0', '')
108111
assert_equal(validator(namelist), ['f1', 'f0', 'f2'])
109-
#
112+
110113
def test_validate_nb_names(self):
111114
"Test validate nb names"
112115
namelist = ('a', 'b', 'c')
113116
validator = NameValidator()
114117
assert_equal(validator(namelist, nbfields=1), ('a',))
115118
assert_equal(validator(namelist, nbfields=5, defaultfmt="g%i"),
116119
['a', 'b', 'c', 'g0', 'g1'])
117-
#
120+
118121
def test_validate_wo_names(self):
119122
"Test validate no names"
120123
namelist = None
121124
validator = NameValidator()
122125
assert_(validator(namelist) is None)
123126
assert_equal(validator(namelist, nbfields=3), ['f0', 'f1', 'f2'])
124127

125-
126-
127-
128128
#-------------------------------------------------------------------------------
129129

130+
130131
def _bytes_to_date(s):
131132
if sys.version_info[0] >= 3:
132133
return date(*time.strptime(s.decode('latin1'), "%Y-%m-%d")[:3])
133134
else:
134135
return date(*time.strptime(s, "%Y-%m-%d")[:3])
135136

137+
136138
class TestStringConverter(TestCase):
137139
"Test StringConverter"
138-
#
140+
139141
def test_creation(self):
140142
"Test creation of a StringConverter"
141143
converter = StringConverter(int, -99999)
142144
assert_equal(converter._status, 1)
143145
assert_equal(converter.default, -99999)
144-
#
146+
145147
def test_upgrade(self):
146148
"Tests the upgrade method."
147149
converter = StringConverter()
@@ -154,7 +156,7 @@ def test_upgrade(self):
154156
assert_equal(converter._status, 3)
155157
converter.upgrade(asbytes('a'))
156158
assert_equal(converter._status, len(converter._mapper) - 1)
157-
#
159+
158160
def test_missing(self):
159161
"Tests the use of missing values."
160162
converter = StringConverter(missing_values=(asbytes('missing'),
@@ -168,7 +170,7 @@ def test_missing(self):
168170
converter('miss')
169171
except ValueError:
170172
pass
171-
#
173+
172174
def test_upgrademapper(self):
173175
"Tests updatemapper"
174176
dateparser = _bytes_to_date
@@ -180,37 +182,39 @@ def test_upgrademapper(self):
180182
assert_equal(test, date(2009, 1, 1))
181183
test = convert(asbytes(''))
182184
assert_equal(test, date(2000, 1, 1))
183-
#
185+
184186
def test_string_to_object(self):
185187
"Make sure that string-to-object functions are properly recognized"
186188
conv = StringConverter(_bytes_to_date)
187189
assert_equal(conv._mapper[-2][0](0), 0j)
188190
assert_(hasattr(conv, 'default'))
189-
#
191+
190192
def test_keep_default(self):
191193
"Make sure we don't lose an explicit default"
192194
converter = StringConverter(None, missing_values=asbytes(''),
193-
default= -999)
195+
default=-999)
194196
converter.upgrade(asbytes('3.14159265'))
195197
assert_equal(converter.default, -999)
196198
assert_equal(converter.type, np.dtype(float))
197199
#
198-
converter = StringConverter(None, missing_values=asbytes(''), default=0)
200+
converter = StringConverter(
201+
None, missing_values=asbytes(''), default=0)
199202
converter.upgrade(asbytes('3.14159265'))
200203
assert_equal(converter.default, 0)
201204
assert_equal(converter.type, np.dtype(float))
202-
#
205+
203206
def test_keep_default_zero(self):
204207
"Check that we don't lose a default of 0"
205208
converter = StringConverter(int, default=0,
206209
missing_values=asbytes("N/A"))
207210
assert_equal(converter.default, 0)
208-
#
211+
209212
def test_keep_missing_values(self):
210213
"Check that we're not losing missing values"
211214
converter = StringConverter(int, default=0,
212215
missing_values=asbytes("N/A"))
213-
assert_equal(converter.missing_values, set(asbytes_nested(['', 'N/A'])))
216+
assert_equal(
217+
converter.missing_values, set(asbytes_nested(['', 'N/A'])))
214218

215219
def test_int64_dtype(self):
216220
"Check that int64 integer types can be specified"
@@ -226,10 +230,9 @@ def test_uint64_dtype(self):
226230
val = asbytes("9223372043271415339")
227231
assert_(converter(val) == 9223372043271415339)
228232

229-
#-------------------------------------------------------------------------------
230233

231234
class TestMiscFunctions(TestCase):
232-
#
235+
233236
def test_has_nested_dtype(self):
234237
"Test has_nested_dtype"
235238
ndtype = np.dtype(np.float)
@@ -292,9 +295,9 @@ def test_easy_dtype(self):
292295
np.dtype([(_, float) for _ in ('a', 'b', 'c')]))
293296
# As simple dtype w/o names (but multiple fields)
294297
ndtype = np.dtype(float)
295-
assert_equal(easy_dtype(ndtype, names=['', '', ''], defaultfmt="f%02i"),
296-
np.dtype([(_, float) for _ in ('f00', 'f01', 'f02')]))
297-
298+
assert_equal(
299+
easy_dtype(ndtype, names=['', '', ''], defaultfmt="f%02i"),
300+
np.dtype([(_, float) for _ in ('f00', 'f01', 'f02')]))
298301

299302
def test_flatten_dtype(self):
300303
"Testing flatten_dtype"

0 commit comments

Comments
 (0)
0