MCPcopy Create free account
hub / github.com/numpy/numpy / test_upgrade

Method test_upgrade

numpy/lib/tests/test__iotools.py:150–185  ·  view source on GitHub ↗

Tests the upgrade method.

(self)

Source from the content-addressed store, hash-verified

148 assert_equal(converter.default, -99999)
149
150 def test_upgrade(self):
151 "Tests the upgrade method."
152
153 converter = StringConverter()
154 assert_equal(converter._status, 0)
155
156 # test int
157 assert_equal(converter.upgrade('0'), 0)
158 assert_equal(converter._status, 1)
159
160 # On systems where long defaults to 32-bit, the statuses will be
161 # offset by one, so we check for this here.
162 import numpy.core.numeric as nx
163 status_offset = int(nx.dtype(nx.int_).itemsize < nx.dtype(nx.int64).itemsize)
164
165 # test int > 2**32
166 assert_equal(converter.upgrade('17179869184'), 17179869184)
167 assert_equal(converter._status, 1 + status_offset)
168
169 # test float
170 assert_allclose(converter.upgrade('0.'), 0.0)
171 assert_equal(converter._status, 2 + status_offset)
172
173 # test complex
174 assert_equal(converter.upgrade('0j'), complex('0j'))
175 assert_equal(converter._status, 3 + status_offset)
176
177 # test str
178 # note that the longdouble type has been skipped, so the
179 # _status increases by 2. Everything should succeed with
180 # unicode conversion (8).
181 for s in ['a', b'a']:
182 res = converter.upgrade(s)
183 assert_(type(res) is str)
184 assert_equal(res, 'a')
185 assert_equal(converter._status, 8 + status_offset)
186
187 def test_missing(self):
188 "Tests the use of missing values."

Callers

nothing calls this directly

Calls 6

upgradeMethod · 0.95
StringConverterClass · 0.90
assert_equalFunction · 0.90
assert_allcloseFunction · 0.90
assert_Function · 0.90
dtypeMethod · 0.45

Tested by

no test coverage detected