From: Ezio Melotti Date: Fri, 21 Sep 2012 13:53:07 +0000 (+0300) Subject: #15304: merge with 3.2. X-Git-Tag: v3.3.1rc1~818^2^2~59 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=050a61f838dcbf4b6fad6eb83404a7eb1ffb9b9b;p=python #15304: merge with 3.2. --- 050a61f838dcbf4b6fad6eb83404a7eb1ffb9b9b diff --cc Lib/test/test_support.py index 14fcdbfeac,0000000000..f6ef5f6147 mode 100644,000000..100644 --- a/Lib/test/test_support.py +++ b/Lib/test/test_support.py @@@ -1,190 -1,0 +1,199 @@@ +#!/usr/bin/env python + +import importlib +import sys +import os +import unittest +import socket +import tempfile +import errno +from test import support + +TESTFN = support.TESTFN +TESTDIRN = os.path.basename(tempfile.mkdtemp(dir='.')) + + +class TestSupport(unittest.TestCase): + def setUp(self): + support.unlink(TESTFN) + support.rmtree(TESTDIRN) + tearDown = setUp + + def test_import_module(self): + support.import_module("ftplib") + self.assertRaises(unittest.SkipTest, support.import_module, "foo") + + def test_import_fresh_module(self): + support.import_fresh_module("ftplib") + + def test_get_attribute(self): + self.assertEqual(support.get_attribute(self, "test_get_attribute"), + self.test_get_attribute) + self.assertRaises(unittest.SkipTest, support.get_attribute, self, "foo") + + @unittest.skip("failing buildbots") + def test_get_original_stdout(self): + self.assertEqual(support.get_original_stdout(), sys.stdout) + + def test_unload(self): + import sched + self.assertIn("sched", sys.modules) + support.unload("sched") + self.assertNotIn("sched", sys.modules) + + def test_unlink(self): + with open(TESTFN, "w") as f: + pass + support.unlink(TESTFN) + self.assertFalse(os.path.exists(TESTFN)) + support.unlink(TESTFN) + + def test_rmtree(self): + os.mkdir(TESTDIRN) + os.mkdir(os.path.join(TESTDIRN, TESTDIRN)) + support.rmtree(TESTDIRN) + self.assertFalse(os.path.exists(TESTDIRN)) + support.rmtree(TESTDIRN) + + def test_forget(self): + mod_filename = TESTFN + '.py' + with open(mod_filename, 'w') as f: + print('foo = 1', file=f) + sys.path.insert(0, os.curdir) + importlib.invalidate_caches() + try: + mod = __import__(TESTFN) + self.assertIn(TESTFN, sys.modules) + + support.forget(TESTFN) + self.assertNotIn(TESTFN, sys.modules) + finally: + del sys.path[0] + support.unlink(mod_filename) + + def test_HOST(self): + s = socket.socket() + s.bind((support.HOST, 0)) + s.close() + + def test_find_unused_port(self): + port = support.find_unused_port() + s = socket.socket() + s.bind((support.HOST, port)) + s.close() + + def test_bind_port(self): + s = socket.socket() + support.bind_port(s) + s.listen(1) + s.close() + + def test_temp_cwd(self): + here = os.getcwd() + with support.temp_cwd(name=TESTFN): + self.assertEqual(os.path.basename(os.getcwd()), TESTFN) + self.assertFalse(os.path.exists(TESTFN)) + self.assertTrue(os.path.basename(os.getcwd()), here) + ++ def test_temp_cwd__chdir_warning(self): ++ """Check the warning message when os.chdir() fails.""" ++ path = TESTFN + '_does_not_exist' ++ with support.check_warnings() as recorder: ++ with support.temp_cwd(path=path, quiet=True): ++ pass ++ messages = [str(w.message) for w in recorder.warnings] ++ self.assertEqual(messages, ['tests may fail, unable to change the CWD to ' + path]) ++ + def test_sortdict(self): + self.assertEqual(support.sortdict({3:3, 2:2, 1:1}), "{1: 1, 2: 2, 3: 3}") + + def test_make_bad_fd(self): + fd = support.make_bad_fd() + with self.assertRaises(OSError) as cm: + os.write(fd, b"foo") + self.assertEqual(cm.exception.errno, errno.EBADF) + + def test_check_syntax_error(self): + support.check_syntax_error(self, "def class") + self.assertRaises(AssertionError, support.check_syntax_error, self, "1") + + def test_CleanImport(self): + import importlib + with support.CleanImport("asyncore"): + importlib.import_module("asyncore") + + def test_DirsOnSysPath(self): + with support.DirsOnSysPath('foo', 'bar'): + self.assertIn("foo", sys.path) + self.assertIn("bar", sys.path) + self.assertNotIn("foo", sys.path) + self.assertNotIn("bar", sys.path) + + def test_captured_stdout(self): + with support.captured_stdout() as s: + print("hello") + self.assertEqual(s.getvalue(), "hello\n") + + def test_captured_stderr(self): + with support.captured_stderr() as s: + print("hello", file=sys.stderr) + self.assertEqual(s.getvalue(), "hello\n") + + def test_captured_stdin(self): + with support.captured_stdin() as s: + print("hello", file=sys.stdin) + self.assertEqual(s.getvalue(), "hello\n") + + def test_gc_collect(self): + support.gc_collect() + + def test_python_is_optimized(self): + self.assertIsInstance(support.python_is_optimized(), bool) + + def test_swap_attr(self): + class Obj: + x = 1 + obj = Obj() + with support.swap_attr(obj, "x", 5): + self.assertEqual(obj.x, 5) + self.assertEqual(obj.x, 1) + + def test_swap_item(self): + D = {"item":1} + with support.swap_item(D, "item", 5): + self.assertEqual(D["item"], 5) + self.assertEqual(D["item"], 1) + + # XXX -follows a list of untested API + # make_legacy_pyc + # is_resource_enabled + # requires + # fcmp + # umaks + # findfile + # check_warnings + # EnvironmentVarGuard + # TransientResource + # transient_internet + # run_with_locale + # set_memlimit + # bigmemtest + # precisionbigmemtest + # bigaddrspacetest + # requires_resource + # run_doctest + # threading_cleanup + # reap_threads + # reap_children + # strip_python_stderr + # args_from_interpreter_flags + # can_symlink + # skip_unless_symlink + + +def test_main(): + tests = [TestSupport] + support.run_unittest(*tests) + +if __name__ == '__main__': + test_main() diff --cc Misc/NEWS index 04580d71f4,bebab93611..5d6ca0f923 --- a/Misc/NEWS +++ b/Misc/NEWS @@@ -33,108 -21,101 +33,112 @@@ Core and Builtin - Issue #15801: Make sure mappings passed to '%' formatting are actually subscriptable. -- Issue #15726: Fix incorrect bounds checking in PyState_FindModule. - Patch by Robin Schreiber. +Library +------- -- Issue #15604: Update uses of PyObject_IsTrue() to check for and handle - errors correctly. Patch by Serhiy Storchaka. +- Issue #15970: xml.etree.ElementTree now serializes correctly the empty HTML + elements 'meta' and 'param'. -- Issue #13119: sys.stdout and sys.stderr are now using "\r\n" newline on - Windows, as Python 2. +- Issue #15842: the SocketIO.{readable,writable,seekable} methods now + raise ValueError when the file-like object is closed. Patch by Alessandro + Moura. -- Issue #14579: Fix CVE-2012-2135: vulnerability in the utf-16 decoder after - error handling. Patch by Serhiy Storchaka. +- Issue #15882: Change _decimal to accept any coefficient tuple when + constructing infinities. This is done for backwards compatibility + with decimal.py: Infinity coefficients are undefined in _decimal + (in accordance with the specification). -- Issue #15404: Refleak in PyMethodObject repr. +- Issue #15876: Fix a refleak in the curses module: window.encoding. -- Issue #15394: An issue in PyModule_Create that caused references to - be leaked on some error paths has been fixed. Patch by Julia Lawall. +- Issue #15881: Fixed atexit hook in multiprocessing. Original patch + by Chris McDonough. -- Issue #15368: An issue that caused bytecode generation to be - non-deterministic when using randomized hashing (-R) has been fixed. +- Issue #15340: Fix importing the random module when /dev/urandom cannot + be opened. This was a regression caused by the hash randomization patch. -- Issue #15020: The program name used to search for Python's path is now - "python3" under Unix, not "python". +- Issue #15841: The readable(), writable() and seekable() methods of BytesIO + and StringIO objects now raise ValueError when the object has been closed. + Patch by Alessandro Moura. -- Issue #15033: Fix the exit status bug when modules invoked using -m swith, - return the proper failure return value (1). Patch contributed by Jeff Knupp. +- Issue #15447: Use subprocess.DEVNULL in webbrowser, instead of opening + os.devnull explicitly and leaving it open. -- Issue #12268: File readline, readlines and read() or readall() methods - no longer lose data when an underlying read system call is interrupted. - IOError is no longer raised due to a read system call returning EINTR - from within these methods. +- Issue #15509: webbrowser.UnixBrowser no longer passes empty arguments to + Popen when %action substitutions produce empty strings. -- Issue #15142: Fix reference leak when deallocating instances of types - created using PyType_FromSpec(). +- Issue #12776,#11839: call argparse type function (specified by add_argument) + only once. Before, the type function was called twice in the case where the + default was specified and the argument was given as well. This was + especially problematic for the FileType type, as a default file would always + be opened, even if a file argument was specified on the command line. -- Issue #10053: Don't close FDs when FileIO.__init__ fails. Loosely based on - the work by Hirokazu Yamamoto. +- Issue #15906: Fix a regression in argparse caused by the preceding change, + when action='append', type='str' and default=[]. -- Issue #14775: Fix a potential quadratic dict build-up due to the garbage - collector repeatedly trying to untrack dicts. +Extension Modules +----------------- -- Issue #14494: Fix __future__.py and its documentation to note that - absolute imports are the default behavior in 3.0 instead of 2.7. - Patch by Sven Marnach. +- Issue #15977: Fix memory leak in Modules/_ssl.c when the function + _set_npn_protocols() is called multiple times, thanks to Daniel Sommermann. -- Issue #14761: Fix potential leak on an error case in the import machinery. +Tests +----- -- Issue #14699: Fix calling the classmethod descriptor directly. ++- Issue #15304: Fix warning message when os.chdir() fails inside ++ test.support.temp_cwd(). Patch by Chris Jerdonek. + -- Issue #14433: Prevent msvcrt crash in interactive prompt when stdin - is closed. + -- Issue #11603 (again): Setting __repr__ to __str__ now raises a RuntimeError - when repr() or str() is called on such an object. +- Issue #15802: Fix test logic in TestMaildir.test_create_tmp. Patch + by Serhiy Storchaka. -- Issue #14658: Fix binding a special method to a builtin implementation of a - special method with a different name. +- Issue #15557: Added a test suite for the webbrowser module, thanks + to Anton Barkovsky. -- Issue #14630: Fix a memory access bug for instances of a subclass of int - with value 0. +Build +----- -- Issue #14612: Fix jumping around with blocks by setting f_lineno. +- Issue #15819: Make sure we can build Python out-of-tree from a readonly + source directory. (Somewhat related to Issue #9860.) -- Issue #14607: Fix keyword-only arguments which started with ``__``. +Documentation +------------- -- Issue #13889: Check and (if necessary) set FPU control word before calling - any of the dtoa.c string <-> float conversion functions, on MSVC builds of - Python. This fixes issues when embedding Python in a Delphi app. +- Issue #11964: Document a change in v3.2 to the behavior of the indent + parameter of json encoding operations. -- Issue #14474: Save and restore exception state in thread.start_new_thread() - while writing error message if the thread leaves a unhandled exception. +Tools/Demos +----------- -- Issue #13019: Fix potential reference leaks in bytearray.extend(). Patch - by Suman Saha. -- Issue #14378: Fix compiling ast.ImportFrom nodes with a "__future__" string as - the module name that was not interned. +What's New in Python 3.3.0? +=========================== -- Issue #14331: Use significantly less stack space when importing modules by - allocating path buffers on the heap instead of the stack. +*Release date: XX-Sep-2012* -- Issue #14334: Prevent in a segfault in type.__getattribute__ when it was not - passed strings. +Core and Builtins +----------------- -- Issue #1469629: Allow cycles through an object's __dict__ slot to be - collected. (For example if ``x.__dict__ is x``). +Library +------- -- Issue #14172: Fix reference leak when marshalling a buffer-like object - (other than a bytes object). -- Issue #13521: dict.setdefault() now does only one lookup for the given key, - making it "atomic" for many purposes. Patch by Filip Gruszczyński. +What's New in Python 3.3.0 Release Candidate 2? +=============================================== -- Issue #14471: Fix a possible buffer overrun in the winreg module. +*Release date: 09-Sep-2012* + +Core and Builtins +----------------- + +- Issue #13992: The trashcan mechanism is now thread-safe. This eliminates + sporadic crashes in multi-thread programs when several long deallocator + chains ran concurrently and involved subclasses of built-in container + types. + +- Issue #15784: Modify OSError.__str__() to better distinguish between + errno error numbers and Windows error numbers. + +- Issue #15781: Fix two small race conditions in import's module locking. Library -------