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