diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2017-11-21 10:10:26 -0700 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2017-11-24 16:51:53 -0700 |
commit | 1d97b3aafdca2722bbe2f0c10a96544121c8f78b (patch) | |
tree | d70280d678745fdd419fdd17586336f766f279b6 /numpy/lib/tests/test__iotools.py | |
parent | d9ca11117f37d48d07818a3aae3641c023454269 (diff) | |
download | numpy-1d97b3aafdca2722bbe2f0c10a96544121c8f78b.tar.gz |
MAINT: Various minor code cleanups.
Minor cleanups of old code to reflect more modern usage.
Diffstat (limited to 'numpy/lib/tests/test__iotools.py')
-rw-r--r-- | numpy/lib/tests/test__iotools.py | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/numpy/lib/tests/test__iotools.py b/numpy/lib/tests/test__iotools.py index b25b42f8c..54fac8da4 100644 --- a/numpy/lib/tests/test__iotools.py +++ b/numpy/lib/tests/test__iotools.py @@ -12,6 +12,7 @@ from numpy.lib._iotools import ( LineSplitter, NameValidator, StringConverter, has_nested_fields, easy_dtype, flatten_dtype ) +from numpy.compat import unicode class TestLineSplitter(object): @@ -155,10 +156,10 @@ class TestStringConverter(object): assert_equal(converter.upgrade('0'), 0) assert_equal(converter._status, 1) - # On systems where integer defaults to 32-bit, the statuses will be + # On systems where long defaults to 32-bit, the statuses will be # offset by one, so we check for this here. import numpy.core.numeric as nx - status_offset = int(nx.dtype(nx.integer).itemsize < nx.dtype(nx.int64).itemsize) + status_offset = int(nx.dtype(nx.int_).itemsize < nx.dtype(nx.int64).itemsize) # test int > 2**32 assert_equal(converter.upgrade('17179869184'), 17179869184) @@ -172,9 +173,15 @@ class TestStringConverter(object): assert_equal(converter.upgrade('0j'), complex('0j')) assert_equal(converter._status, 3 + status_offset) - # test str TODO - #assert_equal(converter.upgrade(b'a'), b'a') - #assert_equal(converter._status, len(converter._mapper) - 1) + # test str + # note that the longdouble type has been skipped, so the + # _status increases by 2. Everything should succeed with + # unicode conversion (5). + for s in ['a', u'a', b'a']: + res = converter.upgrade(s) + assert_(type(res) is unicode) + assert_equal(res, u'a') + assert_equal(converter._status, 5 + status_offset) def test_missing(self): "Tests the use of missing values." @@ -204,8 +211,9 @@ class TestStringConverter(object): def test_string_to_object(self): "Make sure that string-to-object functions are properly recognized" + old_mapper = StringConverter._mapper[:] # copy of list conv = StringConverter(_bytes_to_date) - assert_equal(conv._mapper[-3][0](0), 0j) + assert_equal(conv._mapper, old_mapper) assert_(hasattr(conv, 'default')) def test_keep_default(self): |