annotate Lib/test/test_userstring.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 55383912c225
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
12214
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
2 # UserString is a wrapper around the native builtin string type.
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
3 # UserString instances should behave similar to builtin string objects.
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 24684
diff changeset
4
42954
27f0289b6835 Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents: 42088
diff changeset
5 import string
81356
55383912c225 #16910: test_bytes, test_unicode, and test_userstring now work with unittest test discovery. Patch by Zachary Ware.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 72462
diff changeset
6 import unittest
47201
9c930a32cebb #2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents: 45471
diff changeset
7 from test import support, string_tests
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 24684
diff changeset
8
45424
a9e1fdaf413d Move UserString to collections.
Raymond Hettinger <python@rcn.com>
parents: 42954
diff changeset
9 from collections import UserString
12214
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
10
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 24684
diff changeset
11 class UserStringTest(
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 24684
diff changeset
12 string_tests.CommonTest,
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 24684
diff changeset
13 string_tests.MixinStrUnicodeUserStringTest,
81356
55383912c225 #16910: test_bytes, test_unicode, and test_userstring now work with unittest test discovery. Patch by Zachary Ware.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 72462
diff changeset
14 unittest.TestCase
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 24684
diff changeset
15 ):
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 24684
diff changeset
16
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 24684
diff changeset
17 type2test = UserString
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 24684
diff changeset
18
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 24684
diff changeset
19 # Overwrite the three testing methods, because UserString
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 24684
diff changeset
20 # can't cope with arguments propagated to UserString
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 24684
diff changeset
21 # (and we don't test with subclasses)
72462
0b2660384d4e Issue #13012: Allow 'keepends' to be passed as a keyword argument in str.splitlines, bytes.splitlines and bytearray.splitlines.
Mark Dickinson <mdickinson@enthought.com>
parents: 59522
diff changeset
22 def checkequal(self, result, object, methodname, *args, **kwargs):
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 24684
diff changeset
23 result = self.fixtype(result)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 24684
diff changeset
24 object = self.fixtype(object)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 24684
diff changeset
25 # we don't fix the arguments, because UserString can't cope with it
72462
0b2660384d4e Issue #13012: Allow 'keepends' to be passed as a keyword argument in str.splitlines, bytes.splitlines and bytearray.splitlines.
Mark Dickinson <mdickinson@enthought.com>
parents: 59522
diff changeset
26 realresult = getattr(object, methodname)(*args, **kwargs)
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 24684
diff changeset
27 self.assertEqual(
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 24684
diff changeset
28 result,
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 24684
diff changeset
29 realresult
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 24684
diff changeset
30 )
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 24684
diff changeset
31
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 24684
diff changeset
32 def checkraises(self, exc, object, methodname, *args):
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 24684
diff changeset
33 object = self.fixtype(object)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 24684
diff changeset
34 # we don't fix the arguments, because UserString can't cope with it
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 24684
diff changeset
35 self.assertRaises(
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 24684
diff changeset
36 exc,
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 24684
diff changeset
37 getattr(object, methodname),
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 24684
diff changeset
38 *args
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 24684
diff changeset
39 )
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 24684
diff changeset
40
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 24684
diff changeset
41 def checkcall(self, object, methodname, *args):
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 24684
diff changeset
42 object = self.fixtype(object)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 24684
diff changeset
43 # we don't fix the arguments, because UserString can't cope with it
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 24684
diff changeset
44 getattr(object, methodname)(*args)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 24684
diff changeset
45
34609
c60fde8b0106 Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents: 34606
diff changeset
46
12214
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
47 if __name__ == "__main__":
81356
55383912c225 #16910: test_bytes, test_unicode, and test_userstring now work with unittest test discovery. Patch by Zachary Ware.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 72462
diff changeset
48 unittest.main()