Skip to content

Commit a4ec954

Browse files
committed
Add workaround for PyFilesystem/pyfilesystem2#568 (Python 3.12)
1 parent bf9de50 commit a4ec954

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

pyfatfs/EightDotThree.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def set_byte_name(self, name: bytes):
7575
:param name: `bytes`: Padded (must be 11 bytes) 8dot3 name
7676
"""
7777
if not isinstance(name, bytes):
78-
raise TypeError(f"Given parameter must be of type bytes,"
78+
raise TypeError(f"Given parameter must be of type bytes, "
7979
f"but got {type(name)} instead.")
8080

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

100100
if not self.is_8dot3_conform(name, self.encoding):

pyfatfs/FatIO.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ def __repr__(self) -> str:
5757
5858
ex: <FatFile fs=<PyFat object> path="/README.txt" mode="r">
5959
"""
60-
return f'<{self.__class__.__name__} ' \
61-
f'fs={self.fs} ' \
62-
f'path="{self.name}" ' \
63-
f'mode="{self.mode}"'
60+
return str(f'<{self.__class__.__name__} '
61+
f'fs={self.fs} '
62+
f'path="{self.name}" '
63+
f'mode="{self.mode}"')
6464

6565
def seek(self, offset: int, whence: int = 0) -> int:
6666
"""Seek to a given offset in the file.

tests/test_PyFatFS.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,17 @@ def _make_fs(fat_type: int, **kwargs) -> (PyFatBytesIOFS, BytesIO):
3636
in_memory_fs)
3737

3838

39-
class TestPyFatFS16(FSTestCases, TestCase):
39+
class PyFsCompatLayer:
40+
"""PyFilesystem2 Python 3.12 compatibility layer.
41+
42+
Adds a workaround for PyFilesystem2#568:
43+
https://github.com/PyFilesystem/pyfilesystem2/issues/568
44+
"""
45+
46+
assertRaisesRegexp = TestCase.assertRaisesRegex
47+
48+
49+
class TestPyFatFS16(FSTestCases, TestCase, PyFsCompatLayer):
4050
"""Integration tests with PyFilesystem2 for FAT16."""
4151

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

109119

110-
class TestPyFatFS32(TestPyFatFS16, FSTestCases, TestCase):
120+
class TestPyFatFS32(TestPyFatFS16, FSTestCases, TestCase, PyFsCompatLayer):
111121
"""Integration tests with PyFilesystem2 for FAT32."""
112122

113123
FAT_TYPE = PyFat.FAT_TYPE_FAT32
114124

115125

116-
class TestPyFatFS12(TestPyFatFS16, FSTestCases, TestCase):
126+
class TestPyFatFS12(TestPyFatFS16, FSTestCases, TestCase, PyFsCompatLayer):
117127
"""Test specifics of FAT12 filesystem."""
118128

119129
FAT_TYPE = PyFat.FAT_TYPE_FAT12

0 commit comments

Comments
 (0)