yelite commented on code in PR #11971:
URL: https://github.com/apache/tvm/pull/11971#discussion_r914900763


##########
tests/python/unittest/test_tvmscript_printer_python_doc_printer.py:
##########
@@ -0,0 +1,56 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+import pytest
+
+from tvm.script.printer.doc_printer import to_python_script
+from tvm.script.printer.doc import LiteralDoc
+
+
+def format_script(s: str) -> str:
+    """
+    Remove leading and trailing blank lines, and make the minimum idention 0
+    """
+    s = s.strip("\n")
+    non_empty_lines = [line for line in s.splitlines() if line and not 
line.isspace()]
+    line_indents = [len(line) - len(line.lstrip(" ")) for line in 
non_empty_lines]
+    spaces_to_remove = min(line_indents)
+    return "\n".join(line[spaces_to_remove:] for line in s.splitlines())
+
+
[email protected](
+    "doc,expected",
+    [
+        (LiteralDoc(None), "None"),
+        (LiteralDoc(True), "True"),
+        (LiteralDoc(False), "False"),
+        (LiteralDoc("test"), '"test"'),
+        (LiteralDoc(""), '""'),
+        (LiteralDoc('""'), r'"\"\""'),
+        (LiteralDoc("\n\t\\test\r"), r'"\n\t\\test\r"'),
+        # TODO: make the roundatrippable problem caused by utf8
+        pytest.param(LiteralDoc("\x88"), r'"\x88"', marks=pytest.mark.xfail),

Review Comment:
   There were three xfail tests here. I removed the latter two about float 
number per our discussion yesterday (we want to handle float number precise 
printing in the IRDocsifier). 
   
   This one (on line 45) is about the utf8 encoding. `LiteralDoc("\x88")` will 
print `'\xc2\x88'` (the utf8 encoded bytes for "\x88"). This is not 
roundtrippable.
   
   To fix this, we need to either:
   1. Add utf8 decoding to StrEscape
   2. Output in the form of `b'\xC2\x88'.encode()'`
   
   I don't think unicode support is important to our use case and it doesn't 
help us reach feature parity with the old printer at all. So I don't want to 
solve it for now, but just leave an xfail test as a note



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to