aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_binhex.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_binhex.py')
-rwxr-xr-xLib/test/test_binhex.py34
1 files changed, 21 insertions, 13 deletions
diff --git a/Lib/test/test_binhex.py b/Lib/test/test_binhex.py
index 2f89703b44a..a807bca6393 100755
--- a/Lib/test/test_binhex.py
+++ b/Lib/test/test_binhex.py
@@ -1,4 +1,4 @@
-#! /usr/bin/env python
+#! /usr/bin/env python3
"""Test script for the binhex C module
Uses the mechanism of the python binhex module
@@ -7,26 +7,25 @@
import binhex
import os
import unittest
-from test import test_support
+from test import support
class BinHexTestCase(unittest.TestCase):
def setUp(self):
- self.fname1 = test_support.TESTFN + "1"
- self.fname2 = test_support.TESTFN + "2"
+ self.fname1 = support.TESTFN + "1"
+ self.fname2 = support.TESTFN + "2"
+ self.fname3 = support.TESTFN + "very_long_filename__very_long_filename__very_long_filename__very_long_filename__"
def tearDown(self):
- try: os.unlink(self.fname1)
- except OSError: pass
+ support.unlink(self.fname1)
+ support.unlink(self.fname2)
+ support.unlink(self.fname3)
- try: os.unlink(self.fname2)
- except OSError: pass
-
- DATA = 'Jack is my hero'
+ DATA = b'Jack is my hero'
def test_binhex(self):
- f = open(self.fname1, 'w')
+ f = open(self.fname1, 'wb')
f.write(self.DATA)
f.close()
@@ -34,15 +33,24 @@ class BinHexTestCase(unittest.TestCase):
binhex.hexbin(self.fname2, self.fname1)
- f = open(self.fname1, 'r')
+ f = open(self.fname1, 'rb')
finish = f.readline()
f.close()
self.assertEqual(self.DATA, finish)
+ def test_binhex_error_on_long_filename(self):
+ """
+ The testcase fails if no exception is raised when a filename parameter provided to binhex.binhex()
+ is too long, or if the exception raised in binhex.binhex() is not an instance of binhex.Error.
+ """
+ f3 = open(self.fname3, 'wb')
+ f3.close()
+
+ self.assertRaises(binhex.Error, binhex.binhex, self.fname3, self.fname2)
def test_main():
- test_support.run_unittest(BinHexTestCase)
+ support.run_unittest(BinHexTestCase)
if __name__ == "__main__":