• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""Test script for the binhex C module
2
3   Uses the mechanism of the python binhex module
4   Based on an original test by Roger E. Masse.
5"""
6import binhex
7import unittest
8from test import support
9
10
11class BinHexTestCase(unittest.TestCase):
12
13    def setUp(self):
14        self.fname1 = support.TESTFN + "1"
15        self.fname2 = support.TESTFN + "2"
16        self.fname3 = support.TESTFN + "very_long_filename__very_long_filename__very_long_filename__very_long_filename__"
17
18    def tearDown(self):
19        support.unlink(self.fname1)
20        support.unlink(self.fname2)
21        support.unlink(self.fname3)
22
23    DATA = b'Jack is my hero'
24
25    def test_binhex(self):
26        with open(self.fname1, 'wb') as f:
27            f.write(self.DATA)
28
29        binhex.binhex(self.fname1, self.fname2)
30
31        binhex.hexbin(self.fname2, self.fname1)
32
33        with open(self.fname1, 'rb') as f:
34            finish = f.readline()
35
36        self.assertEqual(self.DATA, finish)
37
38    def test_binhex_error_on_long_filename(self):
39        """
40        The testcase fails if no exception is raised when a filename parameter provided to binhex.binhex()
41        is too long, or if the exception raised in binhex.binhex() is not an instance of binhex.Error.
42        """
43        f3 = open(self.fname3, 'wb')
44        f3.close()
45
46        self.assertRaises(binhex.Error, binhex.binhex, self.fname3, self.fname2)
47
48def test_main():
49    support.run_unittest(BinHexTestCase)
50
51
52if __name__ == "__main__":
53    test_main()
54