diff options
author | Barney Gale <barney.gale@gmail.com> | 2025-03-12 19:06:43 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-12 19:06:43 +0000 |
commit | db6a998b18e9476226507144b3b2fab854095dbc (patch) | |
tree | 1b3cabf1663573d00c1e166c0f9d777cd4326b98 /Lib/test/test_pathlib/test_pathlib_abc.py | |
parent | ea57ffa02e42dc430f2cb2312cdfc3d7ff7a5c70 (diff) | |
download | cpython-db6a998b18e9476226507144b3b2fab854095dbc.tar.gz cpython-db6a998b18e9476226507144b3b2fab854095dbc.zip |
GH-130614: pathlib ABCs: revise test suite for writable paths (#131112)
Test `pathlib.types._WritablePath` in a dedicated test module. These tests
cover `WritableZipPath`, `WritableLocalPath` and `Path`, where the former
two classes are implementations of `_WritablePath` for use in tests.
Diffstat (limited to 'Lib/test/test_pathlib/test_pathlib_abc.py')
-rw-r--r-- | Lib/test/test_pathlib/test_pathlib_abc.py | 41 |
1 files changed, 0 insertions, 41 deletions
diff --git a/Lib/test/test_pathlib/test_pathlib_abc.py b/Lib/test/test_pathlib/test_pathlib_abc.py index 02e2a1da7ee..cff4e3372b7 100644 --- a/Lib/test/test_pathlib/test_pathlib_abc.py +++ b/Lib/test/test_pathlib/test_pathlib_abc.py @@ -336,10 +336,6 @@ class ReadablePathTest(JoinablePathTest): class WritablePathTest(JoinablePathTest): cls = DummyWritablePath - def test_is_writable(self): - p = self.cls(self.base) - self.assertIsInstance(p, _WritablePath) - class DummyRWPath(DummyWritablePath, DummyReadablePath): __slots__ = () @@ -349,43 +345,6 @@ class RWPathTest(WritablePathTest, ReadablePathTest): cls = DummyRWPath can_symlink = False - def test_read_write_bytes(self): - p = self.cls(self.base) - (p / 'fileA').write_bytes(b'abcdefg') - self.assertEqual((p / 'fileA').read_bytes(), b'abcdefg') - # Check that trying to write str does not truncate the file. - self.assertRaises(TypeError, (p / 'fileA').write_bytes, 'somestr') - self.assertEqual((p / 'fileA').read_bytes(), b'abcdefg') - - def test_read_write_text(self): - p = self.cls(self.base) - (p / 'fileA').write_text('äbcdefg', encoding='latin-1') - self.assertEqual((p / 'fileA').read_text( - encoding='utf-8', errors='ignore'), 'bcdefg') - # Check that trying to write bytes does not truncate the file. - self.assertRaises(TypeError, (p / 'fileA').write_text, b'somebytes') - self.assertEqual((p / 'fileA').read_text(encoding='latin-1'), 'äbcdefg') - - def test_write_text_with_newlines(self): - p = self.cls(self.base) - # Check that `\n` character change nothing - (p / 'fileA').write_text('abcde\r\nfghlk\n\rmnopq', newline='\n') - self.assertEqual((p / 'fileA').read_bytes(), - b'abcde\r\nfghlk\n\rmnopq') - # Check that `\r` character replaces `\n` - (p / 'fileA').write_text('abcde\r\nfghlk\n\rmnopq', newline='\r') - self.assertEqual((p / 'fileA').read_bytes(), - b'abcde\r\rfghlk\r\rmnopq') - # Check that `\r\n` character replaces `\n` - (p / 'fileA').write_text('abcde\r\nfghlk\n\rmnopq', newline='\r\n') - self.assertEqual((p / 'fileA').read_bytes(), - b'abcde\r\r\nfghlk\r\n\rmnopq') - # Check that no argument passed will change `\n` to `os.linesep` - os_linesep_byte = bytes(os.linesep, encoding='ascii') - (p / 'fileA').write_text('abcde\nfghlk\n\rmnopq') - self.assertEqual((p / 'fileA').read_bytes(), - b'abcde' + os_linesep_byte + b'fghlk' + os_linesep_byte + b'\rmnopq') - def test_copy_file(self): base = self.cls(self.base) source = base / 'fileA' |