Back to index

enigmail  1.4.3
unit-LineEndings.py
Go to the documentation of this file.
00001 import unittest
00002 
00003 from StringIO import StringIO
00004 import os
00005 import sys
00006 import os.path
00007 sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
00008 
00009 from Preprocessor import Preprocessor
00010 
00011 class TestLineEndings(unittest.TestCase):
00012   """
00013   Unit tests for the Context class
00014   """
00015 
00016   def setUp(self):
00017     self.pp = Preprocessor()
00018     self.pp.out = StringIO()
00019     self.tempnam = os.tempnam('.')
00020 
00021   def tearDown(self):
00022     os.remove(self.tempnam)
00023 
00024   def createFile(self, lineendings):
00025     f = open(self.tempnam, 'wb')
00026     for line, ending in zip(['a', '#literal b', 'c'], lineendings):
00027       f.write(line+ending)
00028     f.close()
00029 
00030   def testMac(self):
00031     self.createFile(['\x0D']*3)
00032     self.pp.do_include(self.tempnam)
00033     self.assertEquals(self.pp.out.getvalue(), 'a\nb\nc\n')
00034 
00035   def testUnix(self):
00036     self.createFile(['\x0A']*3)
00037     self.pp.do_include(self.tempnam)
00038     self.assertEquals(self.pp.out.getvalue(), 'a\nb\nc\n')
00039 
00040   def testWindows(self):
00041     self.createFile(['\x0D\x0A']*3)
00042     self.pp.do_include(self.tempnam)
00043     self.assertEquals(self.pp.out.getvalue(), 'a\nb\nc\n')
00044 
00045 if __name__ == '__main__':
00046   unittest.main()