def test_attrupdate():
	node = html.a(href="gurk", class_="hurz")
	node.attrs.update(xml.Attrs(lang="de"), {"href": "gurk2", html.a.Attrs.id: 42})
	assert str(node["href"]) == "gurk2"
	assert str(node["id"]) == "42"
	assert str(node[xml.Attrs.lang]) == "de"

	node = html.a({xml.Attrs.lang: "de"}, href="gurk", class_="hurz")
	assert str(node[xml.Attrs.lang]) == "de"

	node = html.a(xml.Attrs(lang="de"), href="gurk", class_="hurz")
	assert str(node[xml.Attrs.lang]) == "de"

	class Gurk(xsc.Element):
		model = False
		class Attrs(xsc.Element.Attrs):
			class gurk(xsc.TextAttr): pass
			class hurz(xsc.TextAttr): default = "hinz+kunz"

	node1 = Gurk()
	node2 = Gurk(hurz=None)
	node1.attrs.update(node2.attrs)
	assert "hurz" not in node1.attrs

	node1 = Gurk(hurz=None)
	node2 = Gurk()
	node1.attrs.update(node2.attrs)
	assert "hurz" in node1.attrs

	node = Gurk(Gurk(hurz=None).attrs)
	assert "hurz" not in node.attrs

	attrs = Gurk.Attrs(Gurk.Attrs(hurz=None))
	assert "hurz" not in attrs
	def convert(self, converter):
		e = xsc.Frag(
			xml.XML(), "\n",
			html.DocTypeXHTML10transitional(), "\n",
			html.html(
				html.head(
					meta.contenttype(),
					html.title(
						"Python code coverage",
						ul4.if_("filename"),
							": ", ul4.printx("filename"),
						ul4.else_(),
							" (", ul4.print_("format(timestamp, '%Y-%m-%d')"), ")",
						ul4.end("if"),
					),
					meta.stylesheet(href="/coverage.css"),
					meta.stylesheet(href="/coverage_sortfilelist.css"),
					htmlspecials.javascript(src="/coverage.js"),
				),
				html.body(
					html.div(
						html.div(
							html.a(
								htmlspecials.autoimg(src="http://www.python.org/images/python-logo.gif", alt="Python", border=0),
								href="http://www.python.org/",
							),
							class_="logo",
						),
						html.div(
							ul4.for_("(i, item) in enumerate(crumbs)"),
								html.span(
									html.span(
										ul4.if_("i"),
											">",
										ul4.else_(),
											"\xbb",
										ul4.end("if"),
										class_="bullet",
									),
									ul4.if_("item.href"),
										html.a(ul4.printx("item.title"), href=ul4.printx("item.href")),
									ul4.else_(),
										html.span(ul4.printx("item.title"), class_="here"),
									ul4.end("if"),
								ul4.end("for"),
								class_="crumb",
							),
							class_="crumbs",
						),
						class_="header",
					),
					html.div(
						self.content,
						class_="content",
					),
					onload=ul4.attr_if(ul4.printx("onload"), cond="onload"),
				),
			),
		)
		return e.convert(converter)
def test_allowschemerelurls():
    node = html.a(href="http://www.example.org/index.html")
    assert node.bytes() == b'<a href="http://www.example.org/index.html"></a>'
    assert node.bytes(
        base="http://www.example.org") == b'<a href="index.html"></a>'
    assert node.bytes(base="http://www.example.com"
                      ) == b'<a href="http://www.example.org/index.html"></a>'
    assert node.bytes(base="http://www.example.com", allowschemerelurls=True
                      ) == b'<a href="//www.example.org/index.html"></a>'

    node = specials.url("http://www.example.org/index.html")
    assert node.bytes() == b'http://www.example.org/index.html'
    assert node.bytes(base="http://www.example.org") == b'index.html'
    assert node.bytes(
        base="http://www.example.com") == b'http://www.example.org/index.html'
    assert node.bytes(
        base="http://www.example.com",
        allowschemerelurls=True) == b'//www.example.org/index.html'

    node = html.span(
        style="background: url(http://www.example.org/index.html)")
    assert node.bytes(
    ) == b'<span style="background: url(http://www.example.org/index.html)"></span>'
    assert node.bytes(base="http://www.example.org"
                      ) == b'<span style="background: url(index.html)"></span>'
    assert node.bytes(
        base="http://www.example.com"
    ) == b'<span style="background: url(http://www.example.org/index.html)"></span>'
    assert node.bytes(
        base="http://www.example.com", allowschemerelurls=True
    ) == b'<span style="background: url(//www.example.org/index.html)"></span>'
Esempio n. 4
0
def test_delitem():
    for cls in (xsc.Frag, html.div):
        e = cls(list(range(6)))
        del e[0]
        assert e == cls(1, 2, 3, 4, 5)
        del e[-1]
        assert e == cls(1, 2, 3, 4)

        e = cls(list(range(6)))
        del e[1:5]
        assert e == cls(0, 5)

        e = cls(list(range(6)))
        del e[2:]
        assert e == cls(0, 1)

        e = cls(list(range(6)))
        del e[-2:]
        assert e == cls(0, 1, 2, 3)

        e = cls(list(range(6)))
        del e[:2]
        assert e == cls(2, 3, 4, 5)

        e = cls(list(range(6)))
        del e[:-2]
        assert e == cls(4, 5)

        e = cls(list(range(6)))
        del e[:]
        assert e == cls()

        e = cls(list(range(6)))
        del e[::2]
        assert e == cls(1, 3, 5)

        e = cls(list(range(6)))
        del e[1::2]
        assert e == cls(0, 2, 4)

        e = cls(list(range(6)))
        del e[lambda p: int(str(p[-1])) % 2]
        assert e == cls(0, 2, 4)

        e = cls(html.b(i) if i % 2 else html.a(i) for i in range(6))
        del e[html.b]
        assert e == cls(html.a(0), html.a(2), html.a(4))
def test_delitem():
	for cls in (xsc.Frag, html.div):
		e = cls(range(6))
		del e[0]
		assert e == cls(1, 2, 3, 4, 5)
		del e[-1]
		assert e == cls(1, 2, 3, 4)

		e = cls(range(6))
		del e[1:5]
		assert e == cls(0, 5)

		e = cls(range(6))
		del e[2:]
		assert e == cls(0, 1)

		e = cls(range(6))
		del e[-2:]
		assert e == cls(0, 1, 2, 3)

		e = cls(range(6))
		del e[:2]
		assert e == cls(2, 3, 4, 5)

		e = cls(range(6))
		del e[:-2]
		assert e == cls(4, 5)

		e = cls(range(6))
		del e[:]
		assert e == cls()

		e = cls(range(6))
		del e[::2]
		assert e == cls(1, 3, 5)

		e = cls(range(6))
		del e[1::2]
		assert e == cls(0, 2, 4)

		e = cls(range(6))
		del e[lambda p:int(str(p[-1])) % 2]
		assert e == cls(0, 2, 4)

		e = cls(html.b(i) if i%2 else html.a(i) for i in range(6))
		del e[html.b]
		assert e == cls(html.a(0), html.a(2), html.a(4))
Esempio n. 6
0
def test_attrupdate():
    node = html.a(href="gurk", class_="hurz")
    node.attrs.update(xml.Attrs(lang="de"), {
        "href": "gurk2",
        html.a.Attrs.id: 42
    })
    assert str(node["href"]) == "gurk2"
    assert str(node["id"]) == "42"
    assert str(node[xml.Attrs.lang]) == "de"

    node = html.a({xml.Attrs.lang: "de"}, href="gurk", class_="hurz")
    assert str(node[xml.Attrs.lang]) == "de"

    node = html.a(xml.Attrs(lang="de"), href="gurk", class_="hurz")
    assert str(node[xml.Attrs.lang]) == "de"

    class Gurk(xsc.Element):
        model = False

        class Attrs(xsc.Element.Attrs):
            class gurk(xsc.TextAttr):
                pass

            class hurz(xsc.TextAttr):
                default = "hinz+kunz"

    node1 = Gurk()
    node2 = Gurk(hurz=None)
    node1.attrs.update(node2.attrs)
    assert "hurz" not in node1.attrs

    node1 = Gurk(hurz=None)
    node2 = Gurk()
    node1.attrs.update(node2.attrs)
    assert "hurz" in node1.attrs

    node = Gurk(Gurk(hurz=None).attrs)
    assert "hurz" not in node.attrs

    attrs = Gurk.Attrs(Gurk.Attrs(hurz=None))
    assert "hurz" not in attrs
def test_nsparse():
    # A prepopulated prefix mapping and xmlns attributes should work together
    xml = b"""
		<x:a>
			<x:a xmlns:x='http://www.w3.org/1999/xhtml'>
				<x:a xmlns:x='http://xmlns.livinglogic.de/xist/ns/doc'>gurk</x:a>
			</x:a>
		</x:a>
	"""
    check = doc.a(html.a(doc.a("gurk")))
    node = parse.tree(xml,
                      parse.Expat(),
                      parse.NS(x=doc),
                      parse.Node(),
                      validate=True)
    node = node.walknodes(
        xsc.Element)[0].compacted()  # get rid of the Frag and whitespace
    assert node == check
def test_allowschemerelurls():
	node = html.a(href="http://www.example.org/index.html")
	assert node.bytes() == b'<a href="http://www.example.org/index.html"></a>'
	assert node.bytes(base="http://www.example.org") == b'<a href="index.html"></a>'
	assert node.bytes(base="http://www.example.com") == b'<a href="http://www.example.org/index.html"></a>'
	assert node.bytes(base="http://www.example.com", allowschemerelurls=True) == b'<a href="//www.example.org/index.html"></a>'

	node = specials.url("http://www.example.org/index.html")
	assert node.bytes() == b'http://www.example.org/index.html'
	assert node.bytes(base="http://www.example.org") == b'index.html'
	assert node.bytes(base="http://www.example.com") == b'http://www.example.org/index.html'
	assert node.bytes(base="http://www.example.com", allowschemerelurls=True) == b'//www.example.org/index.html'

	node = html.span(style="background: url(http://www.example.org/index.html)")
	assert node.bytes() == b'<span style="background: url(http://www.example.org/index.html)"></span>'
	assert node.bytes(base="http://www.example.org") == b'<span style="background: url(index.html)"></span>'
	assert node.bytes(base="http://www.example.com") == b'<span style="background: url(http://www.example.org/index.html)"></span>'
	assert node.bytes(base="http://www.example.com", allowschemerelurls=True) == b'<span style="background: url(//www.example.org/index.html)"></span>'
def test_nsparse():
	# A prepopulated prefix mapping and xmlns attributes should work together
	xml = b"""
		<x:a>
			<x:a xmlns:x='http://www.w3.org/1999/xhtml'>
				<x:a xmlns:x='http://xmlns.livinglogic.de/xist/ns/doc'>gurk</x:a>
			</x:a>
		</x:a>
	"""
	check = doc.a(
		html.a(
			doc.a(
				"gurk"
			)
		)
	)
	node = parse.tree(xml, parse.Expat(), parse.NS(x=doc), parse.Node(), validate=True)
	node = node.walknodes(xsc.Element)[0].compacted() # get rid of the Frag and whitespace
	assert node == check
Esempio n. 10
0
 def convert(self, converter):
     attrs = self.attrs.clone()
     attrs["href"].insert(0, "foo")
     e = html.a(self.content, attrs)
     return e.convert(converter)
Esempio n. 11
0
def test_fancyurl():
	node = html.a("gurk", href=("http://", jsp.expression("server")))
	assert node.bytes(base="root:about/us.html") == b'<a href="http://<%= server %>">gurk</a>'
		def convert(self, converter):
			attrs = self.attrs.clone()
			attrs["href"].insert(0, "foo")
			e = html.a(self.content, attrs)
			return e.convert(converter)
	def convert(self, converter):
		e = xsc.Frag(
			html.h1("Python code coverage"),
			html.p("Generated at ", ul4.printx("format(now, '%Y-%m-%d %H:%M:%S')"), class_="note"),
			html.p("Last commit at ", ul4.printx("format(timestamp, '%Y-%m-%d %H:%M:%S')"), " by ", ul4.printx("author"), class_="note"),
			html.p("Changeset identification hash ", ul4.printx("changesetid"), class_="note"),
			html.p("Local revision number ", ul4.printx("revision"), class_="note"),
			html.p(html.a("Build log", href="buildlog.txt"), " ",html.a("Test log", href="testlog.txt"), class_="note"),
			htmlspecials.plaintable(
				html.thead(
					html.tr(
						html.th("Filename", id="filename"),
						html.th("# lines", id="nroflines"),
						html.th("# coverable lines", id="coverablelines"),
						html.th("# covered lines", id="coveredlines"),
						html.th("coverage", id="coverage"),
						html.th("distribution", id="distibution"),
					),
				),
				html.tbody(
					ul4.for_("file in files"),
						html.tr(
							html.th(
								html.a(
									ul4.printx("file.name"),
									href=(ul4.printx("file.name"), ".html"),
								),
								class_="filename",
							),
							html.td(
								ul4.printx("file.lines"),
								class_="nroflines",
							),
							html.td(
								ul4.printx("file.coverablelines"),
								class_="coverablelines",
							),
							html.td(
								ul4.printx("file.coveredlines"),
								class_="coveredlines",
							),
							html.td(
								ul4.if_("file.coverablelines"),
									ul4.printx("format((100.*file.coveredlines)/file.coverablelines, '.2f')"),
									"%",
								ul4.else_(),
									"n/a",
								ul4.end("if"),
								class_=(
									"coverage",
									ul4.if_("not file.coverablelines"),
										" disabled",
									ul4.end("if"),
								),
							),
							html.td(
								ul4.code("totalwidth = 100"),
								ul4.if_("file.coverablelines"),
									ul4.if_("file.coverablelines < file.lines"),
										ul4.code("width = int(1.*(file.lines-file.coverablelines)/file.lines*100)"),
										htmlspecials.pixel(src="/spc.gif", width=ul4.printx("width"), height=8, style="background-color: #ccc;"),
										ul4.code("totalwidth -= width"),
									ul4.end("if"),
									ul4.if_("file.coveredlines < file.coverablelines"),
										ul4.code("width = int(1.*(file.coverablelines-file.coveredlines)/file.lines*100)"),
										htmlspecials.pixel(src="/spc.gif", width=ul4.printx("width"), height=8, style="background-color: #f00;"),
										ul4.code("totalwidth -= width"),
									ul4.end("if"),
									ul4.if_("totalwidth"),
										htmlspecials.pixel(src="/spc.gif", width=ul4.printx("totalwidth"), height=8, style="background-color: #0c0;"),
									ul4.end("if"),
								ul4.else_(),
									htmlspecials.pixel(src="/spc.gif", width=ul4.printx("totalwidth"), height=8, style="background-color: #000;"),
								ul4.end("if"),
								class_="dist",
							),
							class_="files",
						),
					ul4.end("for"),
					id="files",
				),
				class_="files",
			)
		)
		return e.convert(converter)