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