Add weakref support to sockets and re pattern objects.

This commit is contained in:
Raymond Hettinger 2004-05-31 03:09:25 +00:00
parent cb87bc8e7e
commit 027bb633b6
7 changed files with 69 additions and 5 deletions

View file

@ -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))

View file

@ -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):