https://github.com/nathanhi/pyfatfs/commit/a4ec954fc12ff212740bc06ca962d539111e0f60.patch From a4ec954fc12ff212740bc06ca962d539111e0f60 Mon Sep 17 00:00:00 2001 From: "Nathan-J. Hirschauer" Date: Sun, 15 Oct 2023 11:27:55 +0200 Subject: [PATCH] Add workaround for PyFilesystem/pyfilesystem2#568 (Python 3.12) --- pyfatfs/EightDotThree.py | 4 ++-- pyfatfs/FatIO.py | 8 ++++---- tests/test_PyFatFS.py | 16 +++++++++++++--- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git pyfatfs/EightDotThree.py pyfatfs/EightDotThree.py index 57d0ac3..0791228 100644 --- pyfatfs/EightDotThree.py +++ pyfatfs/EightDotThree.py @@ -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) @@ -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): diff --git pyfatfs/FatIO.py pyfatfs/FatIO.py index 5947bd0..67c316e 100644 --- pyfatfs/FatIO.py +++ pyfatfs/FatIO.py @@ -57,10 +57,10 @@ def __repr__(self) -> str: ex: 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. diff --git tests/test_PyFatFS.py tests/test_PyFatFS.py index a62d307..c5771e4 100644 --- tests/test_PyFatFS.py +++ tests/test_PyFatFS.py @@ -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 @@ -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