From d94f44e70971a360e76b224ffcdede81dbd7c768 Mon Sep 17 00:00:00 2001 From: Jonathan Janzen Date: Sat, 7 Sep 2019 16:34:40 -0500 Subject: [PATCH 1/5] Add missing test class (mistake in GH-4455) --- Lib/test/test_plistlib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_plistlib.py b/Lib/test/test_plistlib.py index d3ef6f8ffe3a41b..09404a9505eda85 100644 --- a/Lib/test/test_plistlib.py +++ b/Lib/test/test_plistlib.py @@ -656,7 +656,7 @@ def test__all__(self): def test_main(): - support.run_unittest(TestPlistlib, TestKeyedArchive, MiscTestCase) + support.run_unittest(TestPlistlib, TestBinaryPlistlib, TestKeyedArchive, MiscTestCase) if __name__ == '__main__': From 8c3541aecc0639d160d2acd5e0b306adb03c88b3 Mon Sep 17 00:00:00 2001 From: Jonathan Janzen Date: Sat, 7 Sep 2019 16:34:57 -0500 Subject: [PATCH 2/5] Increase coverage with 4 more test cases --- Lib/test/test_plistlib.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Lib/test/test_plistlib.py b/Lib/test/test_plistlib.py index 09404a9505eda85..cdec47375460dff 100644 --- a/Lib/test/test_plistlib.py +++ b/Lib/test/test_plistlib.py @@ -503,6 +503,26 @@ def test_xml_encodings(self): pl2 = plistlib.loads(data) self.assertEqual(dict(pl), dict(pl2)) + def test_dump_invalid_format(self): + with self.assertRaises(ValueError): + plistlib.dumps({}, fmt="blah") + + def test_load_invalid_file(self): + with self.assertRaises(plistlib.InvalidFileException): + plistlib.loads(b"these are not plist file contents") + + def test_modified_uid_negative(self): + neg_uid = UID(1) + neg_uid.data = -1 # dodge the negative check in the constructor + with self.assertRaises(ValueError): + plistlib.dumps(neg_uid, fmt=plistlib.FMT_BINARY) + + def test_modified_uid_huge(self): + neg_uid = UID(1) + neg_uid.data = 2 ** 64 # dodge the size check in the constructor + with self.assertRaises(OverflowError): + plistlib.dumps(neg_uid, fmt=plistlib.FMT_BINARY) + class TestBinaryPlistlib(unittest.TestCase): From ba1add3cac09c3143046b9ef2224e7a3e163f1fb Mon Sep 17 00:00:00 2001 From: Jon Janzen Date: Fri, 1 Nov 2019 11:01:25 -0500 Subject: [PATCH 3/5] Rename neg_uid to huge_uid in test_modified_uid_huge --- Lib/test/test_plistlib.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_plistlib.py b/Lib/test/test_plistlib.py index cdec47375460dff..543ee9b8ebf2a02 100644 --- a/Lib/test/test_plistlib.py +++ b/Lib/test/test_plistlib.py @@ -518,10 +518,10 @@ def test_modified_uid_negative(self): plistlib.dumps(neg_uid, fmt=plistlib.FMT_BINARY) def test_modified_uid_huge(self): - neg_uid = UID(1) - neg_uid.data = 2 ** 64 # dodge the size check in the constructor + huge_uid = UID(1) + huge_uid.data = 2 ** 64 # dodge the size check in the constructor with self.assertRaises(OverflowError): - plistlib.dumps(neg_uid, fmt=plistlib.FMT_BINARY) + plistlib.dumps(huge_uid, fmt=plistlib.FMT_BINARY) class TestBinaryPlistlib(unittest.TestCase): From acdca3d6e978a36116f67c23ad410b7236ceaa2d Mon Sep 17 00:00:00 2001 From: Jon Janzen Date: Fri, 1 Nov 2019 11:04:55 -0500 Subject: [PATCH 4/5] Replace test_main() with unittest.main() --- Lib/test/test_plistlib.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Lib/test/test_plistlib.py b/Lib/test/test_plistlib.py index 543ee9b8ebf2a02..e82a53c533df037 100644 --- a/Lib/test/test_plistlib.py +++ b/Lib/test/test_plistlib.py @@ -675,9 +675,5 @@ def test__all__(self): support.check__all__(self, plistlib, blacklist=blacklist) -def test_main(): - support.run_unittest(TestPlistlib, TestBinaryPlistlib, TestKeyedArchive, MiscTestCase) - - if __name__ == '__main__': - test_main() + unittest.main() From 7aeec8d27330185c9bd50cef055f795eb1b5386b Mon Sep 17 00:00:00 2001 From: Jon Janzen Date: Fri, 1 Nov 2019 11:07:28 -0500 Subject: [PATCH 5/5] Update plistlib docs --- Doc/library/plistlib.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/plistlib.rst b/Doc/library/plistlib.rst index 68320f15777109f..6def72b3736b91d 100644 --- a/Doc/library/plistlib.rst +++ b/Doc/library/plistlib.rst @@ -133,7 +133,7 @@ The following classes are available: encoded data, which contains UID (see PList manual). It has one attribute, :attr:`data`, which can be used to retrieve the int value - of the UID. :attr:`data` must be in the range `0 <= data <= 2**64`. + of the UID. :attr:`data` must be in the range `0 <= data < 2**64`. .. versionadded:: 3.8