mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Add weakref support to sockets and re pattern objects.
This commit is contained in:
parent
cb87bc8e7e
commit
027bb633b6
7 changed files with 69 additions and 5 deletions
|
@ -5,6 +5,7 @@ from test.test_support import verbose, run_unittest
|
|||
import re
|
||||
from sre import Scanner
|
||||
import sys, os, traceback
|
||||
from weakref import proxy
|
||||
|
||||
# Misc tests from Tim Peters' re.doc
|
||||
|
||||
|
@ -15,6 +16,13 @@ import sys, os, traceback
|
|||
import unittest
|
||||
|
||||
class ReTests(unittest.TestCase):
|
||||
|
||||
def test_weakref(self):
|
||||
s = 'QabbbcR'
|
||||
x = re.compile('ab+c')
|
||||
y = proxy(x)
|
||||
self.assertEqual(x.findall('QabbbcR'), y.findall('QabbbcR'))
|
||||
|
||||
def test_search_star_plus(self):
|
||||
self.assertEqual(re.search('x*', 'axx').span(0), (0, 0))
|
||||
self.assertEqual(re.search('x*', 'axx').span(), (0, 0))
|
||||
|
|
|
@ -9,6 +9,7 @@ import time
|
|||
import thread, threading
|
||||
import Queue
|
||||
import sys
|
||||
from weakref import proxy
|
||||
|
||||
PORT = 50007
|
||||
HOST = 'localhost'
|
||||
|
@ -191,6 +192,19 @@ class SocketConnectedTest(ThreadedTCPSocketTest):
|
|||
|
||||
class GeneralModuleTests(unittest.TestCase):
|
||||
|
||||
def test_weakref(self):
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
p = proxy(s)
|
||||
self.assertEqual(p.fileno(), s.fileno())
|
||||
s.close()
|
||||
s = None
|
||||
try:
|
||||
p.fileno()
|
||||
except ReferenceError:
|
||||
pass
|
||||
else:
|
||||
self.fail('Socket proxy still exists')
|
||||
|
||||
def testSocketError(self):
|
||||
# Testing socket module exceptions
|
||||
def raise_error(*args, **kwargs):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue