mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-19 18:27:29 -05:00
display() should escape by default (#915)
- display(some_str) escapes the string by default. This is almost always what you want
- display(some_obj) calls repr(obj) and escapes the result. Again, it's a very sensible default
- if you want to inject some raw HTML in the output, you can use the new HTML class: display(HTML("<p>hello</p>")).
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import sys
|
||||
from unittest.mock import Mock
|
||||
|
||||
import pyscript
|
||||
@@ -24,7 +25,26 @@ class TestElement:
|
||||
|
||||
def test_format_mime_str():
|
||||
obj = "just a string"
|
||||
out, mime = pyscript.format_mime(obj)
|
||||
assert out == obj
|
||||
assert mime == "text/plain"
|
||||
|
||||
res = pyscript.format_mime(obj)
|
||||
assert res[0] == obj
|
||||
assert res[1] == "text/plain"
|
||||
|
||||
def test_format_mime_str_escaping():
|
||||
obj = "<p>hello</p>"
|
||||
out, mime = pyscript.format_mime(obj)
|
||||
assert out == "<p>hello</p>"
|
||||
assert mime == "text/plain"
|
||||
|
||||
|
||||
def test_format_mime_repr_escaping():
|
||||
out, mime = pyscript.format_mime(sys)
|
||||
assert out == "<module 'sys' (built-in)>"
|
||||
assert mime == "text/plain"
|
||||
|
||||
|
||||
def test_format_mime_HTML():
|
||||
obj = pyscript.HTML("<p>hello</p>")
|
||||
out, mime = pyscript.format_mime(obj)
|
||||
assert out == "<p>hello</p>"
|
||||
assert mime == "text/html"
|
||||
|
||||
Reference in New Issue
Block a user