| 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)') |