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

Method test_record_unicode

numpy/lib/tests/test_io.py:1317–1332  ·  view source on GitHub ↗
(self, path_type)

Source from the content-addressed store, hash-verified

1315
1316 @pytest.mark.parametrize("path_type", [str, Path])
1317 def test_record_unicode(self, path_type):
1318 utf8 = b'\xcf\x96'
1319 with temppath() as str_path:
1320 path = path_type(str_path)
1321 with open(path, 'wb') as f:
1322 f.write(b'1.312 foo' + utf8 + b' \n1.534 bar\n4.444 qux')
1323
1324 dt = [('num', np.float64), ('val', 'U4')]
1325 x = np.fromregex(path, r"(?u)([0-9.]+)\s+(\w+)", dt, encoding='UTF-8')
1326 a = np.array([(1.312, 'foo' + utf8.decode('UTF-8')), (1.534, 'bar'),
1327 (4.444, 'qux')], dtype=dt)
1328 assert_array_equal(x, a)
1329
1330 regexp = re.compile(r"([0-9.]+)\s+(\w+)", re.UNICODE)
1331 x = np.fromregex(path, regexp, dt, encoding='UTF-8')
1332 assert_array_equal(x, a)
1333
1334 def test_compiled_bytes(self):
1335 regexp = re.compile(br'(\d)')

Callers

nothing calls this directly

Calls 6

temppathFunction · 0.90
assert_array_equalFunction · 0.90
openFunction · 0.85
decodeMethod · 0.80
writeMethod · 0.45
compileMethod · 0.45

Tested by

no test coverage detected