test_binhex.py 1004 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. """Test script for the binhex C module
  2. Uses the mechanism of the python binhex module
  3. Based on an original test by Roger E. Masse.
  4. """
  5. import binhex
  6. import os
  7. import unittest
  8. from test import test_support
  9. class BinHexTestCase(unittest.TestCase):
  10. def setUp(self):
  11. self.fname1 = test_support.TESTFN + "1"
  12. self.fname2 = test_support.TESTFN + "2"
  13. def tearDown(self):
  14. try: os.unlink(self.fname1)
  15. except OSError: pass
  16. try: os.unlink(self.fname2)
  17. except OSError: pass
  18. DATA = 'Jack is my hero'
  19. def test_binhex(self):
  20. f = open(self.fname1, 'w')
  21. f.write(self.DATA)
  22. f.close()
  23. binhex.binhex(self.fname1, self.fname2)
  24. binhex.hexbin(self.fname2, self.fname1)
  25. f = open(self.fname1, 'r')
  26. finish = f.readline()
  27. f.close()
  28. self.assertEqual(self.DATA, finish)
  29. def test_main():
  30. test_support.run_unittest(BinHexTestCase)
  31. if __name__ == "__main__":
  32. test_main()