Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
2a903b26
Kaydet (Commit)
2a903b26
authored
Şub 27, 2010
tarafından
Florent Xicluna
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #1729305: Fix doctest to handle encode error with "backslashreplace". It fixes #7667 too.
üst
0263da54
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
3 deletions
+55
-3
doctest.py
Lib/doctest.py
+9
-2
test_doctest.py
Lib/test/test_doctest.py
+44
-1
NEWS
Misc/NEWS
+2
-0
No files found.
Lib/doctest.py
Dosyayı görüntüle @
2a903b26
...
@@ -218,11 +218,18 @@ def _load_testfile(filename, package, module_relative):
...
@@ -218,11 +218,18 @@ def _load_testfile(filename, package, module_relative):
return
file_contents
.
replace
(
os
.
linesep
,
'
\n
'
),
filename
return
file_contents
.
replace
(
os
.
linesep
,
'
\n
'
),
filename
return
open
(
filename
)
.
read
(),
filename
return
open
(
filename
)
.
read
(),
filename
# Use sys.stdout encoding for ouput.
_encoding
=
getattr
(
sys
.
__stdout__
,
'encoding'
,
None
)
or
'utf-8'
def
_indent
(
s
,
indent
=
4
):
def
_indent
(
s
,
indent
=
4
):
"""
"""
Add the given number of space characters to the beginning every
Add the given number of space characters to the beginning of
non-blank line in `s`, and return the result.
every non-blank line in `s`, and return the result.
If the string `s` is Unicode, it is encoded using the stdout
encoding and the `backslashreplace` error handler.
"""
"""
if
isinstance
(
s
,
unicode
):
s
=
s
.
encode
(
_encoding
,
'backslashreplace'
)
# This regexp matches the start of non-blank lines:
# This regexp matches the start of non-blank lines:
return
re
.
sub
(
'(?m)^(?!$)'
,
indent
*
' '
,
s
)
return
re
.
sub
(
'(?m)^(?!$)'
,
indent
*
' '
,
s
)
...
...
Lib/test/test_doctest.py
Dosyayı görüntüle @
2a903b26
# -*- coding: utf-8 -*-
"""
"""
Test script for doctest.
Test script for doctest.
"""
"""
...
@@ -372,7 +373,7 @@ We'll simulate a __file__ attr that ends in pyc:
...
@@ -372,7 +373,7 @@ We'll simulate a __file__ attr that ends in pyc:
>>> tests = finder.find(sample_func)
>>> tests = finder.find(sample_func)
>>> print tests # doctest: +ELLIPSIS
>>> print tests # doctest: +ELLIPSIS
[<DocTest sample_func from ...:1
6
(1 example)>]
[<DocTest sample_func from ...:1
7
(1 example)>]
The exact name depends on how test_doctest was invoked, so allow for
The exact name depends on how test_doctest was invoked, so allow for
leading path components.
leading path components.
...
@@ -2145,6 +2146,13 @@ doctest examples in a given file. In its simple invokation, it is
...
@@ -2145,6 +2146,13 @@ doctest examples in a given file. In its simple invokation, it is
called with the name of a file, which is taken to be relative to the
called with the name of a file, which is taken to be relative to the
calling module. The return value is (#failures, #tests).
calling module. The return value is (#failures, #tests).
We don't want `-v` in sys.argv for these tests.
>>> save_argv = sys.argv
>>> if '-v' in sys.argv:
... sys.argv = [arg for arg in save_argv if arg != '-v']
>>> doctest.testfile('test_doctest.txt') # doctest: +ELLIPSIS
>>> doctest.testfile('test_doctest.txt') # doctest: +ELLIPSIS
**********************************************************************
**********************************************************************
File "...", line 6, in test_doctest.txt
File "...", line 6, in test_doctest.txt
...
@@ -2284,6 +2292,41 @@ using the optional keyword argument `encoding`:
...
@@ -2284,6 +2292,41 @@ using the optional keyword argument `encoding`:
>>> doctest.testfile('test_doctest4.txt', encoding='utf-8')
>>> doctest.testfile('test_doctest4.txt', encoding='utf-8')
TestResults(failed=0, attempted=4)
TestResults(failed=0, attempted=4)
>>> doctest.master = None # Reset master.
>>> doctest.master = None # Reset master.
Switch the module encoding to 'utf-8' to test the verbose output without
bothering with the current sys.stdout encoding.
>>> doctest._encoding, saved_encoding = 'utf-8', doctest._encoding
>>> doctest.testfile('test_doctest4.txt', encoding='utf-8', verbose=True)
Trying:
u'föö'
Expecting:
u'f\xf6\xf6'
ok
Trying:
u'bąr'
Expecting:
u'b\u0105r'
ok
Trying:
'föö'
Expecting:
'f\xc3\xb6\xc3\xb6'
ok
Trying:
'bąr'
Expecting:
'b\xc4\x85r'
ok
1 items passed all tests:
4 tests in test_doctest4.txt
4 tests in 1 items.
4 passed and 0 failed.
Test passed.
TestResults(failed=0, attempted=4)
>>> doctest._encoding = saved_encoding
>>> doctest.master = None # Reset master.
>>> sys.argv = save_argv
"""
"""
# old_test1, ... used to live in doctest.py, but cluttered it. Note
# old_test1, ... used to live in doctest.py, but cluttered it. Note
...
...
Misc/NEWS
Dosyayı görüntüle @
2a903b26
...
@@ -35,6 +35,8 @@ Core and Builtins
...
@@ -35,6 +35,8 @@ Core and Builtins
Library
Library
-------
-------
- Issue #1729305: Fix doctest to handle encode error with "backsplashreplace".
- Issue #691291: codecs.open() should not convert end of lines on reading and
- Issue #691291: codecs.open() should not convert end of lines on reading and
writing.
writing.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment