mirror of
https://github.com/python/cpython.git
synced 2025-10-10 00:43:41 +00:00
bpo-43049: Use io.IncrementalNewlineDecoder for doctest newline conversion (GH-24359)
Followup to bpo-1812 and GH-17385.
This commit is contained in:
parent
503627fc2a
commit
b36349a647
1 changed files with 3 additions and 6 deletions
|
@ -102,7 +102,7 @@ import re
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
import unittest
|
import unittest
|
||||||
from io import StringIO
|
from io import StringIO, IncrementalNewlineDecoder
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
TestResults = namedtuple('TestResults', 'failed attempted')
|
TestResults = namedtuple('TestResults', 'failed attempted')
|
||||||
|
@ -212,11 +212,8 @@ def _normalize_module(module, depth=2):
|
||||||
raise TypeError("Expected a module, string, or None")
|
raise TypeError("Expected a module, string, or None")
|
||||||
|
|
||||||
def _newline_convert(data):
|
def _newline_convert(data):
|
||||||
# We have two cases to cover and we need to make sure we do
|
# The IO module provides a handy decoder for universal newline conversion
|
||||||
# them in the right order
|
return IncrementalNewlineDecoder(None, True).decode(data, True)
|
||||||
for newline in ('\r\n', '\r'):
|
|
||||||
data = data.replace(newline, '\n')
|
|
||||||
return data
|
|
||||||
|
|
||||||
def _load_testfile(filename, package, module_relative, encoding):
|
def _load_testfile(filename, package, module_relative, encoding):
|
||||||
if module_relative:
|
if module_relative:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue