Next / Previous / Contents / Shipman's homepage

14.13. testetbuilder: A test driver for etbuilder

Here is a small script that exercises the etbuilder module.

This script generates a small XHTML page that looks like this:

    <title>Sample page<title>
    <link href="/tcc/style.css" rel="stylesheet"/>
    <h1 class='big-title'>Sample page title</h1>
    <p>A paragraph containing a <a href=''
    >link to the NMT homepage</a>.</p>

The script follows.

#!/usr/bin/env python
from __future__ import print_function
from etbuilder import E, et, CLASS

page = E.html(
      E.title("Sample page"),'/tcc/style.css', rel='stylesheet')),
      E.h1(CLASS('big-title'), "Sample page title"),
      E.p("A paragraph containing ", 1, " ",
        E.a("link to the NMT homepage",
print(et.tostring(page, pretty_print=True, encoding=unicode), end='')