diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/curses/__init__.py | 4 | ||||
-rw-r--r-- | Lib/test/test_curses.py | 7 | ||||
-rw-r--r-- | Lib/test/test_ftplib.py | 36 | ||||
-rw-r--r-- | Lib/test/test_itertools.py | 2 | ||||
-rwxr-xr-x | Lib/token.py | 1 |
5 files changed, 37 insertions, 13 deletions
diff --git a/Lib/curses/__init__.py b/Lib/curses/__init__.py index c3f2f25..bd7d5f6 100644 --- a/Lib/curses/__init__.py +++ b/Lib/curses/__init__.py @@ -15,6 +15,7 @@ __revision__ = "$Id$" from _curses import * from curses.wrapper import wrapper import os as _os +import sys as _sys # Some constants, most notably the ACS_* ones, are only added to the C # _curses module's dictionary after initscr() is called. (Some @@ -28,7 +29,8 @@ def initscr(): import _curses, curses # we call setupterm() here because it raises an error # instead of calling exit() in error cases. - setupterm(term=_os.environ.get("TERM", "unknown")) + setupterm(term=_os.environ.get("TERM", "unknown"), + fd=_sys.__stdout__.fileno()) stdscr = _curses.initscr() for key, value in _curses.__dict__.items(): if key[0:4] == 'ACS_' or key in ('LINES', 'COLS'): diff --git a/Lib/test/test_curses.py b/Lib/test/test_curses.py index 64d6536..d50d81d 100644 --- a/Lib/test/test_curses.py +++ b/Lib/test/test_curses.py @@ -269,13 +269,12 @@ if __name__ == '__main__': curses.wrapper(main) unit_tests() else: + # testing setupterm() inside initscr/endwin + # causes terminal breakage + curses.setupterm(fd=sys.__stdout__.fileno()) try: - # testing setupterm() inside initscr/endwin - # causes terminal breakage - curses.setupterm(fd=sys.__stdout__.fileno()) stdscr = curses.initscr() main(stdscr) finally: curses.endwin() - unit_tests() diff --git a/Lib/test/test_ftplib.py b/Lib/test/test_ftplib.py index d782c53..1ff8d08 100644 --- a/Lib/test/test_ftplib.py +++ b/Lib/test/test_ftplib.py @@ -6,34 +6,48 @@ import time from unittest import TestCase from test import test_support -def server(evt, ready): +server_port = None + +# This function sets the evt 3 times: +# 1) when the connection is ready to be accepted. +# 2) when it is safe for the caller to close the connection +# 3) when we have closed the socket +def server(evt): + global server_port serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM) serv.settimeout(3) serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - serv.bind(("", 9091)) + server_port = test_support.bind_port(serv, "", 9091) serv.listen(5) - ready.set() + + # (1) Signal the caller that we are ready to accept the connection. + evt.set() try: conn, addr = serv.accept() except socket.timeout: pass else: conn.send(b"1 Hola mundo\n") + # (2) Signal the caller that it is safe to close the socket. + evt.set() conn.close() finally: serv.close() + # (3) Signal the caller that we are done. evt.set() class GeneralTests(TestCase): def setUp(self): - ftplib.FTP.port = 9091 self.evt = threading.Event() - ready = threading.Event() - threading.Thread(target=server, args=(self.evt, ready)).start() - ready.wait() + threading.Thread(target=server, args=(self.evt,)).start() + # Wait for the server to be ready. + self.evt.wait() + self.evt.clear() + ftplib.FTP.port = server_port def tearDown(self): + # Wait on the closing of the socket (this shouldn't be necessary). self.evt.wait() def testBasic(self): @@ -42,30 +56,35 @@ class GeneralTests(TestCase): # connects ftp = ftplib.FTP("localhost") + self.evt.wait() ftp.sock.close() def testTimeoutDefault(self): # default ftp = ftplib.FTP("localhost") self.assertTrue(ftp.sock.gettimeout() is None) + self.evt.wait() ftp.sock.close() def testTimeoutValue(self): # a value ftp = ftplib.FTP("localhost", timeout=30) self.assertEqual(ftp.sock.gettimeout(), 30) + self.evt.wait() ftp.sock.close() def testTimeoutConnect(self): ftp = ftplib.FTP() ftp.connect("localhost", timeout=30) self.assertEqual(ftp.sock.gettimeout(), 30) + self.evt.wait() ftp.sock.close() def testTimeoutDifferentOrder(self): ftp = ftplib.FTP(timeout=30) ftp.connect("localhost") self.assertEqual(ftp.sock.gettimeout(), 30) + self.evt.wait() ftp.sock.close() def testTimeoutDirectAccess(self): @@ -73,6 +92,7 @@ class GeneralTests(TestCase): ftp.timeout = 30 ftp.connect("localhost") self.assertEqual(ftp.sock.gettimeout(), 30) + self.evt.wait() ftp.sock.close() def testTimeoutNone(self): @@ -84,10 +104,10 @@ class GeneralTests(TestCase): finally: socket.setdefaulttimeout(previous) self.assertEqual(ftp.sock.gettimeout(), 30) + self.evt.wait() ftp.close() - def test_main(verbose=None): test_support.run_unittest(GeneralTests) diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py index 744b344..63ca17b 100644 --- a/Lib/test/test_itertools.py +++ b/Lib/test/test_itertools.py @@ -177,6 +177,7 @@ class TestBasicOps(unittest.TestCase): def test_ifilter(self): self.assertEqual(list(ifilter(isEven, range(6))), [0,2,4]) self.assertEqual(list(ifilter(None, [0,1,0,2,0])), [1,2]) + self.assertEqual(list(ifilter(bool, [0,1,0,2,0])), [1,2]) self.assertEqual(take(4, ifilter(isEven, count())), [0,2,4,6]) self.assertRaises(TypeError, ifilter) self.assertRaises(TypeError, ifilter, lambda x:x) @@ -187,6 +188,7 @@ class TestBasicOps(unittest.TestCase): def test_ifilterfalse(self): self.assertEqual(list(ifilterfalse(isEven, range(6))), [1,3,5]) self.assertEqual(list(ifilterfalse(None, [0,1,0,2,0])), [0,0,0]) + self.assertEqual(list(ifilterfalse(bool, [0,1,0,2,0])), [0,0,0]) self.assertEqual(take(4, ifilterfalse(isEven, count())), [1,3,5,7]) self.assertRaises(TypeError, ifilterfalse) self.assertRaises(TypeError, ifilterfalse, lambda x:x) diff --git a/Lib/token.py b/Lib/token.py index eb48e76..da4d29b3 100755 --- a/Lib/token.py +++ b/Lib/token.py @@ -72,6 +72,7 @@ tok_name = {} for _name, _value in list(globals().items()): if type(_value) is type(0): tok_name[_value] = _name +del _name, _value def ISTERMINAL(x): |