8000 [3.8] Slightly improve plistlib test coverage. (GH-17025) (GH-17028) · python/cpython@fe934e1 · GitHub
[go: up one dir, main page]

Skip to content

Commit fe934e1

Browse files
bigfootjonserhiy-storchaka
authored andcommitted
[3.8] Slightly improve plistlib test coverage. (GH-17025) (GH-17028)
* Add missing test class (mistake in GH-4455) * Increase coverage with 4 more test cases * Rename neg_uid to huge_uid in test_modified_uid_huge * Replace test_main() with unittest.main() * Update plistlib docs. (cherry picked from commit d0d9f7c) Co-authored-by: Jon Janzen <jjjonjanzen@gmail.com>
1 parent 9528997 commit fe934e1

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

Doc/library/plistlib.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ The following classes are available:
188188
Wraps an :class:`int`. This is used when reading or writing NSKeyedArchiver
189189
encoded data, which contains UID (see PList manual).
190190

191-
It has one attribute, :attr:`data` which can be used to retrieve the int value
192-
of the UID. :attr:`data` must be in the range `0 <= data <= 2**64`.
191+
It has one attribute, :attr:`data`, which can be used to retrieve the int value
192+
of the UID. :attr:`data` must be in the range `0 <= data < 2**64`.
193193

194194
.. versionadded:: 3.8
195195

Lib/test/test_plistlib.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,26 @@ def test_xml_encodings(self):
505505
pl2 = plistlib.loads(data)
506506
self.assertEqual(dict(pl), dict(pl2))
507507

508+
def test_dump_invalid_format(self):
509+
with self.assertRaises(ValueError):
510+
plistlib.dumps({}, fmt="blah")
511+
512+
def test_load_invalid_file(self):
513+
with self.assertRaises(plistlib.InvalidFileException):
514+
plistlib.loads(b"these are not plist file contents")
515+
516+
def test_modified_uid_negative(self):
517+
neg_uid = UID(1)
518+
neg_uid.data = -1 # dodge the negative check in the constructor
519+
with self.assertRaises(ValueError):
520+
plistlib.dumps(neg_uid, fmt=plistlib.FMT_BINARY)
521+
522+
def test_modified_uid_huge(self):
523+
huge_uid = UID(1)
524+
huge_uid.data = 2 ** 64 # dodge the size check in the constructor
525+
with self.assertRaises(OverflowError):
526+
plistlib.dumps(huge_uid, fmt=plistlib.FMT_BINARY)
527+
508528

509529
class TestBinaryPlistlib(unittest.TestCase):
510530

@@ -748,9 +768,5 @@ def test__all__(self):
748768
support.check__all__(self, plistlib, blacklist=blacklist)
749769

750770

751-
def test_main():
752-
support.run_unittest(TestPlistlib, TestPlistlibDeprecated, TestKeyedArchive, MiscTestCase)
753-
754-
755771
if __name__ == '__main__':
756-
test_main()
772+
unittest.main()

0 commit comments

Comments
 (0)
0