blob: 2580fb21e28372ed54b5699b15f66d50e19d8897 [file] [log] [blame]
Roger E. Masse2a1c8341997-01-16 16:44:09 +00001#! /usr/bin/env python
Guido van Rossum7b8f1ab1999-10-19 17:48:54 +00002"""Test script for the binhex C module
Roger E. Masse2a1c8341997-01-16 16:44:09 +00003
4 Uses the mechanism of the python binhex module
Fred Drake275dfda2001-05-22 21:01:14 +00005 Based on an original test by Roger E. Masse.
Roger E. Masse2a1c8341997-01-16 16:44:09 +00006"""
7import binhex
Fred Drake275dfda2001-05-22 21:01:14 +00008import os
Roger E. Masse2a1c8341997-01-16 16:44:09 +00009import tempfile
Fred Drake275dfda2001-05-22 21:01:14 +000010import test_support
11import unittest
Roger E. Masse2a1c8341997-01-16 16:44:09 +000012
Roger E. Masse2a1c8341997-01-16 16:44:09 +000013
Fred Drake275dfda2001-05-22 21:01:14 +000014class BinHexTestCase(unittest.TestCase):
Roger E. Masse2a1c8341997-01-16 16:44:09 +000015
Fred Drake275dfda2001-05-22 21:01:14 +000016 def setUp(self):
17 self.fname1 = tempfile.mktemp()
18 self.fname2 = tempfile.mktemp()
Fred Drake004d5e62000-10-23 17:22:08 +000019
Fred Drake275dfda2001-05-22 21:01:14 +000020 def tearDown(self):
21 try: os.unlink(self.fname1)
22 except OSError: pass
Roger E. Masse2a1c8341997-01-16 16:44:09 +000023
Fred Drake275dfda2001-05-22 21:01:14 +000024 try: os.unlink(self.fname2)
25 except OSError: pass
Roger E. Masse2a1c8341997-01-16 16:44:09 +000026
Fred Drake275dfda2001-05-22 21:01:14 +000027 DATA = 'Jack is my hero'
Roger E. Masse2a1c8341997-01-16 16:44:09 +000028
Fred Drake275dfda2001-05-22 21:01:14 +000029 def test_binhex(self):
30 f = open(self.fname1, 'w')
31 f.write(self.DATA)
32 f.close()
Roger E. Masse2a1c8341997-01-16 16:44:09 +000033
Fred Drake275dfda2001-05-22 21:01:14 +000034 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 Drake2e2be372001-09-20 21:33:42 +000045def test_main():
46 test_support.run_unittest(BinHexTestCase)
47
48
49if __name__ == "__main__":
50 test_main()