home *** CD-ROM | disk | FTP | other *** search
/ Komputer for Alle 2004 #2 / K-CD-2-2004.ISO / OpenOffice Sv / f_0397 / python-core-2.2.2 / lib / test / test_binhex.py < prev    next >
Encoding:
Python Source  |  2003-07-18  |  1017 b   |  51 lines

  1. #! /usr/bin/env python
  2. """Test script for the binhex C module
  3.  
  4.    Uses the mechanism of the python binhex module
  5.    Based on an original test by Roger E. Masse.
  6. """
  7. import binhex
  8. import os
  9. import tempfile
  10. import test_support
  11. import unittest
  12.  
  13.  
  14. class BinHexTestCase(unittest.TestCase):
  15.  
  16.     def setUp(self):
  17.         self.fname1 = tempfile.mktemp()
  18.         self.fname2 = tempfile.mktemp()
  19.  
  20.     def tearDown(self):
  21.         try: os.unlink(self.fname1)
  22.         except OSError: pass
  23.  
  24.         try: os.unlink(self.fname2)
  25.         except OSError: pass
  26.  
  27.     DATA = 'Jack is my hero'
  28.  
  29.     def test_binhex(self):
  30.         f = open(self.fname1, 'w')
  31.         f.write(self.DATA)
  32.         f.close()
  33.  
  34.         binhex.binhex(self.fname1, self.fname2)
  35.  
  36.         binhex.hexbin(self.fname2, self.fname1)
  37.  
  38.         f = open(self.fname1, 'r')
  39.         finish = f.readline()
  40.         f.close()
  41.  
  42.         self.assertEqual(self.DATA, finish)
  43.  
  44.  
  45. def test_main():
  46.     test_support.run_unittest(BinHexTestCase)
  47.  
  48.  
  49. if __name__ == "__main__":
  50.     test_main()
  51.