Roger E. Masse | 2a1c834 | 1997-01-16 16:44:09 +0000 | [diff] [blame] | 1 | #! /usr/bin/env python |
Guido van Rossum | 7b8f1ab | 1999-10-19 17:48:54 +0000 | [diff] [blame] | 2 | """Test script for the binhex C module |
Roger E. Masse | 2a1c834 | 1997-01-16 16:44:09 +0000 | [diff] [blame] | 3 | |
4 | Uses the mechanism of the python binhex module | ||||
Fred Drake | 275dfda | 2001-05-22 21:01:14 +0000 | [diff] [blame] | 5 | Based on an original test by Roger E. Masse. |
Roger E. Masse | 2a1c834 | 1997-01-16 16:44:09 +0000 | [diff] [blame] | 6 | """ |
7 | import binhex | ||||
Fred Drake | 275dfda | 2001-05-22 21:01:14 +0000 | [diff] [blame] | 8 | import os |
Fred Drake | 275dfda | 2001-05-22 21:01:14 +0000 | [diff] [blame] | 9 | import unittest |
Barry Warsaw | 04f357c | 2002-07-23 19:04:11 +0000 | [diff] [blame] | 10 | from test import test_support |
Roger E. Masse | 2a1c834 | 1997-01-16 16:44:09 +0000 | [diff] [blame] | 11 | |
Roger E. Masse | 2a1c834 | 1997-01-16 16:44:09 +0000 | [diff] [blame] | 12 | |
Fred Drake | 275dfda | 2001-05-22 21:01:14 +0000 | [diff] [blame] | 13 | class BinHexTestCase(unittest.TestCase): |
Roger E. Masse | 2a1c834 | 1997-01-16 16:44:09 +0000 | [diff] [blame] | 14 | |
Fred Drake | 275dfda | 2001-05-22 21:01:14 +0000 | [diff] [blame] | 15 | def setUp(self): |
Guido van Rossum | 3b0a329 | 2002-08-09 16:38:32 +0000 | [diff] [blame^] | 16 | self.fname1 = test_support.TESTFN + "1" |
17 | self.fname2 = test_support.TESTFN + "2" | ||||
Fred Drake | 004d5e6 | 2000-10-23 17:22:08 +0000 | [diff] [blame] | 18 | |
Fred Drake | 275dfda | 2001-05-22 21:01:14 +0000 | [diff] [blame] | 19 | def tearDown(self): |
20 | try: os.unlink(self.fname1) | ||||
21 | except OSError: pass | ||||
Roger E. Masse | 2a1c834 | 1997-01-16 16:44:09 +0000 | [diff] [blame] | 22 | |
Fred Drake | 275dfda | 2001-05-22 21:01:14 +0000 | [diff] [blame] | 23 | try: os.unlink(self.fname2) |
24 | except OSError: pass | ||||
Roger E. Masse | 2a1c834 | 1997-01-16 16:44:09 +0000 | [diff] [blame] | 25 | |
Fred Drake | 275dfda | 2001-05-22 21:01:14 +0000 | [diff] [blame] | 26 | DATA = 'Jack is my hero' |
Roger E. Masse | 2a1c834 | 1997-01-16 16:44:09 +0000 | [diff] [blame] | 27 | |
Fred Drake | 275dfda | 2001-05-22 21:01:14 +0000 | [diff] [blame] | 28 | def test_binhex(self): |
29 | f = open(self.fname1, 'w') | ||||
30 | f.write(self.DATA) | ||||
31 | f.close() | ||||
Roger E. Masse | 2a1c834 | 1997-01-16 16:44:09 +0000 | [diff] [blame] | 32 | |
Fred Drake | 275dfda | 2001-05-22 21:01:14 +0000 | [diff] [blame] | 33 | binhex.binhex(self.fname1, self.fname2) |
34 | |||||
35 | binhex.hexbin(self.fname2, self.fname1) | ||||
36 | |||||
37 | f = open(self.fname1, 'r') | ||||
38 | finish = f.readline() | ||||
39 | f.close() | ||||
40 | |||||
41 | self.assertEqual(self.DATA, finish) | ||||
42 | |||||
43 | |||||
Fred Drake | 2e2be37 | 2001-09-20 21:33:42 +0000 | [diff] [blame] | 44 | def test_main(): |
45 | test_support.run_unittest(BinHexTestCase) | ||||
46 | |||||
47 | |||||
48 | if __name__ == "__main__": | ||||
49 | test_main() |