Back to index

python3.2  3.2.2
Public Member Functions
test.test_codecs.BomTest Class Reference

List of all members.

Public Member Functions

def test_seek0

Detailed Description

Definition at line 1630 of file test_codecs.py.


Member Function Documentation

Definition at line 1631 of file test_codecs.py.

01631 
01632     def test_seek0(self):
01633         data = "1234567890"
01634         tests = ("utf-16",
01635                  "utf-16-le",
01636                  "utf-16-be",
01637                  "utf-32",
01638                  "utf-32-le",
01639                  "utf-32-be")
01640         self.addCleanup(support.unlink, support.TESTFN)
01641         for encoding in tests:
01642             # Check if the BOM is written only once
01643             with codecs.open(support.TESTFN, 'w+', encoding=encoding) as f:
01644                 f.write(data)
01645                 f.write(data)
01646                 f.seek(0)
01647                 self.assertEqual(f.read(), data * 2)
01648                 f.seek(0)
01649                 self.assertEqual(f.read(), data * 2)
01650 
01651             # Check that the BOM is written after a seek(0)
01652             with codecs.open(support.TESTFN, 'w+', encoding=encoding) as f:
01653                 f.write(data[0])
01654                 self.assertNotEqual(f.tell(), 0)
01655                 f.seek(0)
01656                 f.write(data)
01657                 f.seek(0)
01658                 self.assertEqual(f.read(), data)
01659 
01660             # (StreamWriter) Check that the BOM is written after a seek(0)
01661             with codecs.open(support.TESTFN, 'w+', encoding=encoding) as f:
01662                 f.writer.write(data[0])
01663                 self.assertNotEqual(f.writer.tell(), 0)
01664                 f.writer.seek(0)
01665                 f.writer.write(data)
01666                 f.seek(0)
01667                 self.assertEqual(f.read(), data)
01668 
01669             # Check that the BOM is not written after a seek() at a position
01670             # different than the start
01671             with codecs.open(support.TESTFN, 'w+', encoding=encoding) as f:
01672                 f.write(data)
01673                 f.seek(f.tell())
01674                 f.write(data)
01675                 f.seek(0)
01676                 self.assertEqual(f.read(), data * 2)
01677 
01678             # (StreamWriter) Check that the BOM is not written after a seek()
01679             # at a position different than the start
01680             with codecs.open(support.TESTFN, 'w+', encoding=encoding) as f:
01681                 f.writer.write(data)
01682                 f.writer.seek(f.writer.tell())
01683                 f.writer.write(data)
01684                 f.seek(0)
01685                 self.assertEqual(f.read(), data * 2)
01686 

Here is the call graph for this function:


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