1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-07-13 01:20:24 +02:00

add plist tests

This commit is contained in:
Kelly Brazil
2022-08-01 11:11:26 -07:00
parent 02f7d73fca
commit 63961d8711
6 changed files with 79 additions and 0 deletions

View File

@ -0,0 +1 @@
{"aDate":1659369751,"aDict":{"aFalseValue":false,"aThirdString":"Mässig, Maß","aTrueValue":true,"anotherString":"<hello & hi there!>"},"aFloat":0.1,"aList":["A","B",12,32.1,[1,2,3]],"aString":"Doodah","anInt":728,"someData":"3c:62:69:6e:61:72:79:20:67:75:6e:6b:3e","someMoreData":"3c:6c:6f:74:73:20:6f:66:20:62:69:6e:61:72:79:20:67:75:6e:6b:3e:3c:6c:6f:74:73:20:6f:66:20:62:69:6e:61:72:79:20:67:75:6e:6b:3e:3c:6c:6f:74:73:20:6f:66:20:62:69:6e:61:72:79:20:67:75:6e:6b:3e:3c:6c:6f:74:73:20:6f:66:20:62:69:6e:61:72:79:20:67:75:6e:6b:3e:3c:6c:6f:74:73:20:6f:66:20:62:69:6e:61:72:79:20:67:75:6e:6b:3e:3c:6c:6f:74:73:20:6f:66:20:62:69:6e:61:72:79:20:67:75:6e:6b:3e:3c:6c:6f:74:73:20:6f:66:20:62:69:6e:61:72:79:20:67:75:6e:6b:3e:3c:6c:6f:74:73:20:6f:66:20:62:69:6e:61:72:79:20:67:75:6e:6b:3e:3c:6c:6f:74:73:20:6f:66:20:62:69:6e:61:72:79:20:67:75:6e:6b:3e:3c:6c:6f:74:73:20:6f:66:20:62:69:6e:61:72:79:20:67:75:6e:6b:3e","aDate_iso":"2022-08-01T09:02:31.181281"}

Binary file not shown.

View File

@ -0,0 +1 @@
{"aDate":1659310470,"aDict":{"aFalseValue":false,"aThirdString":"Mässig, Maß","aTrueValue":true,"anotherString":"<hello & hi there!>"},"aFloat":0.1,"aList":["A","B",12,32.1,[1,2,3]],"aString":"Doodah","anInt":728,"someData":"3c:62:69:6e:61:72:79:20:67:75:6e:6b:3e","someMoreData":"3c:6c:6f:74:73:20:6f:66:20:62:69:6e:61:72:79:20:67:75:6e:6b:3e:3c:6c:6f:74:73:20:6f:66:20:62:69:6e:61:72:79:20:67:75:6e:6b:3e:3c:6c:6f:74:73:20:6f:66:20:62:69:6e:61:72:79:20:67:75:6e:6b:3e:3c:6c:6f:74:73:20:6f:66:20:62:69:6e:61:72:79:20:67:75:6e:6b:3e:3c:6c:6f:74:73:20:6f:66:20:62:69:6e:61:72:79:20:67:75:6e:6b:3e:3c:6c:6f:74:73:20:6f:66:20:62:69:6e:61:72:79:20:67:75:6e:6b:3e:3c:6c:6f:74:73:20:6f:66:20:62:69:6e:61:72:79:20:67:75:6e:6b:3e:3c:6c:6f:74:73:20:6f:66:20:62:69:6e:61:72:79:20:67:75:6e:6b:3e:3c:6c:6f:74:73:20:6f:66:20:62:69:6e:61:72:79:20:67:75:6e:6b:3e:3c:6c:6f:74:73:20:6f:66:20:62:69:6e:61:72:79:20:67:75:6e:6b:3e","aDate_iso":"2022-07-31T16:34:30"}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

75
tests/test_plist.py Normal file
View File

@ -0,0 +1,75 @@
import os
import unittest
import json
import jc.parsers.plist
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
class MyTests(unittest.TestCase):
def setUp(self):
# input
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/plist-garageband-info.plist'), 'rb') as f:
self.generic_garageband = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/plist-safari-info.plist'), 'r', encoding='utf-8') as f:
self.generic_safari = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/plist-alltypes.plist'), 'r', encoding='utf-8') as f:
self.generic_alltypes = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/plist-alltypes-bin.plist'), 'rb') as f:
self.generic_alltypes_bin = f.read()
# output
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/plist-garageband-info.json'), 'r', encoding='utf-8') as f:
self.generic_garageband_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/plist-safari-info.json'), 'r', encoding='utf-8') as f:
self.generic_safari_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/plist-alltypes.json'), 'r', encoding='utf-8') as f:
self.generic_alltypes_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/plist-alltypes-bin.json'), 'r', encoding='utf-8') as f:
self.generic_alltypes_bin_json = json.loads(f.read())
def test_plist_nodata(self):
"""
Test 'plist' with no data
"""
self.assertEqual(jc.parsers.plist.parse('', quiet=True), {})
def test_plist_binary(self):
"""
Test binary plist file (garage band)
"""
self.assertEqual(jc.parsers.plist.parse(self.generic_garageband, quiet=True), self.generic_garageband_json)
def test_plist_xml(self):
"""
Test XML plist file (safari)
"""
self.assertEqual(jc.parsers.plist.parse(self.generic_safari, quiet=True), self.generic_safari_json)
def test_plist_xml_alltypes(self):
"""
Test XML plist file with all object types
"""
self.assertEqual(jc.parsers.plist.parse(self.generic_alltypes, quiet=True), self.generic_alltypes_json)
def test_plist_bin_alltypes(self):
"""
Test binary plist file with all object types
"""
self.assertEqual(jc.parsers.plist.parse(self.generic_alltypes_bin, quiet=True), self.generic_alltypes_bin_json)
if __name__ == '__main__':
unittest.main()