From 00abf385ac3b4b13aee66cbeb2a33604d8a871f5 Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Thu, 27 Mar 2014 12:21:20 -0400 Subject: asyncio.tests: Autodiscover asyncio tests. Patch by Vajrasky Kok. Closes #20668 --- Lib/test/test_asyncio/__init__.py | 22 ++++++++++------------ Misc/NEWS | 3 +++ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Lib/test/test_asyncio/__init__.py b/Lib/test/test_asyncio/__init__.py index 23ce5e8..82158af 100644 --- a/Lib/test/test_asyncio/__init__.py +++ b/Lib/test/test_asyncio/__init__.py @@ -10,20 +10,18 @@ import_module('concurrent.futures') def suite(): - tests_file = os.path.join(os.path.dirname(__file__), 'tests.txt') - with open(tests_file) as fp: - test_names = fp.read().splitlines() tests = unittest.TestSuite() loader = unittest.TestLoader() - for test_name in test_names: - mod_name = 'test.' + test_name - try: - __import__(mod_name) - except unittest.SkipTest: - pass - else: - mod = sys.modules[mod_name] - tests.addTests(loader.loadTestsFromModule(mod)) + for fn in os.listdir(os.path.dirname(__file__)): + if fn.startswith("test") and fn.endswith(".py"): + mod_name = 'test.test_asyncio.' + fn[:-3] + try: + __import__(mod_name) + except unittest.SkipTest: + pass + else: + mod = sys.modules[mod_name] + tests.addTests(loader.loadTestsFromModule(mod)) return tests diff --git a/Misc/NEWS b/Misc/NEWS index 59e6d1c..8f55c63 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -107,6 +107,9 @@ Tests redirect of http://www.python.org/ to https://www.python.org: use http://www.example.com instead. +- Issue #20668: asyncio tests no longer rely on tests.txt file. + (Patch by Vajrasky Kok) + Tools/Demos ----------- -- cgit v0.12 From b1d060bf8b017d2a6cf6a0191b1451aeb27a5c03 Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Thu, 27 Mar 2014 18:23:03 -0400 Subject: inspect: Fix getcallargs() to raise correct TypeError ... for missing keyword-only arguments. Patch by Jeremiah Lowin. Closes #20816. --- Lib/inspect.py | 2 +- Lib/test/test_inspect.py | 8 ++++++++ Misc/NEWS | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Lib/inspect.py b/Lib/inspect.py index c7a2cf8..06057af 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -1208,7 +1208,7 @@ def getcallargs(*func_and_positional, **named): missing = 0 for kwarg in kwonlyargs: if kwarg not in arg2value: - if kwarg in kwonlydefaults: + if kwonlydefaults and kwarg in kwonlydefaults: arg2value[kwarg] = kwonlydefaults[kwarg] else: missing += 1 diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index 5c6ae39..20f7217 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -1206,6 +1206,14 @@ class TestGetcallargsFunctions(unittest.TestCase): self.assertEqualException(f3, '1, 2') self.assertEqualException(f3, '1, 2, a=1, b=2') + # issue #20816: getcallargs() fails to iterate over non-existent + # kwonlydefaults and raises a wrong TypeError + def f5(*, a): pass + with self.assertRaisesRegex(TypeError, + 'missing 1 required keyword-only'): + inspect.getcallargs(f5) + + class TestGetcallargsMethods(TestGetcallargsFunctions): def setUp(self): diff --git a/Misc/NEWS b/Misc/NEWS index 8f55c63..c51ad17 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -83,6 +83,9 @@ Library - Issue #19748: On AIX, time.mktime() now raises an OverflowError for year outsize range [1902; 2037]. +- Issue #20816: Fix inspect.getcallargs() to raise correct TypeError for + missing keyword-only arguments. Patch by Jeremiah Lowin. + Documentation ------------- -- cgit v0.12 From 2542b66bb04e5634410205f54523987dce9e5bf7 Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Thu, 27 Mar 2014 18:42:52 -0400 Subject: inspect: Fix getcallargs() to fail correctly if more than 3 args are missing. Patch by Jeremiah Lowin. Closes #20817. --- Lib/inspect.py | 2 +- Lib/test/test_inspect.py | 6 ++++++ Misc/NEWS | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Lib/inspect.py b/Lib/inspect.py index 06057af..9f9a600 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -1125,7 +1125,7 @@ def _missing_arguments(f_name, argnames, pos, values): elif missing == 2: s = "{} and {}".format(*names) else: - tail = ", {} and {}".format(names[-2:]) + tail = ", {} and {}".format(*names[-2:]) del names[-2:] s = ", ".join(names) + tail raise TypeError("%s() missing %i required %s argument%s: %s" % diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index 20f7217..38367f3 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -1214,6 +1214,12 @@ class TestGetcallargsFunctions(unittest.TestCase): inspect.getcallargs(f5) + # issue20817: + def f6(a, b, c): + pass + with self.assertRaisesRegex(TypeError, "'a', 'b' and 'c'"): + inspect.getcallargs(f6) + class TestGetcallargsMethods(TestGetcallargsFunctions): def setUp(self): diff --git a/Misc/NEWS b/Misc/NEWS index c51ad17..10ddd9a 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -86,6 +86,9 @@ Library - Issue #20816: Fix inspect.getcallargs() to raise correct TypeError for missing keyword-only arguments. Patch by Jeremiah Lowin. +- Issue #20817: Fix inspect.getcallargs() to fail correctly if more + than 3 arguments are missing. Patch by Jeremiah Lowin. + Documentation ------------- -- cgit v0.12 From e7d532fbc9c13e00b1e5c6c0db2dba31d1212de7 Mon Sep 17 00:00:00 2001 From: Ned Deily Date: Thu, 27 Mar 2014 16:39:58 -0700 Subject: Issue #6676: Ensure a meaningful exception is raised when attempting to parse more than one XML document per pyexpat xmlparser instance. (Original patches by Hirokazu Yamamoto and Amaury Forgeot d'Arc, with suggested wording by David Gutteridge) --- Doc/library/pyexpat.rst | 9 ++++++++- Lib/test/test_pyexpat.py | 12 ++++++++++++ Misc/NEWS | 5 +++++ Modules/pyexpat.c | 2 +- 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Doc/library/pyexpat.rst b/Doc/library/pyexpat.rst index 3d88d85..cb8ab65 100644 --- a/Doc/library/pyexpat.rst +++ b/Doc/library/pyexpat.rst @@ -100,6 +100,11 @@ The :mod:`xml.parsers.expat` module contains two functions: http://www.python.org/ns/ elem1 elem2 + Due to limitations in the ``Expat`` library used by :mod:`pyexpat`, + the :class:`xmlparser` instance returned can only be used to parse a single + XML document. Call ``ParserCreate`` for each document to provide unique + parser instances. + .. seealso:: @@ -119,7 +124,9 @@ XMLParser Objects Parses the contents of the string *data*, calling the appropriate handler functions to process the parsed data. *isfinal* must be true on the final call - to this method. *data* can be the empty string at any time. + to this method; it allows the parsing of a single file in fragments, + not the submission of multiple files. + *data* can be the empty string at any time. .. method:: xmlparser.ParseFile(file) diff --git a/Lib/test/test_pyexpat.py b/Lib/test/test_pyexpat.py index 8ef3917..95a614b 100644 --- a/Lib/test/test_pyexpat.py +++ b/Lib/test/test_pyexpat.py @@ -236,6 +236,18 @@ class ParseTest(unittest.TestCase): operations = out.out self._verify_parse_output(operations) + def test_parse_again(self): + parser = expat.ParserCreate() + file = BytesIO(data) + parser.ParseFile(file) + # Issue 6676: ensure a meaningful exception is raised when attempting + # to parse more than one XML document per xmlparser instance, + # a limitation of the Expat library. + with self.assertRaises(expat.error) as cm: + parser.ParseFile(file) + self.assertEqual(expat.ErrorString(cm.exception.code), + expat.errors.XML_ERROR_FINISHED) + class NamespaceSeparatorTest(unittest.TestCase): def test_legal(self): # Tests that make sure we get errors when the namespace_separator value diff --git a/Misc/NEWS b/Misc/NEWS index 10ddd9a..5240f69 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -89,6 +89,11 @@ Library - Issue #20817: Fix inspect.getcallargs() to fail correctly if more than 3 arguments are missing. Patch by Jeremiah Lowin. +- Issue #6676: Ensure a meaningful exception is raised when attempting + to parse more than one XML document per pyexpat xmlparser instance. + (Original patches by Hirokazu Yamamoto and Amaury Forgeot d'Arc, with + suggested wording by David Gutteridge) + Documentation ------------- diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c index a71ecc5..97f2b56 100644 --- a/Modules/pyexpat.c +++ b/Modules/pyexpat.c @@ -908,7 +908,7 @@ xmlparse_ParseFile(xmlparseobject *self, PyObject *f) void *buf = XML_GetBuffer(self->itself, BUF_SIZE); if (buf == NULL) { Py_XDECREF(readmethod); - return PyErr_NoMemory(); + return get_parse_result(self, 0); } bytes_read = readinst(buf, BUF_SIZE, readmethod); -- cgit v0.12