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