예제 #1
0
def test_html2jade():
    html_input = """
<html>
  <head></head>
  <body>
    <div>
      <p>This cost £££</p>
    </div>
  </body>
</html>""".strip()
    jade_expected = (
        """
!!!
html
  head
  body
    div
      p This cost £££""".strip()
        + "\n"
    )
    with path.create_temp_dir() as temp_dir:
        temp_html = temp_dir.child("test.html")
        temp_jade = temp_dir.child("test.jade")
        temp_html.write_text(html_input)
        with path.temp_sys_argv("python", temp_html):
            wiseguy.scripts.html2jade.main()
        assert temp_jade.text() == jade_expected
예제 #2
0
def test_create_temp_dir():
    with path.create_temp_dir() as temp_dir_name:
        for file_name in ['a', 'b', 'c']:
            len(temp_dir_name.files()) == 0
            temp_dir_name.child(file_name).touch()
        assert len(temp_dir_name.files()) == 3
    assert not temp_dir_name.exists()
예제 #3
0
def test_create_temp_dir():
    with path.create_temp_dir() as temp_dir_name:
        for file_name in ['a', 'b', 'c']:
            len(temp_dir_name.files()) == 0
            temp_dir_name.child(file_name).touch()
        assert len(temp_dir_name.files()) == 3
    assert not temp_dir_name.exists()
예제 #4
0
def test_JadeEnv():
    with path.create_temp_dir() as d:
        layout_content = """
html
  body
    block body
    div(class={{baz_var}})"""
        index_content = """
extends layout.jade

append body
  div: p: a.foo"""
        foo_content = """
extends layout.jade

append body
  div= foo_var
  div(class={{bar_var}})
"""
        flam_content = """div= wangle"""
        d.child('layout.jade').write_text(layout_content)
        d.child('index.jade').write_text(index_content)
        d.child('foo.jade').write_text(foo_content)
        d.child('flam.jade').write_text(flam_content)
        env = wu.JadeEnv(d, dict(bar_var="bibble", baz_var="baz"))

        html = env.render("index").strip()
        expected = '''
<html><body>
<div><p><a class="foo"></a></p></div>
<div class="baz"></div>
</body></html>'''.strip()
        assert expected == html

        response = env.get_response("foo", dict(foo_var="flibble"),
                                    "text/html")
        expected = '''
<html><body>
<div>flibble</div>
<div class="bibble"></div>
<div class="baz"></div>
</body></html>'''.strip()
        assert response.data.strip() == expected

        with raises(wu.TemplateNotFound):
            html = env.render("blooble").strip()

        env.update_globals(dict(wangle="wotsit"))
        html = env.render("flam", dict()).strip()
        assert html == "<div>wotsit</div>"
예제 #5
0
def test_JadeEnv():
    with path.create_temp_dir() as d:
        layout_content = """
html
  body
    block body
    div(class={{baz_var}})"""
        index_content = """
extends layout.jade

append body
  div: p: a.foo"""
        foo_content = """
extends layout.jade

append body
  div= foo_var
  div(class={{bar_var}})
"""
        flam_content = """div= wangle"""
        d.child('layout.jade').write_text(layout_content)
        d.child('index.jade').write_text(index_content)
        d.child('foo.jade').write_text(foo_content)
        d.child('flam.jade').write_text(flam_content)
        env = wu.JadeEnv(d, dict(bar_var="bibble", baz_var="baz"))

        html = env.render("index").strip()
        expected = '''
<html><body>
<div><p><a class="foo"></a></p></div>
<div class="baz"></div>
</body></html>'''.strip()
        assert expected == html

        response = env.get_response("foo", dict(foo_var="flibble"), "text/html")
        expected = '''
<html><body>
<div>flibble</div>
<div class="bibble"></div>
<div class="baz"></div>
</body></html>'''.strip()
        assert response.data.strip() == expected

        with raises(wu.TemplateNotFound):
            html = env.render("blooble").strip()

        env.update_globals(dict(wangle="wotsit"))
        html = env.render("flam", dict()).strip()
        assert html == "<div>wotsit</div>"
예제 #6
0
def test_parse_jade():
    jade_input = "html: body: div#main"
    html_expected = """
<!DOCTYPE html>
<html>
  <body>
    <div id="main"></div>
  </body>
</html>""".strip()
    with path.create_temp_dir() as temp_dir:
        temp_html = temp_dir.child("test.html")
        temp_jade = temp_dir.child("test.jade")
        temp_jade.write_text(jade_input)
        with path.temp_sys_argv("python", temp_jade):
            wiseguy.scripts.parse_jade.main()
        assert temp_html.text() == html_expected
예제 #7
0
def test_parse_jade():
    jade_input = "html: body: div#main"
    html_expected = '''
<!DOCTYPE html>
<html>
  <body>
    <div id="main"></div>
  </body>
</html>'''.strip()
    with path.create_temp_dir() as temp_dir:
        temp_html = temp_dir.child("test.html")
        temp_jade = temp_dir.child("test.jade")
        temp_jade.write_text(jade_input)
        with path.temp_sys_argv("python", temp_jade):
            wiseguy.scripts.parse_jade.main()
        assert temp_html.text() == html_expected
예제 #8
0
def test_CascadingEnv():
    with path.create_temp_dir() as d:
        d.child('bar3.jade').write_text("""div Jade Page\n  !=" "+foo_var""")

        env = wu.CascadingEnv(
            wu.LxmlEnv(
                utils.MockObject(
                    bar1=lambda context: wiseguy.html.jade(
                        "div Lxml Page %s"%context['foo_var']))),
            wu.JinjaEnv(
                j2.Environment(
                    loader=j2.DictLoader(
                        dict(
                            bar2="<div>Jinja Page {{foo_var}}</div>",
                            flam="<div>Flam Page {{wangle}}</div>")))),
            wu.JadeEnv(d, dict()))

        expected = "<div>Lxml Page flam</div>"
        result = env.render("bar1", dict(foo_var="flam")).strip()
        assert result == expected
        result = env.get_response("bar1", dict(foo_var="flam"))
        assert result.data.strip() == expected

        expected = "<div>Jinja Page flom</div>"
        result = env.render("bar2", dict(foo_var="flom")).strip()
        assert result == expected
        result = env.get_response("bar2", dict(foo_var="flom"), mimetype="blah")
        assert result.data.strip() == expected
        assert result.mimetype == "blah"

        expected = "<div>Jade Page flim</div>"
        result = env.render("bar3", dict(foo_var="flim")).strip()
        assert result == expected
        result = env.get_response("bar3", dict(foo_var="flim"))
        assert result.data.strip() == expected

        with raises(wu.TemplateNotFound):
            result = env.render("flib", dict())

        with raises(wu.TemplateNotFound):
            result = env.get_response("flib", dict())

        env.update_globals(dict(wangle="wotsit"))
        html = env.render("flam", dict()).strip()
        assert html == "<div>Flam Page wotsit</div>"
예제 #9
0
def test_CascadingEnv():
    with path.create_temp_dir() as d:
        d.child('bar3.jade').write_text("""div Jade Page\n  !=" "+foo_var""")

        env = wu.CascadingEnv(
            wu.LxmlEnv(
                utils.MockObject(bar1=lambda context: wiseguy.html.jade(
                    "div Lxml Page %s" % context['foo_var']))),
            wu.JinjaEnv(
                j2.Environment(loader=j2.DictLoader(
                    dict(bar2="<div>Jinja Page {{foo_var}}</div>",
                         flam="<div>Flam Page {{wangle}}</div>")))),
            wu.JadeEnv(d, dict()))

        expected = "<div>Lxml Page flam</div>"
        result = env.render("bar1", dict(foo_var="flam")).strip()
        assert result == expected
        result = env.get_response("bar1", dict(foo_var="flam"))
        assert result.data.strip() == expected

        expected = "<div>Jinja Page flom</div>"
        result = env.render("bar2", dict(foo_var="flom")).strip()
        assert result == expected
        result = env.get_response("bar2",
                                  dict(foo_var="flom"),
                                  mimetype="blah")
        assert result.data.strip() == expected
        assert result.mimetype == "blah"

        expected = "<div>Jade Page flim</div>"
        result = env.render("bar3", dict(foo_var="flim")).strip()
        assert result == expected
        result = env.get_response("bar3", dict(foo_var="flim"))
        assert result.data.strip() == expected

        with raises(wu.TemplateNotFound):
            result = env.render("flib", dict())

        with raises(wu.TemplateNotFound):
            result = env.get_response("flib", dict())

        env.update_globals(dict(wangle="wotsit"))
        html = env.render("flam", dict()).strip()
        assert html == "<div>Flam Page wotsit</div>"
예제 #10
0
def test_JadeEnv():
    with path.create_temp_dir() as d:
        layout_content = """
html
  body
    block body
    div(class={{baz_var}})"""
        index_content = """
extends layout.jade

append body
  div: p: a.foo"""
        foo_content = """
extends layout.jade

append body
  div= foo_var
  div(class={{bar_var}})
"""
        d.child('layout.jade').write_text(layout_content)
        d.child('index.jade').write_text(index_content)
        d.child('foo.jade').write_text(foo_content)
        env = wu.JadeEnv(d, dict(bar_var="bibble", baz_var="baz"))

        html = env.render("index").strip()
        expected = '''
<html><body>
<div><p><a class="foo"></a></p></div>
<div class="baz"></div>
</body></html>'''.strip()
        assert expected == html

        response = env.get_response("foo", dict(foo_var="flibble"), "text/html")
        expected = '''
<html><body>
<div>flibble</div>
<div class="bibble"></div>
<div class="baz"></div>
</body></html>'''.strip()
        assert response.data.strip() == expected
예제 #11
0
def test_html2jade():
    html_input = '''
<html>
  <head></head>
  <body>
    <div>
      <p>This cost £££</p>
    </div>
  </body>
</html>'''.strip()
    jade_expected = '''
!!!
html
  head
  body
    div
      p This cost £££'''.strip() + "\n"
    with path.create_temp_dir() as temp_dir:
        temp_html = temp_dir.child("test.html")
        temp_jade = temp_dir.child("test.jade")
        temp_html.write_text(html_input)
        with path.temp_sys_argv("python", temp_html):
            wiseguy.scripts.html2jade.main()
        assert temp_jade.text() == jade_expected