Skip to content

Commit

Permalink
Fix ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
trossi committed Sep 11, 2024
1 parent 26a626c commit 4c825b4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions rdata/tests/test_rdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
8 changes: 5 additions & 3 deletions rdata/unparser/_ascii.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4c825b4

Please sign in to comment.