blob: 86ca37ce1b99a7a4be13f121700b714f23e99912 [file] [log] [blame]
Guido van Rossum7b8f1ab1999-10-19 17:48:54 +00001"""Test script for the binhex C module
Roger E. Masse2a1c8341997-01-16 16:44:09 +00002
3 Uses the mechanism of the python binhex module
Fred Drake275dfda2001-05-22 21:01:14 +00004 Based on an original test by Roger E. Masse.
Roger E. Masse2a1c8341997-01-16 16:44:09 +00005"""
Fred Drake275dfda2001-05-22 21:01:14 +00006import unittest
Benjamin Petersonee8712c2008-05-20 21:35:26 +00007from test import support
Roger E. Masse2a1c8341997-01-16 16:44:09 +00008
Victor Stinnerbeea26b2020-01-22 20:44:22 +01009with support.check_warnings(('', DeprecationWarning)):
10 import binhex
11
Roger E. Masse2a1c8341997-01-16 16:44:09 +000012
Fred Drake275dfda2001-05-22 21:01:14 +000013class BinHexTestCase(unittest.TestCase):
Roger E. Masse2a1c8341997-01-16 16:44:09 +000014
Fred Drake275dfda2001-05-22 21:01:14 +000015 def setUp(self):
Benjamin Petersonee8712c2008-05-20 21:35:26 +000016 self.fname1 = support.TESTFN + "1"
17 self.fname2 = support.TESTFN + "2"
Nick Coghlanb3c728f2011-03-16 21:26:40 -040018 self.fname3 = support.TESTFN + "very_long_filename__very_long_filename__very_long_filename__very_long_filename__"
Fred Drake004d5e62000-10-23 17:22:08 +000019
Fred Drake275dfda2001-05-22 21:01:14 +000020 def tearDown(self):
Benjamin Petersonee8712c2008-05-20 21:35:26 +000021 support.unlink(self.fname1)
22 support.unlink(self.fname2)
Nick Coghlanb3c728f2011-03-16 21:26:40 -040023 support.unlink(self.fname3)
Roger E. Masse2a1c8341997-01-16 16:44:09 +000024
Guido van Rossumdcee3c02007-05-22 22:25:42 +000025 DATA = b'Jack is my hero'
Roger E. Masse2a1c8341997-01-16 16:44:09 +000026
Fred Drake275dfda2001-05-22 21:01:14 +000027 def test_binhex(self):
Serhiy Storchaka5b10b982019-03-05 10:06:26 +020028 with open(self.fname1, 'wb') as f:
29 f.write(self.DATA)
Roger E. Masse2a1c8341997-01-16 16:44:09 +000030
Fred Drake275dfda2001-05-22 21:01:14 +000031 binhex.binhex(self.fname1, self.fname2)
32
33 binhex.hexbin(self.fname2, self.fname1)
34
Serhiy Storchaka5b10b982019-03-05 10:06:26 +020035 with open(self.fname1, 'rb') as f:
36 finish = f.readline()
Fred Drake275dfda2001-05-22 21:01:14 +000037
38 self.assertEqual(self.DATA, finish)
39
Nick Coghlanb3c728f2011-03-16 21:26:40 -040040 def test_binhex_error_on_long_filename(self):
41 """
42 The testcase fails if no exception is raised when a filename parameter provided to binhex.binhex()
43 is too long, or if the exception raised in binhex.binhex() is not an instance of binhex.Error.
44 """
45 f3 = open(self.fname3, 'wb')
46 f3.close()
47
48 self.assertRaises(binhex.Error, binhex.binhex, self.fname3, self.fname2)
Fred Drake275dfda2001-05-22 21:01:14 +000049
Fred Drake2e2be372001-09-20 21:33:42 +000050def test_main():
Benjamin Petersonee8712c2008-05-20 21:35:26 +000051 support.run_unittest(BinHexTestCase)
Fred Drake2e2be372001-09-20 21:33:42 +000052
53
54if __name__ == "__main__":
55 test_main()