Remove use of utest.py module from test_ptl, use py.test.
This commit is contained in:
parent
d955d01d2f
commit
079b9b11d3
|
@ -1,5 +1,4 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
from quixote.test.utest import UTest
|
|
||||||
from quixote.ptl.ptl_compile import compile_template
|
from quixote.ptl.ptl_compile import compile_template
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
from quixote.html import TemplateIO, htmltext, _q_join, _q_format
|
from quixote.html import TemplateIO, htmltext, _q_join, _q_format
|
||||||
|
@ -24,73 +23,69 @@ def run_ptl(*source):
|
||||||
dict(_q_TemplateIO=TemplateIO, _q_htmltext=htmltext,
|
dict(_q_TemplateIO=TemplateIO, _q_htmltext=htmltext,
|
||||||
_q_join=_q_join, _q_format=_q_format))
|
_q_join=_q_join, _q_format=_q_format))
|
||||||
|
|
||||||
class Test (UTest):
|
def test_html():
|
||||||
|
run_ptl(
|
||||||
|
'from ptl import htmltext',
|
||||||
|
'def f [html] (a):',
|
||||||
|
' "&"',
|
||||||
|
' a',
|
||||||
|
'assert type(f(1)) == htmltext',
|
||||||
|
'assert f("") == "&"',
|
||||||
|
'assert f("&") == "&&"',
|
||||||
|
'assert f(htmltext("&")) == "&&"')
|
||||||
|
|
||||||
def check_html(self):
|
def test_plain():
|
||||||
|
run_ptl(
|
||||||
|
'from ptl import htmltext',
|
||||||
|
'def f [plain] (a):',
|
||||||
|
' "&"',
|
||||||
|
' a',
|
||||||
|
'assert type(f(1)) == str',
|
||||||
|
'assert f("") == "&"',
|
||||||
|
'assert f("&") == "&&"',
|
||||||
|
'assert f(htmltext("&")) == "&&"',
|
||||||
|
'assert type(f(htmltext("&"))) == str')
|
||||||
|
|
||||||
|
def test_syntax():
|
||||||
|
run_ptl('def f(a):\n a')
|
||||||
|
try:
|
||||||
|
run_ptl('def f [] (a):\n a')
|
||||||
|
assert 0
|
||||||
|
except SyntaxError as e:
|
||||||
|
assert e.lineno == 1
|
||||||
|
try:
|
||||||
|
run_ptl('def f [HTML] (a):\n a')
|
||||||
|
assert 0
|
||||||
|
except SyntaxError as e:
|
||||||
|
assert e.lineno == 1
|
||||||
|
|
||||||
|
|
||||||
|
if HAVE_FSTRINGS:
|
||||||
|
def test_fstring():
|
||||||
run_ptl(
|
run_ptl(
|
||||||
'from quixote.html import htmltext',
|
'from ptl import htmltext',
|
||||||
'def f [html] (a):',
|
'def f [html] (a):',
|
||||||
' "&"',
|
' f"x{a}"',
|
||||||
' a',
|
|
||||||
'assert type(f(1)) == htmltext',
|
'assert type(f(1)) == htmltext',
|
||||||
'assert f("") == "&"',
|
'assert f("&") == "x&"',
|
||||||
'assert f("&") == "&&"',
|
'assert f(htmltext("&")) == "x&"')
|
||||||
'assert f(htmltext("&")) == "&&"')
|
|
||||||
|
|
||||||
def check_plain(self):
|
def test_q_join():
|
||||||
run_ptl(
|
assert _q_join('x', '&') == 'x&'
|
||||||
'from quixote.html import htmltext',
|
assert _q_join('x', htmltext('&')) == 'x&'
|
||||||
'def f [plain] (a):',
|
|
||||||
' "&"',
|
|
||||||
' a',
|
|
||||||
'assert type(f(1)) == str',
|
|
||||||
'assert f("") == "&"',
|
|
||||||
'assert f("&") == "&&"',
|
|
||||||
'assert f(htmltext("&")) == "&&"',
|
|
||||||
'assert type(f(htmltext("&"))) == str')
|
|
||||||
|
|
||||||
def check_syntax(self):
|
def test_q_format():
|
||||||
run_ptl('def f(a):\n a')
|
assert _q_format('&') == '&'
|
||||||
try:
|
assert _q_format(htmltext('&')) == '&'
|
||||||
run_ptl('def f [] (a):\n a')
|
assert _q_format('a', ord('r')) == "'a'"
|
||||||
assert 0
|
assert _q_format('\xff', ord('r')) == "'\xff'"
|
||||||
except SyntaxError as e:
|
assert _q_format('\xff', ord('a')) == "'\\xff'"
|
||||||
assert e.lineno == 1
|
assert _q_format(1, -1, '_>2') == '_1'
|
||||||
try:
|
assert _q_format(1, -1, '_>2') == '_1'
|
||||||
run_ptl('def f [HTML] (a):\n a')
|
assert _q_format(64, -1, 'c') == '@'
|
||||||
assert 0
|
assert _q_format(38, -1, 'c') == '&'
|
||||||
except SyntaxError as e:
|
|
||||||
assert e.lineno == 1
|
|
||||||
|
|
||||||
|
|
||||||
if HAVE_FSTRINGS:
|
|
||||||
def check_fstring(self):
|
|
||||||
run_ptl(
|
|
||||||
'from quixote.html import htmltext',
|
|
||||||
'def f [html] (a):',
|
|
||||||
' f"x{a}"',
|
|
||||||
'assert type(f(1)) == htmltext',
|
|
||||||
'assert f("&") == "x&"',
|
|
||||||
'assert f(htmltext("&")) == "x&"')
|
|
||||||
|
|
||||||
def check_q_join(self):
|
|
||||||
assert _q_join('x', '&') == 'x&'
|
|
||||||
assert _q_join('x', htmltext('&')) == 'x&'
|
|
||||||
|
|
||||||
def check_q_format(self):
|
|
||||||
assert _q_format('&') == '&'
|
|
||||||
assert _q_format(htmltext('&')) == '&'
|
|
||||||
assert _q_format('a', ord('r')) == "'a'"
|
|
||||||
assert _q_format('\xff', ord('r')) == "'\xff'"
|
|
||||||
assert _q_format('\xff', ord('a')) == "'\\xff'"
|
|
||||||
assert _q_format(1, -1, '_>2') == '_1'
|
|
||||||
assert _q_format(1, -1, '_>2') == '_1'
|
|
||||||
assert _q_format(64, -1, 'c') == '@'
|
|
||||||
assert _q_format(38, -1, 'c') == '&'
|
|
||||||
|
|
||||||
|
|
||||||
def test_all():
|
|
||||||
Test()
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test_all()
|
import pytest
|
||||||
|
pytest.main([__file__])
|
||||||
|
|
Loading…
Reference in New Issue