10a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#! /usr/bin/env python 20a8c90248264a8b26970b4473770bcc3df8515fJosh Gao"""Test script for the binhex C module 30a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 40a8c90248264a8b26970b4473770bcc3df8515fJosh Gao Uses the mechanism of the python binhex module 50a8c90248264a8b26970b4473770bcc3df8515fJosh Gao Based on an original test by Roger E. Masse. 60a8c90248264a8b26970b4473770bcc3df8515fJosh Gao""" 70a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoimport binhex 80a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoimport os 90a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoimport unittest 100a8c90248264a8b26970b4473770bcc3df8515fJosh Gaofrom test import test_support 110a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 120a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 130a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoclass BinHexTestCase(unittest.TestCase): 140a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 150a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def setUp(self): 160a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.fname1 = test_support.TESTFN + "1" 170a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.fname2 = test_support.TESTFN + "2" 180a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 190a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def tearDown(self): 200a8c90248264a8b26970b4473770bcc3df8515fJosh Gao try: os.unlink(self.fname1) 210a8c90248264a8b26970b4473770bcc3df8515fJosh Gao except OSError: pass 220a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 230a8c90248264a8b26970b4473770bcc3df8515fJosh Gao try: os.unlink(self.fname2) 240a8c90248264a8b26970b4473770bcc3df8515fJosh Gao except OSError: pass 250a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 260a8c90248264a8b26970b4473770bcc3df8515fJosh Gao DATA = 'Jack is my hero' 270a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 280a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_binhex(self): 290a8c90248264a8b26970b4473770bcc3df8515fJosh Gao f = open(self.fname1, 'w') 300a8c90248264a8b26970b4473770bcc3df8515fJosh Gao f.write(self.DATA) 310a8c90248264a8b26970b4473770bcc3df8515fJosh Gao f.close() 320a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 330a8c90248264a8b26970b4473770bcc3df8515fJosh Gao binhex.binhex(self.fname1, self.fname2) 340a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 350a8c90248264a8b26970b4473770bcc3df8515fJosh Gao binhex.hexbin(self.fname2, self.fname1) 360a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 370a8c90248264a8b26970b4473770bcc3df8515fJosh Gao f = open(self.fname1, 'r') 380a8c90248264a8b26970b4473770bcc3df8515fJosh Gao finish = f.readline() 390a8c90248264a8b26970b4473770bcc3df8515fJosh Gao f.close() 400a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 410a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(self.DATA, finish) 420a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 430a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 440a8c90248264a8b26970b4473770bcc3df8515fJosh Gaodef test_main(): 450a8c90248264a8b26970b4473770bcc3df8515fJosh Gao test_support.run_unittest(BinHexTestCase) 460a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 470a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 480a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoif __name__ == "__main__": 490a8c90248264a8b26970b4473770bcc3df8515fJosh Gao test_main() 50