Skip to content

Commit d0d9f7c

Browse files
bigfootjonserhiy-storchaka
authored andcommitted
Slightly improve plistlib test coverage. (GH-17025)
* 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
1 parent 9bc94ec commit d0d9f7c

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

Doc/library/plistlib.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ The following classes are available:
133133
encoded data, which contains UID (see PList manual).
134134

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

138138
.. versionadded:: 3.8
139139

Lib/test/test_plistlib.py

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

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

507527
class TestBinaryPlistlib(unittest.TestCase):
508528

@@ -655,9 +675,5 @@ def test__all__(self):
655675
support.check__all__(self, plistlib, blacklist=blacklist)
656676

657677

658-
def test_main():
659-
support.run_unittest(TestPlistlib, TestKeyedArchive, MiscTestCase)
660-
661-
662678
if __name__ == '__main__':
663-
test_main()
679+
unittest.main()

0 commit comments

Comments
 (0)