[Python-checkins] [3.8] Slightly improve plistlib test coverage. (GH-17025) (GH-17028)

Serhiy Storchaka webhook-mailer at python.org
Sat Nov 2 10:48:50 EDT 2019


https://github.com/python/cpython/commit/fe934e1d03bca6ca6dd1bf87fce1695eeac984ce
commit: fe934e1d03bca6ca6dd1bf87fce1695eeac984ce
branch: 3.8
author: Jon Janzen <jjjonjanzen at gmail.com>
committer: Serhiy Storchaka <storchaka at gmail.com>
date: 2019-11-02T16:48:22+02:00
summary:

[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 d0d9f7cfa36bafa4e1d9e73eb08835180d376df1)

Co-authored-by: Jon Janzen <jjjonjanzen at gmail.com>

files:
M Doc/library/plistlib.rst
M Lib/test/test_plistlib.py

diff --git a/Doc/library/plistlib.rst b/Doc/library/plistlib.rst
index d84fcac0ef23d..9dfe3c8a0dc98 100644
--- a/Doc/library/plistlib.rst
+++ b/Doc/library/plistlib.rst
@@ -188,8 +188,8 @@ The following classes are available:
    Wraps an :class:`int`.  This is used when reading or writing NSKeyedArchiver
    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`.
+   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`.
 
    .. versionadded:: 3.8
 
diff --git a/Lib/test/test_plistlib.py b/Lib/test/test_plistlib.py
index 5c2d0265079a2..0d887e210dde5 100644
--- a/Lib/test/test_plistlib.py
+++ b/Lib/test/test_plistlib.py
@@ -505,6 +505,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):
+        huge_uid = UID(1)
+        huge_uid.data = 2 ** 64  # dodge the size check in the constructor
+        with self.assertRaises(OverflowError):
+            plistlib.dumps(huge_uid, fmt=plistlib.FMT_BINARY)
+
 
 class TestBinaryPlistlib(unittest.TestCase):
 
@@ -748,9 +768,5 @@ def test__all__(self):
         support.check__all__(self, plistlib, blacklist=blacklist)
 
 
-def test_main():
-    support.run_unittest(TestPlistlib, TestPlistlibDeprecated, TestKeyedArchive, MiscTestCase)
-
-
 if __name__ == '__main__':
-    test_main()
+    unittest.main()



More information about the Python-checkins mailing list