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""" 6import binhex 7import unittest 8from test import support 9 10 11class BinHexTestCase(unittest.TestCase): 12 13 def setUp(self): 14 self.fname1 = support.TESTFN + "1" 15 self.fname2 = support.TESTFN + "2" 16 self.fname3 = support.TESTFN + "very_long_filename__very_long_filename__very_long_filename__very_long_filename__" 17 18 def tearDown(self): 19 support.unlink(self.fname1) 20 support.unlink(self.fname2) 21 support.unlink(self.fname3) 22 23 DATA = b'Jack is my hero' 24 25 def test_binhex(self): 26 f = open(self.fname1, 'wb') 27 f.write(self.DATA) 28 f.close() 29 30 binhex.binhex(self.fname1, self.fname2) 31 32 binhex.hexbin(self.fname2, self.fname1) 33 34 f = open(self.fname1, 'rb') 35 finish = f.readline() 36 f.close() 37 38 self.assertEqual(self.DATA, finish) 39 40 def test_binhex_error_on_long_filename(self): 41 """ 42 The testcase fails if no exception is raised when a filename parameter provided to binhex.binhex() 43 is too long, or if the exception raised in binhex.binhex() is not an instance of binhex.Error. 44 """ 45 f3 = open(self.fname3, 'wb') 46 f3.close() 47 48 self.assertRaises(binhex.Error, binhex.binhex, self.fname3, self.fname2) 49 50def test_main(): 51 support.run_unittest(BinHexTestCase) 52 53 54if __name__ == "__main__": 55 test_main() 56