From: Matthew Fernandez Date: Tue, 8 Feb 2022 04:15:27 +0000 (+1100) Subject: fix 'dot' test helper failing to encode string input X-Git-Tag: 3.0.0~35^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0f12eac348eeff0e8c9b7379ebaee2b65a2b840a;p=graphviz fix 'dot' test helper failing to encode string input When asking the `dot` helper function to process a graph from inline input to a binary output format, the `universal_newlines=True` parameter would not be passed to the underlying `subprocess.check_output` call, resulting in failure to encode the input. That is, something like the following: dot("png:gd", source="digraph { a -> b; }") would result in: self = def _communicate(self, input, endtime, orig_timeout): … > input_view = memoryview(self._input) E TypeError: memoryview: a bytes-like object is required, not 'str' /usr/lib64/python3.6/subprocess.py:1519: TypeError Note that this problem was latent, as no usage fitting the above scenario currently exists. Something like this will be introduced in a future commit. Gitlab: related to #1786 --- diff --git a/rtest/gvtest.py b/rtest/gvtest.py index 390ae6b14..4bae0fea3 100644 --- a/rtest/gvtest.py +++ b/rtest/gvtest.py @@ -81,14 +81,18 @@ def dot(T: str, source_file: Optional[Path] = None, source: Optional[str] = None "one of `source_file` or `source` needs to be provided" # is the output format a textual format? + output_is_text = T in ("cmapx", "json", "pic", "svg", "xdot") + kwargs = {} - if T in ("cmapx", "json", "pic", "svg", "xdot"): + if output_is_text: kwargs["universal_newlines"] = True args = ["dot", f"-T{T}"] if source_file is not None: args += [source_file] + elif not output_is_text: + kwargs["input"] = source.encode("utf-8") else: kwargs["input"] = source