diff --git a/pyfatfs/EightDotThree.py b/pyfatfs/EightDotThree.py index 57d0ac3..0791228 100644 --- a/pyfatfs/EightDotThree.py +++ b/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 a/pyfatfs/FatIO.py b/pyfatfs/FatIO.py index 5947bd0..67c316e 100644 --- a/pyfatfs/FatIO.py +++ b/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 a/tests/test_PyFatFS.py b/tests/test_PyFatFS.py index a62d307..c5771e4 100644 --- a/tests/test_PyFatFS.py +++ b/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