diff --git a/rdata/tests/test_rdata.py b/rdata/tests/test_rdata.py index 53c3f29..5783d19 100644 --- a/rdata/tests/test_rdata.py +++ b/rdata/tests/test_rdata.py @@ -711,12 +711,12 @@ def test_ascii(self) -> None: def test_ascii_characters(self) -> None: """Test reading string with all ascii printable characters.""" data = rdata.read_rds(TESTDATA_PATH / "test_ascii_chars.rds") - assert data == "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\v\f\r\n", data + assert data == "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\v\f\r\n", data # noqa: E501 def test_ascii_ascii_characters(self) -> None: """Test reading string with all ascii printable characters.""" data = rdata.read_rds(TESTDATA_PATH / "test_ascii_ascii_chars.rds") - assert data == "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\v\f\r\n", data + assert data == "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\v\f\r\n", data # noqa: E501 def test_nan_inf(self) -> None: """Test reading nan and inf.""" diff --git a/rdata/unparser/_ascii.py b/rdata/unparser/_ascii.py index bc1e2cc..50d9bc0 100644 --- a/rdata/unparser/_ascii.py +++ b/rdata/unparser/_ascii.py @@ -83,11 +83,13 @@ def unparse_string(self, value: bytes) -> None: # - ' ' that Python writes as ' ', but R as '\040' # - '\v' that Python writes as '\x0b', but R as '\v' # - '\f' that Python writes as '\x0c', but R as '\f' - write_raw = string.printable.replace(' ', '').replace('\v', '').replace('\f', '') + write_raw = string.printable.replace(" ", "")\ + .replace("\v", "")\ + .replace("\f", "") def escape(b: bytes) -> str: - """Escape string, e.g., b'\n' -> r'\\n'""" - return b.decode('latin1').encode('unicode_escape').decode('ascii') + r"""Escape string, e.g., b'\n' -> r'\\n'.""" + return b.decode("latin1").encode("unicode_escape").decode("ascii") # Go though the string byte-by-byte as we need to # convert every non-ascii character separately