annotate Lib/test/test_binhex.py @ 87690:66c1c9f32567 default tip

Add use_weakref option to functools.lru_cache The use_weakref option makes lru_cache create weak references to the function arguments when creating the cache key, which prevents them from staying in the memory forever even after all other references to them are gone. This is a proof of concept for http://bugs.python.org/issue19859
author Radomir Dopieralski <devel@sheep.art.pl>
date Tue, 03 Dec 2013 16:02:48 +0100
parents 5c2d15c6007e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
59522
fcfe324663a6 convert shebang lines: python -> python3
Benjamin Peterson <benjamin@python.org>
parents: 47201
diff changeset
1 #! /usr/bin/env python3
11392
a14d9614da00 This test really only tests the binhex module.
Guido van Rossum <guido@python.org>
parents: 7747
diff changeset
2 """Test script for the binhex C module
4969
0f1ae62dd3b8 test script for the binascii C module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff changeset
3
0f1ae62dd3b8 test script for the binascii C module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff changeset
4 Uses the mechanism of the python binhex module
17921
a1fcfdcb3479 Convert binhex regression test to PyUnit. We could use a better test
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
5 Based on an original test by Roger E. Masse.
4969
0f1ae62dd3b8 test script for the binascii C module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff changeset
6 """
0f1ae62dd3b8 test script for the binascii C module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff changeset
7 import binhex
17921
a1fcfdcb3479 Convert binhex regression test to PyUnit. We could use a better test
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
8 import os
a1fcfdcb3479 Convert binhex regression test to PyUnit. We could use a better test
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
9 import unittest
47201
9c930a32cebb #2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents: 41828
diff changeset
10 from test import support
4969
0f1ae62dd3b8 test script for the binascii C module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff changeset
11
17921
a1fcfdcb3479 Convert binhex regression test to PyUnit. We could use a better test
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
12
a1fcfdcb3479 Convert binhex regression test to PyUnit. We could use a better test
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
13 class BinHexTestCase(unittest.TestCase):
4969
0f1ae62dd3b8 test script for the binascii C module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff changeset
14
17921
a1fcfdcb3479 Convert binhex regression test to PyUnit. We could use a better test
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
15 def setUp(self):
47201
9c930a32cebb #2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents: 41828
diff changeset
16 self.fname1 = support.TESTFN + "1"
9c930a32cebb #2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents: 41828
diff changeset
17 self.fname2 = support.TESTFN + "2"
68633
5c2d15c6007e Close #11577: Improve binhex test coverage and fix ResourceWarning
Nick Coghlan <ncoghlan@gmail.com>
parents: 59522
diff changeset
18 self.fname3 = support.TESTFN + "very_long_filename__very_long_filename__very_long_filename__very_long_filename__"
4969
0f1ae62dd3b8 test script for the binascii C module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff changeset
19
17921
a1fcfdcb3479 Convert binhex regression test to PyUnit. We could use a better test
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
20 def tearDown(self):
47201
9c930a32cebb #2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents: 41828
diff changeset
21 support.unlink(self.fname1)
9c930a32cebb #2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents: 41828
diff changeset
22 support.unlink(self.fname2)
68633
5c2d15c6007e Close #11577: Improve binhex test coverage and fix ResourceWarning
Nick Coghlan <ncoghlan@gmail.com>
parents: 59522
diff changeset
23 support.unlink(self.fname3)
15305
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 13858
diff changeset
24
41828
a7be148f7c56 Make test_binhex pass. (Do we really want to support it still?)
Guido van Rossum <guido@python.org>
parents: 24710
diff changeset
25 DATA = b'Jack is my hero'
4969
0f1ae62dd3b8 test script for the binascii C module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff changeset
26
17921
a1fcfdcb3479 Convert binhex regression test to PyUnit. We could use a better test
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
27 def test_binhex(self):
41828
a7be148f7c56 Make test_binhex pass. (Do we really want to support it still?)
Guido van Rossum <guido@python.org>
parents: 24710
diff changeset
28 f = open(self.fname1, 'wb')
17921
a1fcfdcb3479 Convert binhex regression test to PyUnit. We could use a better test
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
29 f.write(self.DATA)
a1fcfdcb3479 Convert binhex regression test to PyUnit. We could use a better test
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
30 f.close()
a1fcfdcb3479 Convert binhex regression test to PyUnit. We could use a better test
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
31
a1fcfdcb3479 Convert binhex regression test to PyUnit. We could use a better test
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
32 binhex.binhex(self.fname1, self.fname2)
4969
0f1ae62dd3b8 test script for the binascii C module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff changeset
33
17921
a1fcfdcb3479 Convert binhex regression test to PyUnit. We could use a better test
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
34 binhex.hexbin(self.fname2, self.fname1)
4969
0f1ae62dd3b8 test script for the binascii C module.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff changeset
35
41828
a7be148f7c56 Make test_binhex pass. (Do we really want to support it still?)
Guido van Rossum <guido@python.org>
parents: 24710
diff changeset
36 f = open(self.fname1, 'rb')
17921
a1fcfdcb3479 Convert binhex regression test to PyUnit. We could use a better test
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
37 finish = f.readline()
a1fcfdcb3479 Convert binhex regression test to PyUnit. We could use a better test
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
38 f.close()
a1fcfdcb3479 Convert binhex regression test to PyUnit. We could use a better test
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
39
a1fcfdcb3479 Convert binhex regression test to PyUnit. We could use a better test
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
40 self.assertEqual(self.DATA, finish)
a1fcfdcb3479 Convert binhex regression test to PyUnit. We could use a better test
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
41
68633
5c2d15c6007e Close #11577: Improve binhex test coverage and fix ResourceWarning
Nick Coghlan <ncoghlan@gmail.com>
parents: 59522
diff changeset
42 def test_binhex_error_on_long_filename(self):
5c2d15c6007e Close #11577: Improve binhex test coverage and fix ResourceWarning
Nick Coghlan <ncoghlan@gmail.com>
parents: 59522
diff changeset
43 """
5c2d15c6007e Close #11577: Improve binhex test coverage and fix ResourceWarning
Nick Coghlan <ncoghlan@gmail.com>
parents: 59522
diff changeset
44 The testcase fails if no exception is raised when a filename parameter provided to binhex.binhex()
5c2d15c6007e Close #11577: Improve binhex test coverage and fix ResourceWarning
Nick Coghlan <ncoghlan@gmail.com>
parents: 59522
diff changeset
45 is too long, or if the exception raised in binhex.binhex() is not an instance of binhex.Error.
5c2d15c6007e Close #11577: Improve binhex test coverage and fix ResourceWarning
Nick Coghlan <ncoghlan@gmail.com>
parents: 59522
diff changeset
46 """
5c2d15c6007e Close #11577: Improve binhex test coverage and fix ResourceWarning
Nick Coghlan <ncoghlan@gmail.com>
parents: 59522
diff changeset
47 f3 = open(self.fname3, 'wb')
5c2d15c6007e Close #11577: Improve binhex test coverage and fix ResourceWarning
Nick Coghlan <ncoghlan@gmail.com>
parents: 59522
diff changeset
48 f3.close()
5c2d15c6007e Close #11577: Improve binhex test coverage and fix ResourceWarning
Nick Coghlan <ncoghlan@gmail.com>
parents: 59522
diff changeset
49
5c2d15c6007e Close #11577: Improve binhex test coverage and fix ResourceWarning
Nick Coghlan <ncoghlan@gmail.com>
parents: 59522
diff changeset
50 self.assertRaises(binhex.Error, binhex.binhex, self.fname3, self.fname2)
17921
a1fcfdcb3479 Convert binhex regression test to PyUnit. We could use a better test
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
51
20013
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 17921
diff changeset
52 def test_main():
47201
9c930a32cebb #2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents: 41828
diff changeset
53 support.run_unittest(BinHexTestCase)
20013
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 17921
diff changeset
54
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 17921
diff changeset
55
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 17921
diff changeset
56 if __name__ == "__main__":
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 17921
diff changeset
57 test_main()