MCPcopy Index your code
hub / github.com/numpy/numpy / test_upgrade

Method test_upgrade

numpy/lib/tests/test__iotools.py:154–189  ·  view source on GitHub ↗

Tests the upgrade method.

(self)

Source from the content-addressed store, hash-verified

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