Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
test.test_pyexpat.ChardataBufferTest Class Reference

List of all members.

Public Member Functions

def test_1025_bytes
def test_1000_bytes
def test_wrong_size
def test_unchanged_size
def test_disabling_buffer
def make_document
def counting_handler
def small_buffer_test
def test_change_size_1
def test_change_size_2

Public Attributes

 n

Detailed Description

test setting of chardata buffer size

Definition at line 462 of file test_pyexpat.py.


Member Function Documentation

Definition at line 540 of file test_pyexpat.py.

00540 
00541     def counting_handler(self, text):
00542         self.n += 1

Here is the caller graph for this function:

Definition at line 537 of file test_pyexpat.py.

00537 
00538     def make_document(self, bytes):
00539         return ("<?xml version='1.0'?><tag>" + bytes * 'a' + '</tag>')

Definition at line 543 of file test_pyexpat.py.

00543 
00544     def small_buffer_test(self, buffer_len):
00545         xml = "<?xml version='1.0' encoding='iso8859'?><s>%s</s>" % ('a' * buffer_len)
00546         parser = expat.ParserCreate()
00547         parser.CharacterDataHandler = self.counting_handler
00548         parser.buffer_size = 1024
00549         parser.buffer_text = 1
00550 
00551         self.n = 0
00552         parser.Parse(xml)
00553         return self.n

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 470 of file test_pyexpat.py.

00470 
00471     def test_1000_bytes(self):
00472         self.assertEqual(self.small_buffer_test(1000), 1)

Here is the call graph for this function:

Definition at line 467 of file test_pyexpat.py.

00467 
00468     def test_1025_bytes(self):
00469         self.assertEqual(self.small_buffer_test(1025), 2)

Here is the call graph for this function:

Definition at line 554 of file test_pyexpat.py.

00554 
00555     def test_change_size_1(self):
00556         xml1 = "<?xml version='1.0' encoding='iso8859'?><a><s>%s" % ('a' * 1024)
00557         xml2 = "aaa</s><s>%s</s></a>" % ('a' * 1025)
00558         parser = expat.ParserCreate()
00559         parser.CharacterDataHandler = self.counting_handler
00560         parser.buffer_text = 1
00561         parser.buffer_size = 1024
00562         self.assertEqual(parser.buffer_size, 1024)
00563 
00564         self.n = 0
00565         parser.Parse(xml1, 0)
00566         parser.buffer_size *= 2
00567         self.assertEqual(parser.buffer_size, 2048)
00568         parser.Parse(xml2, 1)
00569         self.assertEqual(self.n, 2)

Here is the call graph for this function:

Definition at line 570 of file test_pyexpat.py.

00570 
00571     def test_change_size_2(self):
00572         xml1 = "<?xml version='1.0' encoding='iso8859'?><a>a<s>%s" % ('a' * 1023)
00573         xml2 = "aaa</s><s>%s</s></a>" % ('a' * 1025)
00574         parser = expat.ParserCreate()
00575         parser.CharacterDataHandler = self.counting_handler
00576         parser.buffer_text = 1
00577         parser.buffer_size = 2048
00578         self.assertEqual(parser.buffer_size, 2048)
00579 
00580         self.n=0
00581         parser.Parse(xml1, 0)
00582         parser.buffer_size = parser.buffer_size // 2
00583         self.assertEqual(parser.buffer_size, 1024)
00584         parser.Parse(xml2, 1)
00585         self.assertEqual(self.n, 4)

Here is the call graph for this function:

Definition at line 505 of file test_pyexpat.py.

00505 
00506     def test_disabling_buffer(self):
00507         xml1 = "<?xml version='1.0' encoding='iso8859'?><a>%s" % ('a' * 512)
00508         xml2 = ('b' * 1024)
00509         xml3 = "%s</a>" % ('c' * 1024)
00510         parser = expat.ParserCreate()
00511         parser.CharacterDataHandler = self.counting_handler
00512         parser.buffer_text = 1
00513         parser.buffer_size = 1024
00514         self.assertEqual(parser.buffer_size, 1024)
00515 
00516         # Parse one chunk of XML
00517         self.n = 0
00518         parser.Parse(xml1, 0)
00519         self.assertEqual(parser.buffer_size, 1024)
00520         self.assertEqual(self.n, 1)
00521 
00522         # Turn off buffering and parse the next chunk.
00523         parser.buffer_text = 0
00524         self.assertFalse(parser.buffer_text)
00525         self.assertEqual(parser.buffer_size, 1024)
00526         for i in range(10):
00527             parser.Parse(xml2, 0)
00528         self.assertEqual(self.n, 11)
00529 
00530         parser.buffer_text = 1
00531         self.assertTrue(parser.buffer_text)
00532         self.assertEqual(parser.buffer_size, 1024)
00533         parser.Parse(xml3, 1)
00534         self.assertEqual(self.n, 12)
00535 
00536 

Here is the call graph for this function:

Definition at line 482 of file test_pyexpat.py.

00482 
00483     def test_unchanged_size(self):
00484         xml1 = ("<?xml version='1.0' encoding='iso8859'?><s>%s" % ('a' * 512))
00485         xml2 = 'a'*512 + '</s>'
00486         parser = expat.ParserCreate()
00487         parser.CharacterDataHandler = self.counting_handler
00488         parser.buffer_size = 512
00489         parser.buffer_text = 1
00490 
00491         # Feed 512 bytes of character data: the handler should be called
00492         # once.
00493         self.n = 0
00494         parser.Parse(xml1)
00495         self.assertEqual(self.n, 1)
00496 
00497         # Reassign to buffer_size, but assign the same size.
00498         parser.buffer_size = parser.buffer_size
00499         self.assertEqual(self.n, 1)
00500 
00501         # Try parsing rest of the document
00502         parser.Parse(xml2)
00503         self.assertEqual(self.n, 2)
00504 

Here is the call graph for this function:

Definition at line 473 of file test_pyexpat.py.

00473 
00474     def test_wrong_size(self):
00475         parser = expat.ParserCreate()
00476         parser.buffer_text = 1
00477         def f(size):
00478             parser.buffer_size = size
00479 
00480         self.assertRaises(ValueError, f, -1)
00481         self.assertRaises(ValueError, f, 0)

Here is the call graph for this function:


Member Data Documentation

Definition at line 492 of file test_pyexpat.py.


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