👷 ALLOW_UNICODE and custom pretty printer in doctests

We could also have set ALLOW_UNICODE globally, but this way we might
catch situations where we definitely do not expect mixed results between
py2 and py3.
This commit is contained in:
Gina Häußge committed 2019-02-21 15:29:20 +01:00
1 parent 8080e65366
commit 02566ae9d0
11 files changed
+129 -103

No files matched your search

+4
View File
@@ -0,0 +1,4 @@
[pytest]
testpaths = src tests
addopts = --doctest-modules
--doctest-repr=octoprint.util:pp
+1
View File
@@ -81,6 +81,7 @@ EXTRA_REQUIRES = dict(
# Testing dependencies
"mock>=2.0.0,<3",
"pytest>=4.2.1,<5.0",
"pytest-doctest-custom>=1.0.0,<1.1",
"ddt",
# linter
+6 -7
View File
@@ -79,18 +79,17 @@ def get_divider_line(c, message=None, length=78, indent=3):
Examples:
>>> from octoprint.util import to_native_str
>>> to_native_str(get_divider_line("-"))
>>> get_divider_line("-") # doctest: +ALLOW_UNICODE
'------------------------------------------------------------------------------'
>>> to_native_str(get_divider_line("=", length=10))
>>> get_divider_line("=", length=10) # doctest: +ALLOW_UNICODE
'=========='
>>> to_native_str(get_divider_line("-", message="Hi", length=10))
>>> get_divider_line("-", message="Hi", length=10) # doctest: +ALLOW_UNICODE
'--- Hi ---'
>>> to_native_str(get_divider_line("-", message="A slightly longer text"))
>>> get_divider_line("-", message="A slightly longer text") # doctest: +ALLOW_UNICODE
'--- A slightly longer text ---------------------------------------------------'
>>> to_native_str(get_divider_line("-", message="A slightly longer text", indent=5))
>>> get_divider_line("-", message="A slightly longer text", indent=5) # doctest: +ALLOW_UNICODE
'----- A slightly longer text -------------------------------------------------'
>>> to_native_str(get_divider_line("-", message="Hello World!", length=10))
>>> get_divider_line("-", message="Hello World!", length=10) # doctest: +ALLOW_UNICODE
'--- Hello World!'
>>> get_divider_line(None)
Traceback (most recent call last):
+11 -15
View File
@@ -439,12 +439,11 @@ class AnnouncementPlugin(octoprint.plugin.AssetPlugin,
_image_tag_re = re.compile(r'<img.*?/?>')
def _strip_images(text):
"""
>>> from octoprint.util import to_native_str
>>> to_native_str(_strip_images("<a href='test.html'>I'm a link</a> and this is an image: <img src='foo.jpg' alt='foo'>"))
>>> _strip_images("<a href='test.html'>I'm a link</a> and this is an image: <img src='foo.jpg' alt='foo'>") # doctest: +ALLOW_UNICODE
"<a href='test.html'>I'm a link</a> and this is an image: "
>>> to_native_str(_strip_images("One <img src=\\"one.jpg\\"> and two <img src='two.jpg' > and three <img src=three.jpg> and four <img src=\\"four.png\\" alt=\\"four\\">"))
>>> _strip_images("One <img src=\\"one.jpg\\"> and two <img src='two.jpg' > and three <img src=three.jpg> and four <img src=\\"four.png\\" alt=\\"four\\">") # doctest: +ALLOW_UNICODE
'One and two and three and four '
>>> to_native_str(_strip_images("No images here"))
>>> _strip_images("No images here") # doctest: +ALLOW_UNICODE
'No images here'
"""
return _image_tag_re.sub('', text)
@@ -452,10 +451,9 @@ def _strip_images(text):
def _replace_images(text, callback):
"""
>>> callback = lambda img: "foobar"
>>> from octoprint.util import to_native_str
>>> to_native_str(_replace_images("<a href='test.html'>I'm a link</a> and this is an image: <img src='foo.jpg' alt='foo'>", callback))
>>> _replace_images("<a href='test.html'>I'm a link</a> and this is an image: <img src='foo.jpg' alt='foo'>", callback) # doctest: +ALLOW_UNICODE
"<a href='test.html'>I'm a link</a> and this is an image: foobar"
>>> to_native_str(_replace_images("One <img src=\\"one.jpg\\"> and two <img src='two.jpg' > and three <img src=three.jpg> and four <img src=\\"four.png\\" alt=\\"four\\">", callback))
>>> _replace_images("One <img src=\\"one.jpg\\"> and two <img src='two.jpg' > and three <img src=three.jpg> and four <img src=\\"four.png\\" alt=\\"four\\">", callback) # doctest: +ALLOW_UNICODE
'One foobar and two foobar and three foobar and four foobar'
"""
result = text
@@ -468,14 +466,13 @@ def _replace_images(text, callback):
_image_src_re = re.compile(r'src=(?P<quote>[\'"]*)(?P<src>.*?)(?P=quote)(?=\s+|>)')
def _lazy_images(text, placeholder=None):
"""
>>> from octoprint.util import to_native_str
>>> to_native_str(_lazy_images("<a href='test.html'>I'm a link</a> and this is an image: <img src='foo.jpg' alt='foo'>"))
>>> _lazy_images("<a href='test.html'>I'm a link</a> and this is an image: <img src='foo.jpg' alt='foo'>") # doctest: +ALLOW_UNICODE
'<a href=\\'test.html\\'>I\\'m a link</a> and this is an image: <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-src=\\'foo.jpg\\' alt=\\'foo\\'>'
>>> to_native_str(_lazy_images("<a href='test.html'>I'm a link</a> and this is an image: <img src='foo.jpg' alt='foo'>", placeholder="ph.png"))
>>> _lazy_images("<a href='test.html'>I'm a link</a> and this is an image: <img src='foo.jpg' alt='foo'>", placeholder="ph.png") # doctest: +ALLOW_UNICODE
'<a href=\\'test.html\\'>I\\'m a link</a> and this is an image: <img src="ph.png" data-src=\\'foo.jpg\\' alt=\\'foo\\'>'
>>> to_native_str(_lazy_images("One <img src=\\"one.jpg\\"> and two <img src='two.jpg' > and three <img src=three.jpg> and four <img src=\\"four.png\\" alt=\\"four\\">", placeholder="ph.png"))
>>> _lazy_images("One <img src=\\"one.jpg\\"> and two <img src='two.jpg' > and three <img src=three.jpg> and four <img src=\\"four.png\\" alt=\\"four\\">", placeholder="ph.png") # doctest: +ALLOW_UNICODE
'One <img src="ph.png" data-src="one.jpg"> and two <img src="ph.png" data-src=\\'two.jpg\\' > and three <img src="ph.png" data-src=three.jpg> and four <img src="ph.png" data-src="four.png" alt="four">'
>>> to_native_str(_lazy_images("No images here"))
>>> _lazy_images("No images here") # doctest: +ALLOW_UNICODE
'No images here'
"""
if placeholder is None:
@@ -495,10 +492,9 @@ def _lazy_images(text, placeholder=None):
def _strip_tags(text):
"""
>>> from octoprint.util import to_native_str
>>> to_native_str(_strip_tags("<a href='test.html'>Hello world</a>&lt;img src='foo.jpg'&gt;"))
>>> _strip_tags("<a href='test.html'>Hello world</a>&lt;img src='foo.jpg'&gt;") # doctest: +ALLOW_UNICODE
"Hello world&lt;img src='foo.jpg'&gt;"
>>> to_native_str(_strip_tags("&#62; &#x3E; Foo"))
>>> _strip_tags("&#62; &#x3E; Foo") # doctest: +ALLOW_UNICODE
'&#62; &#x3E; Foo'
"""
try:
@@ -146,7 +146,7 @@ class PrinterProfileSubwizard(object):
return gettext("Default Printer Profile")
Subwizards = type(to_native_str("Subwizwards"),
Subwizards = type(to_native_str("Subwizards"),
tuple(cls for clsname, cls in inspect.getmembers(sys.modules[__name__], inspect.isclass)
if clsname.endswith("Subwizard")),
dict())
+1 -2
View File
@@ -97,10 +97,9 @@ def valid_timelapse(path):
def _extract_prefix(filename):
"""
>>> from octoprint.util import to_native_str
>>> _extract_prefix("some_long_filename_without_hyphen.jpg")
>>> _extract_prefix("-first_char_is_hyphen.jpg")
>>> to_native_str(_extract_prefix("some_long_filename_with-stuff.jpg"))
>>> _extract_prefix("some_long_filename_with-stuff.jpg") # doctest: +ALLOW_UNICODE
'some_long_filename_with'
"""
pos = filename.rfind("-")
+83 -53
View File
@@ -36,27 +36,73 @@ from past.builtins import basestring, unicode
logger = logging.getLogger(__name__)
def to_bytes(s_or_u, encoding="utf-8", errors="strict"):
"""Make sure ``s_or_u`` is a bytestring."""
if isinstance(s_or_u, unicode):
return s_or_u.encode(encoding, errors=errors)
else:
return s_or_u
def to_unicode(s_or_u, encoding="utf-8", errors="strict"):
"""Make sure ``s_or_u`` is a unicode string."""
if isinstance(s_or_u, bytes):
return s_or_u.decode(encoding, errors=errors)
else:
return s_or_u
def to_native_str(s_or_u):
"""Make sure ``s_or_u`` is a 'str'."""
if sys.version_info[0] == 2:
if isinstance(s_or_u, unicode):
return s_or_u.encode("utf-8")
elif isinstance(s_or_u, set): # only used for doctests
if not s_or_u:
return b"set()"
return b'{'+b', '.join(repr(to_native_str(x)) for x in sorted(s_or_u))+b'}'
return to_bytes(s_or_u)
else:
if isinstance(s_or_u, bytes):
return s_or_u.decode("utf-8") # only used for doctests
elif isinstance(s_or_u, str):
pass
elif isinstance(s_or_u, set): # only used for doctests
return '{'+repr(tuple(sorted(s_or_u)))[1:-1]+'}'
else:
raise RuntimeError("Please use a string here.")
return s_or_u
return to_unicode(s_or_u)
def pp(value):
"""
>>> pp(dict()) # doctest: +ALLOW_UNICODE
'dict()'
>>> pp(dict(a=1, b=2, c=3)) # doctest: +ALLOW_UNICODE
'dict(a=1, b=2, c=3)'
>>> pp(set()) # doctest: +ALLOW_UNICODE
'set()'
>>> pp({"a", "b"}) # doctest: +ALLOW_UNICODE
"{'a', 'b'}"
>>> pp(["a", "b", "d", "c"]) # doctest: +ALLOW_UNICODE
"['a', 'b', 'd', 'c']"
>>> pp(("a", "b", "d", "c")) # doctest: +ALLOW_UNICODE
"('a', 'b', 'd', 'c')"
>>> pp("foo") # doctest: +ALLOW_UNICODE
"'foo'"
>>> pp([dict(a=1, b=2), {"a", "c", "b"}, (1, 2), None, 1, True, "foo"]) # doctest: +ALLOW_UNICODE
"[dict(a=1, b=2), {'a', 'b', 'c'}, (1, 2), None, 1, True, 'foo']"
"""
if isinstance(value, dict):
# sort by keys
r = "dict("
r += ", ".join(map(lambda i: i[0] + "=" + pp(i[1]), sorted(value.items())))
r += ")"
return r
elif isinstance(value, set):
if len(value):
# filled set: sort
r = "{"
r += ", ".join(map(pp, sorted(value)))
r += "}"
return r
else:
# empty set
return "set()"
elif isinstance(value, list):
return "[" + ", ".join(map(pp, value)) + "]"
elif isinstance(value, tuple):
return "(" + ", ".join(map(pp, value)) + ")"
else:
return repr(value)
def warning_decorator_factory(warning_type):
def specific_warning(message, stacklevel=1, since=None, includedoc=None, extenddoc=False):
@@ -193,6 +239,9 @@ Returns:
"""
to_str = deprecated("to_str has been renamed to to_bytes", since="1.3.11")(to_bytes)
def get_formatted_size(num):
"""
Formats the given byte count as a human readable rounded size expressed in the most pressing unit among B(ytes),
@@ -337,20 +386,20 @@ def get_dos_filename(input, existing_filenames=None, extension=None, whitelisted
Examples:
>>> to_native_str(get_dos_filename("test1234.gco"))
>>> get_dos_filename("test1234.gco") # doctest: +ALLOW_UNICODE
'test1234.gco'
>>> to_native_str(get_dos_filename("test1234.gcode"))
>>> get_dos_filename("test1234.gcode") # doctest: +ALLOW_UNICODE
'test1234.gco'
>>> to_native_str(get_dos_filename("test12345.gco"))
>>> get_dos_filename("test12345.gco") # doctest: +ALLOW_UNICODE
'test12~1.gco'
>>> to_native_str(get_dos_filename("test1234.fnord", extension="gco"))
>>> get_dos_filename("test1234.fnord", extension="gco") # doctest: +ALLOW_UNICODE
'test1234.gco'
>>> to_native_str(get_dos_filename("auto0.g", extension="gco"))
>>> get_dos_filename("auto0.g", extension="gco") # doctest: +ALLOW_UNICODE
'auto0.gco'
>>> to_native_str(get_dos_filename("auto0.g", extension="gco", whitelisted_extensions=["g"]))
>>> get_dos_filename("auto0.g", extension="gco", whitelisted_extensions=["g"]) # doctest: +ALLOW_UNICODE
'auto0.g'
>>> get_dos_filename(None)
>>> to_native_str(get_dos_filename("foo"))
>>> get_dos_filename("foo") # doctest: +ALLOW_UNICODE
'foo'
"""
@@ -422,30 +471,30 @@ def find_collision_free_name(filename, extension, existing_filenames, max_power=
Examples:
>>> to_native_str(find_collision_free_name("test1234", "gco", []))
>>> find_collision_free_name("test1234", "gco", []) # doctest: +ALLOW_UNICODE
'test1234.gco'
>>> to_native_str(find_collision_free_name("test1234", "gcode", []))
>>> find_collision_free_name("test1234", "gcode", []) # doctest: +ALLOW_UNICODE
'test1234.gco'
>>> to_native_str(find_collision_free_name("test12345", "gco", []))
>>> find_collision_free_name("test12345", "gco", []) # doctest: +ALLOW_UNICODE
'test12~1.gco'
>>> to_native_str(find_collision_free_name("test 123", "gco", []))
>>> find_collision_free_name("test 123", "gco", []) # doctest: +ALLOW_UNICODE
'test_123.gco'
>>> to_native_str(find_collision_free_name("test1234", "g o", []))
>>> find_collision_free_name("test1234", "g o", []) # doctest: +ALLOW_UNICODE
'test1234.g_o'
>>> to_native_str(find_collision_free_name("test12345", "gco", ["/test12~1.gco"]))
>>> find_collision_free_name("test12345", "gco", ["/test12~1.gco"]) # doctest: +ALLOW_UNICODE
'test12~2.gco'
>>> many_files = ["/test12~{}.gco".format(x) for x in range(10)[1:]]
>>> to_native_str(find_collision_free_name("test12345", "gco", many_files))
>>> find_collision_free_name("test12345", "gco", many_files) # doctest: +ALLOW_UNICODE
'test1~10.gco'
>>> many_more_files = many_files + ["/test1~{}.gco".format(x) for x in range(10, 99)]
>>> to_native_str(find_collision_free_name("test12345", "gco", many_more_files))
>>> find_collision_free_name("test12345", "gco", many_more_files) # doctest: +ALLOW_UNICODE
'test1~99.gco'
>>> many_more_files_plus_one = many_more_files + ["/test1~99.gco"]
>>> to_native_str(find_collision_free_name("test12345", "gco", many_more_files_plus_one))
>>> find_collision_free_name("test12345", "gco", many_more_files_plus_one) # doctest: +ALLOW_UNICODE
Traceback (most recent call last):
...
ValueError: Can't create a collision free filename
>>> to_native_str(find_collision_free_name("test12345", "gco", many_more_files_plus_one, max_power=3))
>>> find_collision_free_name("test12345", "gco", many_more_files_plus_one, max_power=3) # doctest: +ALLOW_UNICODE
'test~100.gco'
"""
@@ -526,25 +575,6 @@ def filter_non_ascii(line):
return True
def to_bytes(s_or_u, encoding="utf-8", errors="strict"):
"""Make sure ``s_or_u`` is a bytestring."""
if isinstance(s_or_u, unicode):
return s_or_u.encode(encoding, errors=errors)
else:
return s_or_u
to_str = deprecated("to_str has been renamed to to_bytes", since="1.3.11")(to_bytes)
def to_unicode(s_or_u, encoding="utf-8", errors="strict"):
"""Make sure ``s_or_u`` is a unicode string."""
if isinstance(s_or_u, bytes):
return s_or_u.decode(encoding, errors=errors)
else:
return s_or_u
def chunks(l, n):
"""
Yield successive n-sized chunks from l.
@@ -1607,7 +1637,7 @@ class dictview(collections.Mapping):
...
KeyError: 'foo'
>>> my_dict["foo"] = "bar"
>>> to_native_str(view["foo"])
>>> view["foo"] # doctest: +ALLOW_UNICODE
'bar'
>>> view["foo"] = "fnord"
Traceback (most recent call last):
@@ -1645,7 +1675,7 @@ class protectedkeydict(collections.MutableMapping):
"""
>>> my_dict = dict(a="a")
>>> protected = protectedkeydict(my_dict)
>>> to_native_str(protected["a"])
>>> protected["a"] # doctest: +ALLOW_UNICODE
'a'
>>> protected["a"] = "b" # doctest: +ALLOW_UNICODE
Traceback (most recent call last):
+16 -19
View File
@@ -4576,35 +4576,32 @@ def _normalize_command_handler_result(command, command_type, gcode, subcode, tag
be empty in which case the command is to be suppressed.
Examples:
>>> from octoprint.util import to_native_str
>>> uu = lambda x: tuple(to_native_str(y) if y is not None else None for y in x)
>>> u = lambda x: list(uu(y) for y in x)
>>> u(_normalize_command_handler_result("M105", None, "M105", None, None, None))
>>> _normalize_command_handler_result("M105", None, "M105", None, None, None) # doctest: +ALLOW_UNICODE
[('M105', None, 'M105', None, None)]
>>> u(_normalize_command_handler_result("M105", None, "M105", None, None, "M110"))
>>> _normalize_command_handler_result("M105", None, "M105", None, None, "M110") # doctest: +ALLOW_UNICODE
[('M110', None, 'M110', None, None)]
>>> u(_normalize_command_handler_result("M105", None, "M105", None, None, ["M110"]))
>>> _normalize_command_handler_result("M105", None, "M105", None, None, ["M110"]) # doctest: +ALLOW_UNICODE
[('M110', None, 'M110', None, None)]
>>> u(_normalize_command_handler_result("M105", None, "M105", None, None, ["M110", "M117 Foobar"]))
>>> _normalize_command_handler_result("M105", None, "M105", None, None, ["M110", "M117 Foobar"]) # doctest: +ALLOW_UNICODE
[('M110', None, 'M110', None, None), ('M117 Foobar', None, 'M117', None, None)]
>>> u(_normalize_command_handler_result("M105", None, "M105", None, None, [("M110",), "M117 Foobar"]))
>>> _normalize_command_handler_result("M105", None, "M105", None, None, [("M110",), "M117 Foobar"]) # doctest: +ALLOW_UNICODE
[('M110', None, 'M110', None, None), ('M117 Foobar', None, 'M117', None, None)]
>>> u(_normalize_command_handler_result("M105", None, "M105", None, None, [("M110", "lineno_reset"), "M117 Foobar"]))
>>> _normalize_command_handler_result("M105", None, "M105", None, None, [("M110", "lineno_reset"), "M117 Foobar"]) # doctest: +ALLOW_UNICODE
[('M110', 'lineno_reset', 'M110', None, None), ('M117 Foobar', None, 'M117', None, None)]
>>> u(_normalize_command_handler_result("M105", None, "M105", None, None, []))
>>> _normalize_command_handler_result("M105", None, "M105", None, None, []) # doctest: +ALLOW_UNICODE
[]
>>> u(_normalize_command_handler_result("M105", None, "M105", None, None, ["M110", None]))
>>> _normalize_command_handler_result("M105", None, "M105", None, None, ["M110", None]) # doctest: +ALLOW_UNICODE
[('M110', None, 'M110', None, None)]
>>> u(_normalize_command_handler_result("M105", None, "M105", None, None, [("M110",), (None, "ignored")]))
>>> _normalize_command_handler_result("M105", None, "M105", None, None, [("M110",), (None, "ignored")]) # doctest: +ALLOW_UNICODE
[('M110', None, 'M110', None, None)]
>>> u(_normalize_command_handler_result("M105", None, "M105", None, None, [("M110",), ("M117 Foobar", "display_message"), ("tuple", "of", "unexpected", "length"), ("M110", "lineno_reset")]))
>>> _normalize_command_handler_result("M105", None, "M105", None, None, [("M110",), ("M117 Foobar", "display_message"), ("tuple", "of", "unexpected", "length"), ("M110", "lineno_reset")]) # doctest: +ALLOW_UNICODE
[('M110', None, 'M110', None, None), ('M117 Foobar', 'display_message', 'M117', None, None), ('M110', 'lineno_reset', 'M110', None, None)]
>>> u(_normalize_command_handler_result("M105", None, "M105", None, {"tag1", "tag2"}, ["M110", "M117 Foobar"]))
[('M110', None, 'M110', None, "{'tag1', 'tag2'}"), ('M117 Foobar', None, 'M117', None, "{'tag1', 'tag2'}")]
>>> u(_normalize_command_handler_result("M105", None, "M105", None, {"tag1", "tag2"}, ["M110", "M105", "M117 Foobar"], tags_to_add={"tag3"}))
[('M110', None, 'M110', None, "{'tag1', 'tag2', 'tag3'}"), ('M105', None, 'M105', None, "{'tag1', 'tag2'}"), ('M117 Foobar', None, 'M117', None, "{'tag1', 'tag2', 'tag3'}")]
>>> u(_normalize_command_handler_result("M105", None, "M105", None, {"tag1", "tag2"}, ["M110", ("M105", "temperature_poll"), "M117 Foobar"], tags_to_add={"tag3"}))
[('M110', None, 'M110', None, "{'tag1', 'tag2', 'tag3'}"), ('M105', 'temperature_poll', 'M105', None, "{'tag1', 'tag2', 'tag3'}"), ('M117 Foobar', None, 'M117', None, "{'tag1', 'tag2', 'tag3'}")]
>>> _normalize_command_handler_result("M105", None, "M105", None, {"tag1", "tag2"}, ["M110", "M117 Foobar"]) # doctest: +ALLOW_UNICODE
[('M110', None, 'M110', None, {'tag1', 'tag2'}), ('M117 Foobar', None, 'M117', None, {'tag1', 'tag2'})]
>>> _normalize_command_handler_result("M105", None, "M105", None, {"tag1", "tag2"}, ["M110", "M105", "M117 Foobar"], tags_to_add={"tag3"}) # doctest: +ALLOW_UNICODE
[('M110', None, 'M110', None, {'tag1', 'tag2', 'tag3'}), ('M105', None, 'M105', None, {'tag1', 'tag2'}), ('M117 Foobar', None, 'M117', None, {'tag1', 'tag2', 'tag3'})]
>>> _normalize_command_handler_result("M105", None, "M105", None, {"tag1", "tag2"}, ["M110", ("M105", "temperature_poll"), "M117 Foobar"], tags_to_add={"tag3"}) # doctest: +ALLOW_UNICODE
[('M110', None, 'M110', None, {'tag1', 'tag2', 'tag3'}), ('M105', 'temperature_poll', 'M105', None, {'tag1', 'tag2', 'tag3'}), ('M117 Foobar', None, 'M117', None, {'tag1', 'tag2', 'tag3'})]
Arguments:
command (str or None): The command for which the handler result was
+2 -3
View File
@@ -37,12 +37,11 @@ def clean_ansi(line):
Example::
>>> from octoprint.util import to_native_str
>>> text = b"Some text with some \x1b[31mred words\x1b[39m in it"
>>> to_native_str(clean_ansi(text))
>>> clean_ansi(text) # doctest: +ALLOW_BYTES
'Some text with some red words in it'
>>> text = b"We \x1b[?25lhide the cursor here and then \x1b[?25hshow it again here"
>>> to_native_str(clean_ansi(text))
>>> clean_ansi(text) # doctest: +ALLOW_BYTES
'We hide the cursor here and then show it again here'
"""
if isinstance(line, unicode):
+1 -2
View File
@@ -426,9 +426,8 @@ class PipCaller(CommandlineCaller):
Example::
>>> from octoprint.util import to_native_str
>>> text = b'some text with some\x1b[?25h ANSI codes for \x1b[31mred words\x1b[39m and\x1b[?25l also some cursor control codes'
>>> to_native_str(PipCaller._preprocess(text))
>>> PipCaller._preprocess(text) # doctest: +ALLOW_UNICODE
'some text with some ANSI codes for red words and also some cursor control codes'
"""
return to_unicode(clean_ansi(text))
+3 -1
View File
@@ -3,11 +3,13 @@ envlist = py27,py37,flake8
[testenv]
passenv = APPDATA
setenv = PY_IGNORE_IMPORTMISMATCH = 1
deps =
mock>=2.0.0,<3
pytest>=4.2.1,<5.0
pytest-doctest-custom>=1.0.0,<1.1
ddt
commands = pytest src tests --doctest-modules []
commands = pytest
[testenv:flake8]
basepython = python3