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 |
Roger E. Masse | 2a1c834 | 1997-01-16 16:44:09 +0000 | [diff] [blame] | 9 | import tempfile |
Fred Drake | 275dfda | 2001-05-22 21:01:14 +0000 | [diff] [blame] | 10 | import test_support |
11 | import unittest | ||||
Roger E. Masse | 2a1c834 | 1997-01-16 16:44:09 +0000 | [diff] [blame] | 12 | |
Roger E. Masse | 2a1c834 | 1997-01-16 16:44:09 +0000 | [diff] [blame] | 13 | |
Fred Drake | 275dfda | 2001-05-22 21:01:14 +0000 | [diff] [blame] | 14 | class BinHexTestCase(unittest.TestCase): |
Roger E. Masse | 2a1c834 | 1997-01-16 16:44:09 +0000 | [diff] [blame] | 15 | |
Fred Drake | 275dfda | 2001-05-22 21:01:14 +0000 | [diff] [blame] | 16 | def setUp(self): |
17 | self.fname1 = tempfile.mktemp() | ||||
18 | self.fname2 = tempfile.mktemp() | ||||
Fred Drake | 004d5e6 | 2000-10-23 17:22:08 +0000 | [diff] [blame] | 19 | |
Fred Drake | 275dfda | 2001-05-22 21:01:14 +0000 | [diff] [blame] | 20 | def tearDown(self): |
21 | try: os.unlink(self.fname1) | ||||
22 | except OSError: pass | ||||
Roger E. Masse | 2a1c834 | 1997-01-16 16:44:09 +0000 | [diff] [blame] | 23 | |
Fred Drake | 275dfda | 2001-05-22 21:01:14 +0000 | [diff] [blame] | 24 | try: os.unlink(self.fname2) |
25 | except OSError: pass | ||||
Roger E. Masse | 2a1c834 | 1997-01-16 16:44:09 +0000 | [diff] [blame] | 26 | |
Fred Drake | 275dfda | 2001-05-22 21:01:14 +0000 | [diff] [blame] | 27 | DATA = 'Jack is my hero' |
Roger E. Masse | 2a1c834 | 1997-01-16 16:44:09 +0000 | [diff] [blame] | 28 | |
Fred Drake | 275dfda | 2001-05-22 21:01:14 +0000 | [diff] [blame] | 29 | def test_binhex(self): |
30 | f = open(self.fname1, 'w') | ||||
31 | f.write(self.DATA) | ||||
32 | f.close() | ||||
Roger E. Masse | 2a1c834 | 1997-01-16 16:44:09 +0000 | [diff] [blame] | 33 | |
Fred Drake | 275dfda | 2001-05-22 21:01:14 +0000 | [diff] [blame] | 34 | binhex.binhex(self.fname1, self.fname2) |
35 | |||||
36 | binhex.hexbin(self.fname2, self.fname1) | ||||
37 | |||||
38 | f = open(self.fname1, 'r') | ||||
39 | finish = f.readline() | ||||
40 | f.close() | ||||
41 | |||||
42 | self.assertEqual(self.DATA, finish) | ||||
43 | |||||
44 | |||||
Fred Drake | 2e2be37 | 2001-09-20 21:33:42 +0000 | [diff] [blame^] | 45 | def test_main(): |
46 | test_support.run_unittest(BinHexTestCase) | ||||
47 | |||||
48 | |||||
49 | if __name__ == "__main__": | ||||
50 | test_main() |