()
| 2424 | |
| 2425 | |
| 2426 | def test_encode_decode_errors() -> None: |
| 2427 | encodeBase = xr.DataArray(["a", "b", "a\x9d"]) |
| 2428 | |
| 2429 | msg = ( |
| 2430 | r"'charmap' codec can't encode character '\\x9d' in position 1:" |
| 2431 | " character maps to <undefined>" |
| 2432 | ) |
| 2433 | with pytest.raises(UnicodeEncodeError, match=msg): |
| 2434 | encodeBase.str.encode("cp1252") |
| 2435 | |
| 2436 | f = lambda x: x.encode("cp1252", "ignore") |
| 2437 | result = encodeBase.str.encode("cp1252", "ignore") |
| 2438 | expected = xr.DataArray([f(x) for x in encodeBase.values.tolist()]) |
| 2439 | |
| 2440 | assert result.dtype == expected.dtype |
| 2441 | assert_equal(result, expected) |
| 2442 | |
| 2443 | decodeBase = xr.DataArray([b"a", b"b", b"a\x9d"]) |
| 2444 | |
| 2445 | msg = ( |
| 2446 | "'charmap' codec can't decode byte 0x9d in position 1:" |
| 2447 | " character maps to <undefined>" |
| 2448 | ) |
| 2449 | with pytest.raises(UnicodeDecodeError, match=msg): |
| 2450 | decodeBase.str.decode("cp1252") |
| 2451 | |
| 2452 | f = lambda x: x.decode("cp1252", "ignore") |
| 2453 | result = decodeBase.str.decode("cp1252", "ignore") |
| 2454 | expected = xr.DataArray([f(x) for x in decodeBase.values.tolist()]) |
| 2455 | |
| 2456 | assert result.dtype == expected.dtype |
| 2457 | assert_equal(result, expected) |
| 2458 | |
| 2459 | |
| 2460 | def test_partition_whitespace(dtype) -> None: |
nothing calls this directly
no test coverage detected
searching dependent graphs…