Example #1
0
def test_nesting():
    assert matches(H.div(H.div(H.b("inner"))),
                   "<div><div><b>inner</b></div></div>")
    assert matches(H.div(H.b("hello"), H.i("there")),
                   "<div><b>hello</b><i>there</i></div>")
    assert matches(
        H.div([[[H.b("hello"), [H.i("there")]]]]),
        "<div><b>hello</b><i>there</i></div>",
    )
Example #2
0
def test_trepr():
    assert pstr([1, 2, "hello"]) == "[1, 2, 'hello']"
    assert pstr({"a": 1, "b": 2}) == "{'a': 1, 'b': 2}"
    assert pstr(Point(1, 2)) == "Point(x=1, y=2)"
    assert (
        pstr(H.span["kls"](H.b("great"), "canyon"))
        == '<span class="kls"><b>great</b>canyon</span>'
    )
Example #3
0
def test_as_page_with_resources():
    sty = H.style("b { color: red; }")
    scr = H.script("x = 1234;")
    resources = (sty, scr)
    inner = H.b("resources").fill(resources=scr)
    tag = H.div("with ", inner).fill(resources=sty)
    utf8 = H.meta({"http-equiv": "Content-type"},
                  content="text/html",
                  charset="UTF-8")
    page = H.inline(
        H.raw("<!DOCTYPE html>"),
        H.html(H.head(utf8, *resources), H.body(tag)),
    )
    assert tag.as_page() == page
Example #4
0
def test_incremental():
    d0 = H.div()
    assert matches(d0, "<div></div>")

    d = d0("crumpet")
    assert matches(d0, "<div></div>")
    assert matches(d, "<div>crumpet</div>")

    d = d(H.b("tea"))
    assert matches(d, "<div>crumpet<b>tea</b></div>")

    d = d(id="paramount")
    assert matches(d, '<div id="paramount">crumpet<b>tea</b></div>')

    d = d({"sheep": "bah"}, quack=True)
    assert matches(
        d, '<div id="paramount" sheep="bah" quack>crumpet<b>tea</b></div>')

    d = d(quack=False)
    assert matches(d,
                   '<div id="paramount" sheep="bah" >crumpet<b>tea</b></div>')
Example #5
0
def test_config():
    assert hrepr(Katana()) == H.b("n/a")
    assert hrepr(Katana(), katana=1234) == H.b(1234)
    assert hrepr(KatanaWrapper(Katana(), 9000)) == H.b(9000)
Example #6
0
 def __hrepr__(self, H, hrepr):
     return H.b(hrepr.config.katana or "n/a")
Example #7
0
def test_inline():
    assert matches(H.inline("thing"), "thing")
    assert matches(H.inline("<b>hello</b>"), "&lt;b&gt;hello&lt;/b&gt;")
    assert matches(H.inline(H.b("hello"), H.i("there")),
                   "<b>hello</b><i>there</i>")
Example #8
0
def test_raw():
    assert matches(H.raw("thing"), "thing")
    assert matches(H.raw("<b>hello</b>"), "<b>hello</b>")
    assert matches(H.raw(H.b("hello"), H.i("there")),
                   "<b>hello</b><i>there</i>")
    assert matches(H.raw(H.b("<inner>")), "<b>&lt;inner&gt;</b>")
Example #9
0
def test_misc():
    assert matches(H.whimsy("cal"), "<whimsy>cal</whimsy>")
    assert H.div(H.b("hello")) == H.div(H.b("hello"))
    assert H.div(H.b("hello")) != H.div(H.i("hello"))
    assert isinstance(hash(H.div(H.div("yay!"))), int)
    assert repr(H.div("soupe")) == str(H.div("soupe"))
Example #10
0
def test_tag():
    tg = H.span["hello"](1, 2, H.b("there"))
    assert hrepr(tg) == tg