Guido van Rossum | 228b8e8 | 1997-04-02 06:13:34 +0000 | [diff] [blame] | 1 | #! /usr/bin/env python |
| 2 | """Test script for the binascii C module |
| 3 | |
| 4 | Uses the mechanism of the python binhex module |
| 5 | Roger E. Masse |
| 6 | """ |
| 7 | import binhex |
| 8 | import tempfile |
| 9 | from test_support import verbose |
| 10 | |
| 11 | def test(): |
| 12 | |
| 13 | try: |
| 14 | fname1 = tempfile.mktemp() |
| 15 | fname2 = tempfile.mktemp() |
| 16 | f = open(fname1, 'w') |
| 17 | except: |
| 18 | raise ImportError, "Cannot test binascii without a temp file" |
| 19 | |
| 20 | start = 'Jack is my hero' |
| 21 | f.write(start) |
| 22 | f.close() |
| 23 | |
| 24 | binhex.binhex(fname1, fname2) |
| 25 | if verbose: |
| 26 | print 'binhex' |
| 27 | |
| 28 | binhex.hexbin(fname2, fname1) |
| 29 | if verbose: |
| 30 | print 'hexbin' |
| 31 | |
| 32 | f = open(fname1, 'r') |
| 33 | finish = f.readline() |
| 34 | |
| 35 | if start <> finish: |
| 36 | print 'Error: binhex <> hexbin' |
| 37 | elif verbose: |
| 38 | print 'binhex == hexbin' |
| 39 | |
| 40 | try: |
| 41 | import os |
| 42 | os.unlink(fname1) |
| 43 | os.unlink(fname2) |
| 44 | except: |
| 45 | pass |
| 46 | test() |