ยปCore Development>Code coverage>Lib/test/test_binhex.py

Python code coverage for Lib/test/test_binhex.py

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