-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_nsplist.py
More file actions
61 lines (46 loc) · 1.3 KB
/
test_nsplist.py
File metadata and controls
61 lines (46 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import nsplist
def encode_bin(data):
data = data.encode('hex')
joined = ' '.join(data[i:i + 2] for i in range(0, len(data), 2))
return '< ' + joined + ' >'
def test_dict():
data = '{\n\t"x" = "0";\n\t"y" = "1";\n\t"z" = "2";\n\t"t" = "3";\n}'
plist = nsplist.loads(data)
assert plist['x'] == '0'
assert plist['y'] == '1'
assert plist['z'] == '2'
assert plist['t'] == '3'
def test_list():
data = '("a", "b", c,)'
plist = nsplist.loads(data)
assert plist == ['a', 'b', 'c']
# def test_strange_strings():
# """From https://code.google.com/p/plist"""
# data = '''{
# "key&\102"="value&\U0042==";
# key2 = "strangestring\\\"";
# key3 = "strangestring\\";
# }'''
# plist = nsplist.loads(data)
# assert plist == {}
# def test_all_types():
# """From https://code.google.com/p/plist"""
# data = '''{
# keyA = valueA;
# "key&\102" = "value&\U0042";
# date = "2011-11-28T09:21:30Z";
# data = <00000004 10410820 82>;
# array = (
# YES,
# NO,
# 87,
# 3.14159
# );
# }'''
# plist = nsplist.loads(data)
# assert plist == {}
def test_binary():
data = '\xae\x9fg=\xe6\xaa?\x0bvS5\xfas\xea\x1c\xa7'
blob = encode_bin(data)
plist = nsplist.loads(blob)
assert data == plist