Skip to content

Commit

Permalink
Add workaround for PyFilesystem/pyfilesystem2#568 (Python 3.12)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanhi committed Oct 15, 2023
1 parent 5112a58 commit 3b91a14
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
4 changes: 2 additions & 2 deletions pyfatfs/EightDotThree.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def set_byte_name(self, name: bytes):
:param name: `bytes`: Padded (must be 11 bytes) 8dot3 name
"""
if not isinstance(name, bytes):
raise TypeError(f"Given parameter must be of type bytes,"
raise TypeError(f"Given parameter must be of type bytes, "
f"but got {type(name)} instead.")

name = bytearray(name)
Expand All @@ -94,7 +94,7 @@ def set_byte_name(self, name: bytes):
def set_str_name(self, name: str):
"""Set the name as string from user input (i.e. folder creation)."""
if not isinstance(name, str):
raise TypeError(f"Given parameter must be of type str,"
raise TypeError(f"Given parameter must be of type str, "
f"but got {type(name)} instead.")

if not self.is_8dot3_conform(name, self.encoding):
Expand Down
8 changes: 4 additions & 4 deletions pyfatfs/FatIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ def __repr__(self) -> str:
ex: <FatFile fs=<PyFat object> path="/README.txt" mode="r">
"""
return f'<{self.__class__.__name__} ' \
f'fs={self.fs} ' \
f'path="{self.name}" ' \
f'mode="{self.mode}"'
return str(f'<{self.__class__.__name__} '
f'fs={self.fs} '
f'path="{self.name}" '
f'mode="{self.mode}"')

def seek(self, offset: int, whence: int = 0) -> int:
"""Seek to a given offset in the file.
Expand Down
16 changes: 13 additions & 3 deletions tests/test_PyFatFS.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,17 @@ def _make_fs(fat_type: int, **kwargs) -> (PyFatBytesIOFS, BytesIO):
in_memory_fs)


class TestPyFatFS16(FSTestCases, TestCase):
class PyFsCompatLayer:
"""PyFilesystem2 Python 3.12 compatibility layer.
Adds a workaround for PyFilesystem2#568:
https://github.com/PyFilesystem/pyfilesystem2/issues/568
"""

assertRaisesRegexp = TestCase.assertRaisesRegex


class TestPyFatFS16(FSTestCases, TestCase, PyFsCompatLayer):
"""Integration tests with PyFilesystem2 for FAT16."""

FAT_TYPE = PyFat.FAT_TYPE_FAT16
Expand Down Expand Up @@ -107,13 +117,13 @@ def test_writetest_truncates(self):
assert self.fs.readtext(fname) == '1' * 16


class TestPyFatFS32(TestPyFatFS16, FSTestCases, TestCase):
class TestPyFatFS32(TestPyFatFS16, FSTestCases, TestCase, PyFsCompatLayer):
"""Integration tests with PyFilesystem2 for FAT32."""

FAT_TYPE = PyFat.FAT_TYPE_FAT32


class TestPyFatFS12(TestPyFatFS16, FSTestCases, TestCase):
class TestPyFatFS12(TestPyFatFS16, FSTestCases, TestCase, PyFsCompatLayer):
"""Test specifics of FAT12 filesystem."""

FAT_TYPE = PyFat.FAT_TYPE_FAT12
Expand Down

0 comments on commit 3b91a14

Please sign in to comment.