From 02566ae9d02529ccc2a60c321fd4e3033c50fb49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 21 Feb 2019 15:29:20 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20ALLOW=5FUNICODE=20and=20custom?= =?UTF-8?q?=20pretty=20printer=20in=20doctests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- pytest.ini | 4 + setup.py | 1 + src/octoprint/logging/__init__.py | 13 +- .../plugins/announcements/__init__.py | 26 ++-- .../plugins/corewizard/subwizards.py | 2 +- src/octoprint/timelapse.py | 3 +- src/octoprint/util/__init__.py | 136 +++++++++++------- src/octoprint/util/comm.py | 35 +++-- src/octoprint/util/commandline.py | 5 +- src/octoprint/util/pip.py | 3 +- tox.ini | 4 +- 11 files changed, 129 insertions(+), 103 deletions(-) create mode 100644 pytest.ini diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 000000000..b6cad3962 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,4 @@ +[pytest] +testpaths = src tests +addopts = --doctest-modules + --doctest-repr=octoprint.util:pp diff --git a/setup.py b/setup.py index bbb41071e..1870b156b 100644 --- a/setup.py +++ b/setup.py @@ -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 diff --git a/src/octoprint/logging/__init__.py b/src/octoprint/logging/__init__.py index 6a0043ba5..1e324038b 100644 --- a/src/octoprint/logging/__init__.py +++ b/src/octoprint/logging/__init__.py @@ -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): diff --git a/src/octoprint/plugins/announcements/__init__.py b/src/octoprint/plugins/announcements/__init__.py index 2963e2cfa..2441b00e4 100644 --- a/src/octoprint/plugins/announcements/__init__.py +++ b/src/octoprint/plugins/announcements/__init__.py @@ -439,12 +439,11 @@ class AnnouncementPlugin(octoprint.plugin.AssetPlugin, _image_tag_re = re.compile(r'') def _strip_images(text): """ - >>> from octoprint.util import to_native_str - >>> to_native_str(_strip_images("I'm a link and this is an image: foo")) + >>> _strip_images("I'm a link and this is an image: foo") # doctest: +ALLOW_UNICODE "I'm a link and this is an image: " - >>> to_native_str(_strip_images("One and two and three and four \\"four\\"")) + >>> _strip_images("One and two and three and four \\"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("I'm a link and this is an image: foo", callback)) + >>> _replace_images("I'm a link and this is an image: foo", callback) # doctest: +ALLOW_UNICODE "I'm a link and this is an image: foobar" - >>> to_native_str(_replace_images("One and two and three and four \\"four\\"", callback)) + >>> _replace_images("One and two and three and four \\"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[\'"]*)(?P.*?)(?P=quote)(?=\s+|>)') def _lazy_images(text, placeholder=None): """ - >>> from octoprint.util import to_native_str - >>> to_native_str(_lazy_images("I'm a link and this is an image: foo")) + >>> _lazy_images("I'm a link and this is an image: foo") # doctest: +ALLOW_UNICODE 'I\\'m a link and this is an image: \\'foo\\'' - >>> to_native_str(_lazy_images("I'm a link and this is an image: foo", placeholder="ph.png")) + >>> _lazy_images("I'm a link and this is an image: foo", placeholder="ph.png") # doctest: +ALLOW_UNICODE 'I\\'m a link and this is an image: \\'foo\\'' - >>> to_native_str(_lazy_images("One and two and three and four \\"four\\"", placeholder="ph.png")) + >>> _lazy_images("One and two and three and four \\"four\\"", placeholder="ph.png") # doctest: +ALLOW_UNICODE 'One and two and three and four 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("Hello world<img src='foo.jpg'>")) + >>> _strip_tags("Hello world<img src='foo.jpg'>") # doctest: +ALLOW_UNICODE "Hello world<img src='foo.jpg'>" - >>> to_native_str(_strip_tags("> > Foo")) + >>> _strip_tags("> > Foo") # doctest: +ALLOW_UNICODE '> > Foo' """ try: diff --git a/src/octoprint/plugins/corewizard/subwizards.py b/src/octoprint/plugins/corewizard/subwizards.py index 97244ee39..0fee431c7 100644 --- a/src/octoprint/plugins/corewizard/subwizards.py +++ b/src/octoprint/plugins/corewizard/subwizards.py @@ -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()) diff --git a/src/octoprint/timelapse.py b/src/octoprint/timelapse.py index f551654c1..f9d89af98 100644 --- a/src/octoprint/timelapse.py +++ b/src/octoprint/timelapse.py @@ -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("-") diff --git a/src/octoprint/util/__init__.py b/src/octoprint/util/__init__.py index 72a98759c..3c8481ea8 100644 --- a/src/octoprint/util/__init__.py +++ b/src/octoprint/util/__init__.py @@ -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): diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index 8ca3e2eec..1f3748f1f 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -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 diff --git a/src/octoprint/util/commandline.py b/src/octoprint/util/commandline.py index 8a7f0c182..50027dd5d 100644 --- a/src/octoprint/util/commandline.py +++ b/src/octoprint/util/commandline.py @@ -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): diff --git a/src/octoprint/util/pip.py b/src/octoprint/util/pip.py index 07f18f9d8..e6d06a471 100644 --- a/src/octoprint/util/pip.py +++ b/src/octoprint/util/pip.py @@ -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)) diff --git a/tox.ini b/tox.ini index dbd0497c9..98d3b08fb 100644 --- a/tox.ini +++ b/tox.ini @@ -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