~ubuntu-branches/ubuntu/trusty/python3.4/trusty-proposed

« back to all changes in this revision

Viewing changes to Lib/test/test_binhex.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-11-25 09:44:27 UTC
  • Revision ID: package-import@ubuntu.com-20131125094427-lzxj8ap5w01lmo7f
Tags: upstream-3.4~b1
ImportĀ upstreamĀ versionĀ 3.4~b1

Show diffs side-by-side

added added

removed removed

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