annotate Lib/test/test_plistlib.py @ 79675:c0a2294de787 2.7

Issue #16199: Backport 2to3 typo fix from 3.2.
author Chris Jerdonek <chris.jerdonek@gmail.com>
date Thu, 11 Oct 2012 16:15:46 -0700
parents f5afadb745da
children a389700fbc74
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28056
a8c87a0beb98 Test suite for the plistlib module.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1 # Copyright (C) 2003 Python Software Foundation
a8c87a0beb98 Test suite for the plistlib module.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
2
a8c87a0beb98 Test suite for the plistlib module.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
3 import unittest
a8c87a0beb98 Test suite for the plistlib module.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
4 import plistlib
a8c87a0beb98 Test suite for the plistlib module.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
5 import os
33843
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
6 import datetime
28056
a8c87a0beb98 Test suite for the plistlib module.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
7 from test import test_support
a8c87a0beb98 Test suite for the plistlib module.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
8
33843
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
9
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
10 # This test data was generated through Cocoa's NSDictionary class
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
11 TESTDATA = """<?xml version="1.0" encoding="UTF-8"?>
60801
f5afadb745da Sync test_plistlib.py with plistlib.py
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 45468
diff changeset
12 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" \
33843
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
13 "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
14 <plist version="1.0">
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
15 <dict>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
16 <key>aDate</key>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
17 <date>2004-10-26T10:33:33Z</date>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
18 <key>aDict</key>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
19 <dict>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
20 <key>aFalseValue</key>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
21 <false/>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
22 <key>aTrueValue</key>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
23 <true/>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
24 <key>aUnicodeValue</key>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
25 <string>M\xc3\xa4ssig, Ma\xc3\x9f</string>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
26 <key>anotherString</key>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
27 <string>&lt;hello &amp; 'hi' there!&gt;</string>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
28 <key>deeperDict</key>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
29 <dict>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
30 <key>a</key>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
31 <integer>17</integer>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
32 <key>b</key>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
33 <real>32.5</real>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
34 <key>c</key>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
35 <array>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
36 <integer>1</integer>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
37 <integer>2</integer>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
38 <string>text</string>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
39 </array>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
40 </dict>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
41 </dict>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
42 <key>aFloat</key>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
43 <real>0.5</real>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
44 <key>aList</key>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
45 <array>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
46 <string>A</string>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
47 <string>B</string>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
48 <integer>12</integer>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
49 <real>32.5</real>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
50 <array>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
51 <integer>1</integer>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
52 <integer>2</integer>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
53 <integer>3</integer>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
54 </array>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
55 </array>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
56 <key>aString</key>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
57 <string>Doodah</string>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
58 <key>anInt</key>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
59 <integer>728</integer>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
60 <key>nestedData</key>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
61 <array>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
62 <data>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
63 PGxvdHMgb2YgYmluYXJ5IGd1bms+AAECAzxsb3RzIG9mIGJpbmFyeSBndW5r
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
64 PgABAgM8bG90cyBvZiBiaW5hcnkgZ3Vuaz4AAQIDPGxvdHMgb2YgYmluYXJ5
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
65 IGd1bms+AAECAzxsb3RzIG9mIGJpbmFyeSBndW5rPgABAgM8bG90cyBvZiBi
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
66 aW5hcnkgZ3Vuaz4AAQIDPGxvdHMgb2YgYmluYXJ5IGd1bms+AAECAzxsb3Rz
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
67 IG9mIGJpbmFyeSBndW5rPgABAgM8bG90cyBvZiBiaW5hcnkgZ3Vuaz4AAQID
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
68 PGxvdHMgb2YgYmluYXJ5IGd1bms+AAECAw==
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
69 </data>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
70 </array>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
71 <key>someData</key>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
72 <data>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
73 PGJpbmFyeSBndW5rPg==
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
74 </data>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
75 <key>someMoreData</key>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
76 <data>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
77 PGxvdHMgb2YgYmluYXJ5IGd1bms+AAECAzxsb3RzIG9mIGJpbmFyeSBndW5rPgABAgM8
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
78 bG90cyBvZiBiaW5hcnkgZ3Vuaz4AAQIDPGxvdHMgb2YgYmluYXJ5IGd1bms+AAECAzxs
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
79 b3RzIG9mIGJpbmFyeSBndW5rPgABAgM8bG90cyBvZiBiaW5hcnkgZ3Vuaz4AAQIDPGxv
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
80 dHMgb2YgYmluYXJ5IGd1bms+AAECAzxsb3RzIG9mIGJpbmFyeSBndW5rPgABAgM8bG90
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
81 cyBvZiBiaW5hcnkgZ3Vuaz4AAQIDPGxvdHMgb2YgYmluYXJ5IGd1bms+AAECAw==
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
82 </data>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
83 <key>\xc3\x85benraa</key>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
84 <string>That was a unicode key.</string>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
85 </dict>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
86 </plist>
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
87 """.replace(" " * 8, "\t") # Apple as well as plistlib.py output hard tabs
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
88
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
89
28056
a8c87a0beb98 Test suite for the plistlib module.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
90 class TestPlistlib(unittest.TestCase):
a8c87a0beb98 Test suite for the plistlib module.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
91
a8c87a0beb98 Test suite for the plistlib module.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
92 def tearDown(self):
a8c87a0beb98 Test suite for the plistlib module.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
93 try:
a8c87a0beb98 Test suite for the plistlib module.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
94 os.unlink(test_support.TESTFN)
a8c87a0beb98 Test suite for the plistlib module.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
95 except:
a8c87a0beb98 Test suite for the plistlib module.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
96 pass
a8c87a0beb98 Test suite for the plistlib module.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
97
a8c87a0beb98 Test suite for the plistlib module.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
98 def _create(self):
33843
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
99 pl = dict(
28056
a8c87a0beb98 Test suite for the plistlib module.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
100 aString="Doodah",
33843
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
101 aList=["A", "B", 12, 32.5, [1, 2, 3]],
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
102 aFloat = 0.5,
28056
a8c87a0beb98 Test suite for the plistlib module.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
103 anInt = 728,
33843
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
104 aDict=dict(
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
105 anotherString="<hello & 'hi' there!>",
28056
a8c87a0beb98 Test suite for the plistlib module.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
106 aUnicodeValue=u'M\xe4ssig, Ma\xdf',
a8c87a0beb98 Test suite for the plistlib module.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
107 aTrueValue=True,
a8c87a0beb98 Test suite for the plistlib module.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
108 aFalseValue=False,
33843
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
109 deeperDict=dict(a=17, b=32.5, c=[1, 2, "text"]),
28056
a8c87a0beb98 Test suite for the plistlib module.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
110 ),
a8c87a0beb98 Test suite for the plistlib module.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
111 someData = plistlib.Data("<binary gunk>"),
33843
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
112 someMoreData = plistlib.Data("<lots of binary gunk>\0\1\2\3" * 10),
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
113 nestedData = [plistlib.Data("<lots of binary gunk>\0\1\2\3" * 10)],
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
114 aDate = datetime.datetime(2004, 10, 26, 10, 33, 33),
28056
a8c87a0beb98 Test suite for the plistlib module.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
115 )
33843
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
116 pl[u'\xc5benraa'] = "That was a unicode key."
28056
a8c87a0beb98 Test suite for the plistlib module.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
117 return pl
28231
4cafa5141012 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 28056
diff changeset
118
28056
a8c87a0beb98 Test suite for the plistlib module.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
119 def test_create(self):
a8c87a0beb98 Test suite for the plistlib module.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
120 pl = self._create()
a8c87a0beb98 Test suite for the plistlib module.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
121 self.assertEqual(pl["aString"], "Doodah")
a8c87a0beb98 Test suite for the plistlib module.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
122 self.assertEqual(pl["aDict"]["aFalseValue"], False)
a8c87a0beb98 Test suite for the plistlib module.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
123
a8c87a0beb98 Test suite for the plistlib module.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
124 def test_io(self):
a8c87a0beb98 Test suite for the plistlib module.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
125 pl = self._create()
33649
7450bb93c395 use new readPlist() and writePlist() functions
Just van Rossum <just@letterror.com>
parents: 29728
diff changeset
126 plistlib.writePlist(pl, test_support.TESTFN)
7450bb93c395 use new readPlist() and writePlist() functions
Just van Rossum <just@letterror.com>
parents: 29728
diff changeset
127 pl2 = plistlib.readPlist(test_support.TESTFN)
28231
4cafa5141012 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 28056
diff changeset
128 self.assertEqual(dict(pl), dict(pl2))
28056
a8c87a0beb98 Test suite for the plistlib module.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
129
33843
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
130 def test_string(self):
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
131 pl = self._create()
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
132 data = plistlib.writePlistToString(pl)
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
133 pl2 = plistlib.readPlistFromString(data)
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
134 self.assertEqual(dict(pl), dict(pl2))
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
135 data2 = plistlib.writePlistToString(pl2)
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
136 self.assertEqual(data, data2)
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
137
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
138 def test_appleformatting(self):
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
139 pl = plistlib.readPlistFromString(TESTDATA)
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
140 data = plistlib.writePlistToString(pl)
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
141 self.assertEqual(data, TESTDATA,
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
142 "generated data was not identical to Apple's output")
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
143
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
144 def test_appleformattingfromliteral(self):
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
145 pl = self._create()
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
146 pl2 = plistlib.readPlistFromString(TESTDATA)
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
147 self.assertEqual(dict(pl), dict(pl2),
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
148 "generated data was not identical to Apple's output")
ac4fa942f92e - Added tests for the string load/dump function.
Just van Rossum <just@letterror.com>
parents: 33649
diff changeset
149
29728
4c90a631d632 - added (c)StringIO tests; cStringIO usage failed in the previous
Just van Rossum <just@letterror.com>
parents: 28231
diff changeset
150 def test_stringio(self):
4c90a631d632 - added (c)StringIO tests; cStringIO usage failed in the previous
Just van Rossum <just@letterror.com>
parents: 28231
diff changeset
151 from StringIO import StringIO
4c90a631d632 - added (c)StringIO tests; cStringIO usage failed in the previous
Just van Rossum <just@letterror.com>
parents: 28231
diff changeset
152 f = StringIO()
4c90a631d632 - added (c)StringIO tests; cStringIO usage failed in the previous
Just van Rossum <just@letterror.com>
parents: 28231
diff changeset
153 pl = self._create()
33649
7450bb93c395 use new readPlist() and writePlist() functions
Just van Rossum <just@letterror.com>
parents: 29728
diff changeset
154 plistlib.writePlist(pl, f)
7450bb93c395 use new readPlist() and writePlist() functions
Just van Rossum <just@letterror.com>
parents: 29728
diff changeset
155 pl2 = plistlib.readPlist(StringIO(f.getvalue()))
29728
4c90a631d632 - added (c)StringIO tests; cStringIO usage failed in the previous
Just van Rossum <just@letterror.com>
parents: 28231
diff changeset
156 self.assertEqual(dict(pl), dict(pl2))
4c90a631d632 - added (c)StringIO tests; cStringIO usage failed in the previous
Just van Rossum <just@letterror.com>
parents: 28231
diff changeset
157
4c90a631d632 - added (c)StringIO tests; cStringIO usage failed in the previous
Just van Rossum <just@letterror.com>
parents: 28231
diff changeset
158 def test_cstringio(self):
4c90a631d632 - added (c)StringIO tests; cStringIO usage failed in the previous
Just van Rossum <just@letterror.com>
parents: 28231
diff changeset
159 from cStringIO import StringIO
4c90a631d632 - added (c)StringIO tests; cStringIO usage failed in the previous
Just van Rossum <just@letterror.com>
parents: 28231
diff changeset
160 f = StringIO()
4c90a631d632 - added (c)StringIO tests; cStringIO usage failed in the previous
Just van Rossum <just@letterror.com>
parents: 28231
diff changeset
161 pl = self._create()
33649
7450bb93c395 use new readPlist() and writePlist() functions
Just van Rossum <just@letterror.com>
parents: 29728
diff changeset
162 plistlib.writePlist(pl, f)
7450bb93c395 use new readPlist() and writePlist() functions
Just van Rossum <just@letterror.com>
parents: 29728
diff changeset
163 pl2 = plistlib.readPlist(StringIO(f.getvalue()))
29728
4c90a631d632 - added (c)StringIO tests; cStringIO usage failed in the previous
Just van Rossum <just@letterror.com>
parents: 28231
diff changeset
164 self.assertEqual(dict(pl), dict(pl2))
4c90a631d632 - added (c)StringIO tests; cStringIO usage failed in the previous
Just van Rossum <just@letterror.com>
parents: 28231
diff changeset
165
33978
33a846b777a8 testing control chars and non-dict root objects
Just van Rossum <just@letterror.com>
parents: 33843
diff changeset
166 def test_controlcharacters(self):
33979
f92616f8c33c On second thought: "Errors should never pass silently", so barf when a
Just van Rossum <just@letterror.com>
parents: 33978
diff changeset
167 for i in range(128):
f92616f8c33c On second thought: "Errors should never pass silently", so barf when a
Just van Rossum <just@letterror.com>
parents: 33978
diff changeset
168 c = chr(i)
f92616f8c33c On second thought: "Errors should never pass silently", so barf when a
Just van Rossum <just@letterror.com>
parents: 33978
diff changeset
169 testString = "string containing %s" % c
f92616f8c33c On second thought: "Errors should never pass silently", so barf when a
Just van Rossum <just@letterror.com>
parents: 33978
diff changeset
170 if i >= 32 or c in "\r\n\t":
f92616f8c33c On second thought: "Errors should never pass silently", so barf when a
Just van Rossum <just@letterror.com>
parents: 33978
diff changeset
171 # \r, \n and \t are the only legal control chars in XML
f92616f8c33c On second thought: "Errors should never pass silently", so barf when a
Just van Rossum <just@letterror.com>
parents: 33978
diff changeset
172 plistlib.writePlistToString(testString)
f92616f8c33c On second thought: "Errors should never pass silently", so barf when a
Just van Rossum <just@letterror.com>
parents: 33978
diff changeset
173 else:
f92616f8c33c On second thought: "Errors should never pass silently", so barf when a
Just van Rossum <just@letterror.com>
parents: 33978
diff changeset
174 self.assertRaises(ValueError,
f92616f8c33c On second thought: "Errors should never pass silently", so barf when a
Just van Rossum <just@letterror.com>
parents: 33978
diff changeset
175 plistlib.writePlistToString,
f92616f8c33c On second thought: "Errors should never pass silently", so barf when a
Just van Rossum <just@letterror.com>
parents: 33978
diff changeset
176 testString)
33978
33a846b777a8 testing control chars and non-dict root objects
Just van Rossum <just@letterror.com>
parents: 33843
diff changeset
177
33a846b777a8 testing control chars and non-dict root objects
Just van Rossum <just@letterror.com>
parents: 33843
diff changeset
178 def test_nondictroot(self):
33a846b777a8 testing control chars and non-dict root objects
Just van Rossum <just@letterror.com>
parents: 33843
diff changeset
179 test1 = "abc"
33a846b777a8 testing control chars and non-dict root objects
Just van Rossum <just@letterror.com>
parents: 33843
diff changeset
180 test2 = [1, 2, 3, "abc"]
33a846b777a8 testing control chars and non-dict root objects
Just van Rossum <just@letterror.com>
parents: 33843
diff changeset
181 result1 = plistlib.readPlistFromString(plistlib.writePlistToString(test1))
33a846b777a8 testing control chars and non-dict root objects
Just van Rossum <just@letterror.com>
parents: 33843
diff changeset
182 result2 = plistlib.readPlistFromString(plistlib.writePlistToString(test2))
33a846b777a8 testing control chars and non-dict root objects
Just van Rossum <just@letterror.com>
parents: 33843
diff changeset
183 self.assertEqual(test1, result1)
33a846b777a8 testing control chars and non-dict root objects
Just van Rossum <just@letterror.com>
parents: 33843
diff changeset
184 self.assertEqual(test2, result2)
28056
a8c87a0beb98 Test suite for the plistlib module.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
185
a8c87a0beb98 Test suite for the plistlib module.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
186
a8c87a0beb98 Test suite for the plistlib module.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
187 def test_main():
a8c87a0beb98 Test suite for the plistlib module.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
188 test_support.run_unittest(TestPlistlib)
a8c87a0beb98 Test suite for the plistlib module.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
189
a8c87a0beb98 Test suite for the plistlib module.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
190
a8c87a0beb98 Test suite for the plistlib module.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
191 if __name__ == '__main__':
a8c87a0beb98 Test suite for the plistlib module.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
192 test_main()