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

Method test_record_unicode

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

Source from the content-addressed store, hash-verified

1304
1305 @pytest.mark.parametrize("path_type", [str, Path])
1306 def test_record_unicode(self, path_type):
1307 utf8 = b'\xcf\x96'
1308 with temppath() as str_path:
1309 path = path_type(str_path)
1310 with open(path, 'wb') as f:
1311 f.write(b'1.312 foo' + utf8 + b' \n1.534 bar\n4.444 qux')
1312
1313 dt = [('num', np.float64), ('val', 'U4')]
1314 x = np.fromregex(path, r"(?u)([0-9.]+)\s+(\w+)", dt, encoding='UTF-8')
1315 a = np.array([(1.312, 'foo' + utf8.decode('UTF-8')), (1.534, 'bar'),
1316 (4.444, 'qux')], dtype=dt)
1317 assert_array_equal(x, a)
1318
1319 regexp = re.compile(r"([0-9.]+)\s+(\w+)", re.UNICODE)
1320 x = np.fromregex(path, regexp, dt, encoding='UTF-8')
1321 assert_array_equal(x, a)
1322
1323 def test_compiled_bytes(self):
1324 regexp = re.compile(b'(\\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