Back to index

python3.2  3.2.2
Public Member Functions | Private Member Functions
test.test_plistlib.TestPlistlib Class Reference

List of all members.

Public Member Functions

def tearDown
def test_create
def test_io
def test_bytes
def test_appleformatting
def test_appleformattingfromliteral
def test_bytesio
def test_controlcharacters
def test_nondictroot
def test_invalidarray
def test_invaliddict
def test_invalidinteger
def test_invalidreal

Private Member Functions

def _create

Detailed Description

Definition at line 90 of file test_plistlib.py.


Member Function Documentation

def test.test_plistlib.TestPlistlib._create (   self) [private]

Definition at line 98 of file test_plistlib.py.

00098 
00099     def _create(self):
00100         pl = dict(
00101             aString="Doodah",
00102             aList=["A", "B", 12, 32.5, [1, 2, 3]],
00103             aFloat = 0.5,
00104             anInt = 728,
00105             aDict=dict(
00106                 anotherString="<hello & 'hi' there!>",
00107                 aUnicodeValue='M\xe4ssig, Ma\xdf',
00108                 aTrueValue=True,
00109                 aFalseValue=False,
00110                 deeperDict=dict(a=17, b=32.5, c=[1, 2, "text"]),
00111             ),
00112             someData = plistlib.Data(b"<binary gunk>"),
00113             someMoreData = plistlib.Data(b"<lots of binary gunk>\0\1\2\3" * 10),
00114             nestedData = [plistlib.Data(b"<lots of binary gunk>\0\1\2\3" * 10)],
00115             aDate = datetime.datetime(2004, 10, 26, 10, 33, 33),
00116         )
00117         pl['\xc5benraa'] = "That was a unicode key."
00118         return pl

Here is the caller graph for this function:

Definition at line 92 of file test_plistlib.py.

00092 
00093     def tearDown(self):
00094         try:
00095             os.unlink(support.TESTFN)
00096         except:
00097             pass

Here is the caller graph for this function:

Definition at line 138 of file test_plistlib.py.

00138 
00139     def test_appleformatting(self):
00140         pl = plistlib.readPlistFromBytes(TESTDATA)
00141         data = plistlib.writePlistToBytes(pl)
00142         self.assertEqual(data, TESTDATA,
00143                          "generated data was not identical to Apple's output")

Here is the call graph for this function:

Definition at line 144 of file test_plistlib.py.

00144 
00145     def test_appleformattingfromliteral(self):
00146         pl = self._create()
00147         pl2 = plistlib.readPlistFromBytes(TESTDATA)
00148         self.assertEqual(dict(pl), dict(pl2),
00149                          "generated data was not identical to Apple's output")

Here is the call graph for this function:

Definition at line 130 of file test_plistlib.py.

00130 
00131     def test_bytes(self):
00132         pl = self._create()
00133         data = plistlib.writePlistToBytes(pl)
00134         pl2 = plistlib.readPlistFromBytes(data)
00135         self.assertEqual(dict(pl), dict(pl2))
00136         data2 = plistlib.writePlistToBytes(pl2)
00137         self.assertEqual(data, data2)

Here is the call graph for this function:

Definition at line 150 of file test_plistlib.py.

00150 
00151     def test_bytesio(self):
00152         from io import BytesIO
00153         b = BytesIO()
00154         pl = self._create()
00155         plistlib.writePlist(pl, b)
00156         pl2 = plistlib.readPlist(BytesIO(b.getvalue()))
00157         self.assertEqual(dict(pl), dict(pl2))

Here is the call graph for this function:

Definition at line 158 of file test_plistlib.py.

00158 
00159     def test_controlcharacters(self):
00160         for i in range(128):
00161             c = chr(i)
00162             testString = "string containing %s" % c
00163             if i >= 32 or c in "\r\n\t":
00164                 # \r, \n and \t are the only legal control chars in XML
00165                 plistlib.writePlistToBytes(testString)
00166             else:
00167                 self.assertRaises(ValueError,
00168                                   plistlib.writePlistToBytes,
00169                                   testString)

Here is the call graph for this function:

Definition at line 119 of file test_plistlib.py.

00119 
00120     def test_create(self):
00121         pl = self._create()
00122         self.assertEqual(pl["aString"], "Doodah")
00123         self.assertEqual(pl["aDict"]["aFalseValue"], False)

Here is the call graph for this function:

Definition at line 178 of file test_plistlib.py.

00178 
00179     def test_invalidarray(self):
00180         for i in ["<key>key inside an array</key>",
00181                   "<key>key inside an array2</key><real>3</real>",
00182                   "<true/><key>key inside an array3</key>"]:
00183             self.assertRaises(ValueError, plistlib.readPlistFromBytes,
00184                               ("<plist><array>%s</array></plist>"%i).encode())

Here is the call graph for this function:

Definition at line 185 of file test_plistlib.py.

00185 
00186     def test_invaliddict(self):
00187         for i in ["<key><true/>k</key><string>compound key</string>",
00188                   "<key>single key</key>",
00189                   "<string>missing key</string>",
00190                   "<key>k1</key><string>v1</string><real>5.3</real>"
00191                   "<key>k1</key><key>k2</key><string>double key</string>"]:
00192             self.assertRaises(ValueError, plistlib.readPlistFromBytes,
00193                               ("<plist><dict>%s</dict></plist>"%i).encode())
00194             self.assertRaises(ValueError, plistlib.readPlistFromBytes,
00195                               ("<plist><array><dict>%s</dict></array></plist>"%i).encode())

Here is the call graph for this function:

Definition at line 196 of file test_plistlib.py.

00196 
00197     def test_invalidinteger(self):
00198         self.assertRaises(ValueError, plistlib.readPlistFromBytes,
00199                           b"<plist><integer>not integer</integer></plist>")

Here is the call graph for this function:

Definition at line 200 of file test_plistlib.py.

00200 
00201     def test_invalidreal(self):
00202         self.assertRaises(ValueError, plistlib.readPlistFromBytes,
00203                           b"<plist><integer>not real</integer></plist>")
00204 

Here is the call graph for this function:

Definition at line 124 of file test_plistlib.py.

00124 
00125     def test_io(self):
00126         pl = self._create()
00127         plistlib.writePlist(pl, support.TESTFN)
00128         pl2 = plistlib.readPlist(support.TESTFN)
00129         self.assertEqual(dict(pl), dict(pl2))

Here is the call graph for this function:

Definition at line 170 of file test_plistlib.py.

00170 
00171     def test_nondictroot(self):
00172         test1 = "abc"
00173         test2 = [1, 2, 3, "abc"]
00174         result1 = plistlib.readPlistFromBytes(plistlib.writePlistToBytes(test1))
00175         result2 = plistlib.readPlistFromBytes(plistlib.writePlistToBytes(test2))
00176         self.assertEqual(test1, result1)
00177         self.assertEqual(test2, result2)

Here is the call graph for this function:


The documentation for this class was generated from the following file: