Fix the remaining docstr tests

Sets are annoying to test:
(a) their repr() is different
(b) they might get re-ordered.
This commit is contained in:
Matthias Urlichs committed 2019-02-04 14:15:09 +01:00
1 parent 40b231f692
commit e676d53e9f
2 files changed
+25 -17

No files matched your search

+9 -1
View File
@@ -41,10 +41,18 @@ def to_native_str(s_or_u):
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 s_or_u)+b'}'
else:
if isinstance(s_or_u, bytes):
return s_or_u.decode("utf-8") # only used for doctests
elif not isinstance(s_or_u, str):
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
+16 -16
View File
@@ -4587,32 +4587,32 @@ def _normalize_command_handler_result(command, command_type, gcode, subcode, tag
>>> 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)
>>> _normalize_command_handler_result("M105", None, "M105", None, None, None)
>>> u(_normalize_command_handler_result("M105", None, "M105", None, None, None))
[('M105', None, 'M105', None, None)]
>>> _normalize_command_handler_result("M105", None, "M105", None, None, "M110")
>>> u(_normalize_command_handler_result("M105", None, "M105", None, None, "M110"))
[('M110', None, 'M110', None, None)]
>>> _normalize_command_handler_result("M105", None, "M105", None, None, ["M110"])
>>> u(_normalize_command_handler_result("M105", None, "M105", None, None, ["M110"]))
[('M110', None, 'M110', None, None)]
>>> _normalize_command_handler_result("M105", None, "M105", None, None, ["M110", "M117 Foobar"])
>>> u(_normalize_command_handler_result("M105", None, "M105", None, None, ["M110", "M117 Foobar"]))
[('M110', None, 'M110', None, None), ('M117 Foobar', None, 'M117', None, None)]
>>> _normalize_command_handler_result("M105", None, "M105", None, None, [("M110",), "M117 Foobar"])
>>> u(_normalize_command_handler_result("M105", None, "M105", None, None, [("M110",), "M117 Foobar"]))
[('M110', None, 'M110', None, None), ('M117 Foobar', None, 'M117', None, None)]
>>> _normalize_command_handler_result("M105", None, "M105", None, None, [("M110", "lineno_reset"), "M117 Foobar"])
>>> u(_normalize_command_handler_result("M105", None, "M105", None, None, [("M110", "lineno_reset"), "M117 Foobar"]))
[('M110', 'lineno_reset', 'M110', None, None), ('M117 Foobar', None, 'M117', None, None)]
>>> _normalize_command_handler_result("M105", None, "M105", None, None, [])
>>> u(_normalize_command_handler_result("M105", None, "M105", None, None, []))
[]
>>> _normalize_command_handler_result("M105", None, "M105", None, None, ["M110", None])
>>> u(_normalize_command_handler_result("M105", None, "M105", None, None, ["M110", None]))
[('M110', None, 'M110', None, None)]
>>> _normalize_command_handler_result("M105", None, "M105", None, None, [("M110",), (None, "ignored")])
>>> u(_normalize_command_handler_result("M105", None, "M105", None, None, [("M110",), (None, "ignored")]))
[('M110', None, 'M110', None, None)]
>>> _normalize_command_handler_result("M105", None, "M105", None, None, [("M110",), ("M117 Foobar", "display_message"), ("tuple", "of", "unexpected", "length"), ("M110", "lineno_reset")])
>>> u(_normalize_command_handler_result("M105", None, "M105", None, None, [("M110",), ("M117 Foobar", "display_message"), ("tuple", "of", "unexpected", "length"), ("M110", "lineno_reset")]))
[('M110', None, 'M110', None, None), ('M117 Foobar', 'display_message', 'M117', None, None), ('M110', 'lineno_reset', 'M110', None, None)]
>>> _normalize_command_handler_result("M105", None, "M105", None, {"tag1", "tag2"}, ["M110", "M117 Foobar"])
[('M110', None, 'M110', None, set(['tag1', 'tag2'])), ('M117 Foobar', None, 'M117', None, set(['tag1', 'tag2']))]
>>> _normalize_command_handler_result("M105", None, "M105", None, {"tag1", "tag2"}, ["M110", "M105", "M117 Foobar"], tags_to_add={"tag3"})
[('M110', None, 'M110', None, set(['tag1', 'tag2', 'tag3'])), ('M105', None, 'M105', None, set(['tag1', 'tag2'])), ('M117 Foobar', None, 'M117', None, set(['tag1', 'tag2', 'tag3']))]
>>> _normalize_command_handler_result("M105", None, "M105", None, {"tag1", "tag2"}, ["M110", ("M105", "temperature_poll"), "M117 Foobar"], tags_to_add={"tag3"})
[('M110', None, 'M110', None, set(['tag1', 'tag2', 'tag3'])), ('M105', 'temperature_poll', 'M105', None, set(['tag1', 'tag2', 'tag3'])), ('M117 Foobar', None, 'M117', None, set(['tag1', 'tag2', 'tag3']))]
>>> 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'}")]
Arguments:
command (str or None): The command for which the handler result was