From d9f57630fed16bd1e97737f8afc22b5cc6645769 Mon Sep 17 00:00:00 2001 From: Florent Xicluna Date: Thu, 14 Oct 2010 20:56:20 +0000 Subject: Fix the regex to match all kind of filenames, for interactive debugging in doctests. (issue #9409) --- Lib/doctest.py | 2 +- Lib/test/test_doctest.py | 22 +++++++++++----------- Misc/NEWS | 3 +++ 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Lib/doctest.py b/Lib/doctest.py index 0a0dafd..e15f704 100644 --- a/Lib/doctest.py +++ b/Lib/doctest.py @@ -1319,7 +1319,7 @@ class DocTestRunner: self.tries += t __LINECACHE_FILENAME_RE = re.compile(r'[\w\.]+)' + r'(?P.+)' r'\[(?P\d+)\]>$') def __patched_linecache_getlines(self, filename, module_globals=None): m = self.__LINECACHE_FILENAME_RE.match(filename) diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py index 96c93f6..c0136a6 100644 --- a/Lib/test/test_doctest.py +++ b/Lib/test/test_doctest.py @@ -1700,7 +1700,7 @@ def test_pdb_set_trace(): ... >>> import pdb; pdb.set_trace() ... ''' >>> parser = doctest.DocTestParser() - >>> test = parser.get_doctest(doc, {}, "foo", "foo.py", 0) + >>> test = parser.get_doctest(doc, {}, "foo-bär@baz", "foo-bär@baz.py", 0) >>> runner = doctest.DocTestRunner(verbose=False) To demonstrate this, we'll create a fake standard input that @@ -1716,7 +1716,7 @@ def test_pdb_set_trace(): >>> try: runner.run(test) ... finally: sys.stdin = real_stdin --Return-- - > (1)()->None + > (1)()->None -> import pdb; pdb.set_trace() (Pdb) print(x) 42 @@ -1733,7 +1733,7 @@ def test_pdb_set_trace(): ... >>> x=1 ... >>> calls_set_trace() ... ''' - >>> test = parser.get_doctest(doc, globals(), "foo", "foo.py", 0) + >>> test = parser.get_doctest(doc, globals(), "foo-bär@baz", "foo-bär@baz.py", 0) >>> real_stdin = sys.stdin >>> sys.stdin = _FakeInput([ ... 'print(y)', # print data defined in the function @@ -1752,7 +1752,7 @@ def test_pdb_set_trace(): (Pdb) print(y) 2 (Pdb) up - > (1)() + > (1)() -> calls_set_trace() (Pdb) print(x) 1 @@ -1770,7 +1770,7 @@ def test_pdb_set_trace(): ... ... import pdb; pdb.set_trace() ... >>> f(3) ... ''' - >>> test = parser.get_doctest(doc, globals(), "foo", "foo.py", 0) + >>> test = parser.get_doctest(doc, globals(), "foo-bär@baz", "foo-bär@baz.py", 0) >>> real_stdin = sys.stdin >>> sys.stdin = _FakeInput([ ... 'list', # list source from example 2 @@ -1784,7 +1784,7 @@ def test_pdb_set_trace(): ... finally: sys.stdin = real_stdin ... # doctest: +NORMALIZE_WHITESPACE --Return-- - > (3)g()->None + > (3)g()->None -> import pdb; pdb.set_trace() (Pdb) list 1 def g(x): @@ -1793,7 +1793,7 @@ def test_pdb_set_trace(): [EOF] (Pdb) next --Return-- - > (2)f()->None + > (2)f()->None -> g(x*2) (Pdb) list 1 def f(x): @@ -1801,14 +1801,14 @@ def test_pdb_set_trace(): [EOF] (Pdb) next --Return-- - > (1)()->None + > (1)()->None -> f(3) (Pdb) list 1 -> f(3) [EOF] (Pdb) continue ********************************************************************** - File "foo.py", line 7, in foo + File "foo-bär@baz.py", line 7, in foo-bär@baz Failed example: f(3) Expected nothing @@ -1842,7 +1842,7 @@ def test_pdb_set_trace_nested(): ... ''' >>> parser = doctest.DocTestParser() >>> runner = doctest.DocTestRunner(verbose=False) - >>> test = parser.get_doctest(doc, globals(), "foo", "foo.py", 0) + >>> test = parser.get_doctest(doc, globals(), "foo-bär@baz", "foo-bär@baz.py", 0) >>> real_stdin = sys.stdin >>> sys.stdin = _FakeInput([ ... 'print(y)', # print data defined in the function @@ -1895,7 +1895,7 @@ def test_pdb_set_trace_nested(): (Pdb) print(y) 1 (Pdb) up - > (1)() + > (1)() -> calls_set_trace() (Pdb) print(foo) *** NameError: name 'foo' is not defined diff --git a/Misc/NEWS b/Misc/NEWS index c09e24f..38e68e3 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -21,6 +21,9 @@ Core and Builtins Library ------- +- Issue 9409: Fix the regex to match all kind of filenames, for interactive + debugging in doctests. + - Issue 9183: ``datetime.timezone(datetime.timedelta(0))`` will now return the same instance as ``datetime.timezone.utc``. -- cgit v0.12