Skip to content

Slightly improve plistlib test coverage #17025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Doc/library/plistlib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
26 changes: 21 additions & 5 deletions Lib/test/test_plistlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
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):

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


def test_main():
support.run_unittest(TestPlistlib, TestKeyedArchive, MiscTestCase)


if __name__ == '__main__':
test_main()
unittest.main()