def sqlservercode():
    return xsc.Frag(
        toxic.args("@search varchar(100)"), toxic.vars("declare @i integer;"),
        htmlspecials.plaintable(
            toxic.code("""
				set @i = 1;

				declare @row_name varchar(100);
				declare person_cursor cursor for
					select name from person where name like @search

				open person_cursor

				while 1 = 1
				begin
					fetch next from person_cursor into @row_name;
					if (@@fetch_status != 0)
						break

					"""),
            html.tr(html.th(toxic.expr("@i"), align="right"),
                    html.td(toxic.expr("schema.xmlescape(@row_name)"))),
            toxic.code("""
					set @i = @i+1;
				end

				close person_cursor
				deallocate person_cursor
			""")))
def sqlservercode():
	return xsc.Frag(
		toxic.args("@search varchar(100)"),
		toxic.vars("declare @i integer;"),
		htmlspecials.plaintable(
			toxic.code("""
				set @i = 1;

				declare @row_name varchar(100);
				declare person_cursor cursor for
					select name from person where name like @search

				open person_cursor

				while 1 = 1
				begin
					fetch next from person_cursor into @row_name;
					if (@@fetch_status != 0)
						break

					"""),
					html.tr(
						html.th(toxic.expr("@i"), align="right"),
						html.td(toxic.expr("schema.xmlescape(@row_name)"))
					),
					toxic.code("""
					set @i = @i+1;
				end

				close person_cursor
				deallocate person_cursor
			""")
		)
	)
def test_publishboolattr():
    node = html.td("?", nowrap=None)
    assert node.bytes(xhtml=0) == b"""<td>?</td>"""

    node = html.td("?", nowrap=True)
    assert node.bytes(xhtml=0) == b"""<td nowrap>?</td>"""
    assert node.bytes(xhtml=1) == b"""<td nowrap="nowrap">?</td>"""
    assert node.bytes(xhtml=2) == b"""<td nowrap="nowrap">?</td>"""

    class foo(xsc.Element):
        class Attrs(xsc.Element.Attrs):
            class bar(xsc.BoolAttr):
                xmlname = "baz"

    # Check that the XML name is used as the value
    assert foo("?", bar=True).bytes(xhtml=2) == b"""<foo baz="baz">?</foo>"""
def test_publishboolattr():
	node = html.td("?", nowrap=None)
	assert node.bytes(xhtml=0) == b"""<td>?</td>"""

	node = html.td("?", nowrap=True)
	assert node.bytes(xhtml=0) == b"""<td nowrap>?</td>"""
	assert node.bytes(xhtml=1) == b"""<td nowrap="nowrap">?</td>"""
	assert node.bytes(xhtml=2) == b"""<td nowrap="nowrap">?</td>"""

	class foo(xsc.Element):
		class Attrs(xsc.Element.Attrs):
			class bar(xsc.BoolAttr):
				xmlname = "baz"

	# Check that the XML name is used as the value
	assert foo("?", bar=True).bytes(xhtml=2) == b"""<foo baz="baz">?</foo>"""
	def index(self):
		def isimg(name):
			if name.endswith(".gif") or name.endswith(".jpg") or name.endswith(".png"):
				return os.path.isfile(os.path.join(self.directory, name))
			return False

		names = [name for name in os.listdir(self.directory) if isimg(name)]
		names.sort()

		collect = xsc.Frag()
		i = 0

		with xsc.build():
			with xsc.Frag() as e:
				+xml.XML()
				+html.DocTypeXHTML10transitional()
				with html.html():
					with html.head():
						+meta.contenttype()
						+html.title("All images from ", doc.z(self.directory))
						+html.link(rel="stylesheet", type="text/css", href="images.css")
					with html.body():
						with htmlspecials.plaintable():
							for name in names:
								collect.append(html.td(htmlspecials.autoimg(src=("/images/", name)), html.br(), name, align="center"))
								i += 1
								if i == cols:
									+html.tr(collect)
									collect = xsc.Frag()
									i = 0
							if collect:
								+html.tr(collect)

		return e.conv().bytes()
	def convert(self, converter):
		e = xsc.Frag(
			html.h1("Python code coverage for ", ul4.printx("filename")),
			htmlspecials.plaintable(
				html.thead(
					html.tr(
						html.th("#"),
						html.th("count"),
						html.th("content"),
					),
				),
				html.tbody(
					ul4.for_("(i, line) in enumerate(lines)"),
						html.tr(
							html.th(ul4.print_("i+1")),
							html.td(
								ul4.if_("not isnone(line.count) and line.count >= 0"),
									ul4.printx("line.count"),
								ul4.else_(),
									"n/a",
								ul4.end("if"),
								class_="count",
							),
							html.td(ul4.printx("line.content"), class_="line"),
							class_=ul4.attr_if(
								ul4.if_("isnone(line.count) or line.count < 0"),
									"uncoverable",
								ul4.elif_("not line.count"),
									"uncovered",
								ul4.end("if"),
								cond="isnone(line.count) or line.count <= 0",
							),
						),
					ul4.end("for"),
				),
				class_="file",
			)
		)
		return e.convert(converter)
def oraclecode():
    return xsc.Frag(
        toxic.args("search in varchar2"), toxic.vars("i integer;"),
        htmlspecials.plaintable(
            toxic.code("""
				i := 1;
				for row in (select name from person where name like search) loop
					"""),
            html.tr(html.th(toxic.expr("i"), align="right"),
                    html.td(toxic.expr("xmlescape(row.name)"))),
            toxic.code("""
					i := i+1;
				end loop;
			""")))
def oraclecode():
	return xsc.Frag(
		toxic.args("search in varchar2"),
		toxic.vars("i integer;"),
		htmlspecials.plaintable(
			toxic.code("""
				i := 1;
				for row in (select name from person where name like search) loop
					"""),
					html.tr(
						html.th(toxic.expr("i"), align="right"),
						html.td(toxic.expr("xmlescape(row.name)"))
					),
					toxic.code("""
					i := i+1;
				end loop;
			""")
		)
	)
    def index(self):
        def isimg(name):
            if name.endswith(".gif") or name.endswith(".jpg") or name.endswith(
                    ".png"):
                return os.path.isfile(os.path.join(self.directory, name))
            return False

        names = [name for name in os.listdir(self.directory) if isimg(name)]
        names.sort()

        collect = xsc.Frag()
        i = 0

        with xsc.build():
            with xsc.Frag() as e:
                +xml.XML()
                +html.DocTypeXHTML10transitional()
                with html.html():
                    with html.head():
                        +meta.contenttype()
                        +html.title("All images from ", doc.z(self.directory))
                        +html.link(rel="stylesheet",
                                   type="text/css",
                                   href="images.css")
                    with html.body():
                        with htmlspecials.plaintable():
                            for name in names:
                                collect.append(
                                    html.td(
                                        htmlspecials.autoimg(src=("/images/",
                                                                  name)),
                                        html.br(),
                                        name,
                                        align="center"))
                                i += 1
                                if i == cols:
                                    +html.tr(collect)
                                    collect = xsc.Frag()
                                    i = 0
                            if collect:
                                +html.tr(collect)

        return e.conv().bytes()
Beispiel #10
0
## Copyright 1999-2017 by LivingLogic AG, Bayreuth/Germany
## Copyright 1999-2017 by Walter Dörwald
##
## All Rights Reserved
##
## See ll/xist/__init__.py for the license

import pytest

from ll import misc
from ll.xist import xsc, xfind
from ll.xist.ns import html, xml

import xist_common as common

node = html.div(html.tr(html.th("gurk"), html.td("hurz"), id=html.b(42)),
                class_=html.i("hinz"))


def path2str(path):
    return ".".join("#" if isinstance(node, xsc.Text) else node.xmlname
                    for node in path)


def iterpath2str(iter):
    return [path2str(s) for s in iter]


def test_walk_coverage():
    node = common.createfrag()
##
## See ll/xist/__init__.py for the license

import pytest

from ll import misc
from ll.xist import xsc, xfind
from ll.xist.ns import html, xml

import xist_common as common


node = html.div(
	html.tr(
		html.th("gurk"),
		html.td("hurz"),
		id=html.b(42)
	),
	class_=html.i("hinz")
)


def path2str(path):
	return ".".join("#" if isinstance(node, xsc.Text) else node.xmlname for node in path)


def iterpath2str(iter):
	return [path2str(s) for s in iter]


def test_walk_coverage():
	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)