本文整理汇总了Python中py.xml.html.html函数的典型用法代码示例。如果您正苦于以下问题:Python html函数的具体用法?Python html怎么用?Python html使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了html函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _generate_html
def _generate_html(pages):
"""Generate html for given pages.
:param pages: list of `Page.class`
:return: path to tempdir.
:rtype: string.
"""
tempdir = tempfile.mkdtemp()
doc = html.html(
html.head(
# python don't allow keyword args with hypens
html.meta(content="text/html; charset=utf-8", **{"http-equiv": "Content-Type"}),
_get_tile(html, pages)
),
html.body(
html.div(_generate_body(html, pages, tempdir), id='article'),
)
)
with open(os.path.join(tempdir, 'histmag.html'), 'wb') as out_file:
logger.debug(
'Saving generated html to {file}'.format(file=os.path.join(tempdir, 'histmag.html'))
)
out_file.write(doc.unicode(indent=2).encode('utf8'))
return tempdir
开发者ID:krzysztofzuraw,项目名称:histmag_to_kindle,代码行数:27,代码来源:generator.py
示例2: make_html_report
def make_html_report(path, report):
def tabelize(value):
try:
rows = []
for key in value.keys():
rows.append(html.tr(html.td(html.pre(key)), html.td(tabelize(value[key]))))
return html.table(rows)
except AttributeError:
if type(value) == type([]):
return html.table(map(tabelize, value))
else:
return html.pre(value)
body_els = []
keys = report.keys()
keys.sort()
links = []
for key in keys:
links.append(html.li(html.a(key, href="#" + key)))
body_els.append(html.ul(links))
for key in keys:
body_els.append(html.a(html.h1(key), id=key))
body_els.append(tabelize(report[key]))
with open(path, 'w') as f:
doc = html.html(html.head(html.style('table, td {border: 1px solid;}')), html.body(body_els))
f.write(str(doc))
开发者ID:Mozilla-TWQA,项目名称:fxos-certsuite,代码行数:26,代码来源:cert.py
示例3: make_report
def make_report(self, time, summary_results, subsuite_results):
self.time = time
self.summary_results = summary_results
self.subsuite_results = subsuite_results
return html.html(
self.make_head(),
self.make_body()
)
开发者ID:Mozilla-TWQA,项目名称:fxos-certsuite,代码行数:8,代码来源:summary.py
示例4: startDocument
def startDocument(self):
h = html.html()
self.head = head = html.head()
self.title = title = html.title(self.title)
self._push(h)
h.append(head)
h.append(title)
self.body = body = html.body()
self._push(body)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:9,代码来源:transform.py
示例5: simple_list_project
def simple_list_project(self):
request = self.request
name = self.context.name
# we only serve absolute links so we don't care about the route's slash
abort_if_invalid_projectname(request, name)
stage = self.context.stage
if stage.get_projectname(name) is None:
# we return 200 instead of !=200 so that pip/easy_install don't
# ask for the full simple page although we know it doesn't exist
# XXX change that when pip-6.0 is released?
abort(request, 200, "no such project %r" % name)
projectname = self.context.projectname
try:
result = stage.get_releaselinks(projectname)
except stage.UpstreamError as e:
threadlog.error(e.msg)
abort(request, 502, e.msg)
links = []
for link in result:
relpath = link.entrypath
href = "/" + relpath
href = URL(request.path_info).relpath(href)
if link.eggfragment:
href += "#egg=%s" % link.eggfragment
elif link.hash_spec:
href += "#" + link.hash_spec
links.extend([
"/".join(relpath.split("/", 2)[:2]) + " ",
html.a(link.basename, href=href),
html.br(), "\n",
])
title = "%s: links for %s" % (stage.name, projectname)
if stage.has_pypi_base(projectname):
refresh_title = "Refresh" if stage.ixconfig["type"] == "mirror" else \
"Refresh PyPI links"
refresh_url = request.route_url(
"/{user}/{index}/+simple/{name}/refresh",
user=self.context.username, index=self.context.index,
name=projectname)
refresh_form = [
html.form(
html.input(
type="submit", value=refresh_title, name="refresh"),
action=refresh_url,
method="post"),
"\n"]
else:
refresh_form = []
return Response(html.html(
html.head(
html.title(title)),
html.body(
html.h1(title), "\n",
refresh_form,
links)).unicode(indent=2))
开发者ID:uceo,项目名称:uceo-2015,代码行数:56,代码来源:views.py
示例6: simple_html_body
def simple_html_body(title, bodytags):
return html.html(
html.head(
html.title(title)
),
html.body(
html.h1(title),
*bodytags
)
)
开发者ID:zerotired,项目名称:devpi,代码行数:10,代码来源:views.py
示例7: simple_list_project
def simple_list_project(self):
request = self.request
name = self.context.name
# we only serve absolute links so we don't care about the route's slash
abort_if_invalid_projectname(request, name)
stage = self.context.stage
projectname = stage.get_projectname(name)
if projectname is None:
abort(request, 200, "no such project %r" % projectname)
if name != projectname:
redirect("/%s/+simple/%s/" % (stage.name, projectname))
try:
result = stage.get_releaselinks(projectname)
except stage.UpstreamError as e:
threadlog.error(e.msg)
abort(request, 502, e.msg)
links = []
for link in result:
relpath = link.entrypath
href = "/" + relpath
href = URL(request.path).relpath(href)
if link.eggfragment:
href += "#egg=%s" % link.eggfragment
elif link.md5:
href += "#md5=%s" % link.md5
links.extend([
"/".join(relpath.split("/", 2)[:2]) + " ",
html.a(link.basename, href=href),
html.br(), "\n",
])
title = "%s: links for %s" % (stage.name, projectname)
if stage.has_pypi_base(projectname):
refresh_title = "Refresh" if stage.ixconfig["type"] == "mirror" else \
"Refresh PyPI links"
refresh_url = request.route_url(
"/{user}/{index}/+simple/{name}/refresh",
user=self.context.username, index=self.context.index,
name=projectname)
refresh_form = [
html.form(
html.input(
type="submit", value=refresh_title, name="refresh"),
action=refresh_url,
method="post"),
"\n"]
else:
refresh_form = []
return Response(html.html(
html.head(
html.title(title)),
html.body(
html.h1(title), "\n",
refresh_form,
links)).unicode(indent=2))
开发者ID:t-8ch,项目名称:devpi,代码行数:55,代码来源:views.py
示例8: simple_html_body
def simple_html_body(title, bodytags, extrahead=""):
return html.html(
html.head(
html.title(title),
extrahead,
),
html.body(
html.h1(title), "\n",
bodytags
)
)
开发者ID:kenatbasis,项目名称:devpi,代码行数:11,代码来源:views.py
示例9: create_unknown_html
def create_unknown_html(path):
h = html.html(
html.head(
html.title('Can not display page'),
style,
),
html.body(
html.p('The data URL (%s) does not contain Python code.' % (path,))
),
)
return h.unicode()
开发者ID:mickg10,项目名称:DARLAB,代码行数:11,代码来源:html.py
示例10: __init__
def __init__(self, title=None):
self.body = html.body()
self.head = html.head()
self.doc = html.html(self.head, self.body)
if title is not None:
self.head.append(
html.meta(name="title", content=title))
self.head.append(
html.link(rel="Stylesheet", type="text/css", href="MochiKit-1.1/examples/sortable_tables/sortable_tables.css"))
self.head.append(
html.script(rel="JavaScript", type="text/javascript", src="MochiKit-1.1/lib/MochiKit/MochiKit.js"))
self.head.append(
html.script(rel="JavaScript", type="text/javascript", src="MochiKit-1.1/examples/sortable_tables/sortable_tables.js"))
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:14,代码来源:pybench.py
示例11: pytest_sessionfinish
def pytest_sessionfinish(self, session, exitstatus):
self._make_report_dir()
logfile = py.std.codecs.open(self.logfile, 'w', encoding='utf-8')
suite_stop_time = time.time()
suite_time_delta = suite_stop_time - self.suite_start_time
numtests = self.passed + self.failed
generated = datetime.datetime.now()
doc = html.html(
html.head(
html.meta(charset='utf-8'),
html.title('Test Report'),
html.link(rel='stylesheet', href='style.css'),
html.script(src='jquery.js'),
html.script(src='main.js')),
html.body(
html.p('Report generated on %s at %s ' % (
generated.strftime('%d-%b-%Y'),
generated.strftime('%H:%M:%S'),
)),
html.div([html.p(
html.span('%i tests' % numtests, class_='all clickable'),
' ran in %i seconds.' % suite_time_delta,
html.br(),
html.span('%i passed' % self.passed, class_='passed clickable'), ', ',
html.span('%i skipped' % self.skipped, class_='skipped clickable'), ', ',
html.span('%i failed' % self.failed, class_='failed clickable'), ', ',
html.span('%i errors' % self.errors, class_='error clickable'), '.',
html.br(), ),
html.span('Hide all errors', class_='clickable hide_all_errors'), ', ',
html.span('Show all errors', class_='clickable show_all_errors'),
], id='summary-wrapper'),
html.div(id='summary-space'),
html.table([
html.thead(html.tr([
html.th('Result', class_='sortable', col='result'),
html.th('Class', class_='sortable', col='class'),
html.th('Name', class_='sortable', col='name'),
html.th('Duration', class_='sortable numeric', col='duration'),
# html.th('Output')]), id='results-table-head'),
html.th('Links')]), id='results-table-head'),
html.tbody(*self.test_logs, id='results-table-body')], id='results-table')))
logfile.write(
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">' + doc.unicode(
indent=2))
logfile.close()
self.process_screenshot_files()
self.process_debug_event_files()
self.process_performance_files()
开发者ID:salsita,项目名称:shishito,代码行数:50,代码来源:junithtml.py
示例12: __init__
def __init__(self, encoding, tokenizer=None):
self.encoding = encoding
self.html = root = html.html()
self.head = head = self.create_head()
root.append(head)
self.body = body = self.create_body()
root.append(body)
self.table, self.tbody = table, tbody = self.create_table()
body.append(table)
if tokenizer is None:
tokenizer = Tokenizer(PythonSchema)
self.tokenizer = tokenizer
开发者ID:mickg10,项目名称:DARLAB,代码行数:14,代码来源:html.py
示例13: create_dir_html
def create_dir_html(path, href_prefix=''):
h = html.html(
html.head(
html.title('directory listing of %s' % (path,)),
style,
),
)
body = html.body(
html.h1('directory listing of %s' % (path,)),
)
h.append(body)
table = html.table()
body.append(table)
tbody = html.tbody()
table.append(tbody)
items = list(path.listdir())
items.sort(key=lambda p: p.basename)
items.sort(key=lambda p: not p.check(dir=True))
for fpath in items:
tr = html.tr()
tbody.append(tr)
td1 = html.td(fpath.check(dir=True) and 'D' or 'F', class_='type')
tr.append(td1)
href = fpath.basename
if href_prefix:
href = '%s%s' % (href_prefix, href)
if fpath.check(dir=True):
href += '/'
td2 = html.td(html.a(fpath.basename, href=href), class_='name')
tr.append(td2)
td3 = html.td(time.strftime('%Y-%m-%d %H:%M:%S',
time.gmtime(fpath.mtime())), class_='mtime')
tr.append(td3)
if fpath.check(dir=True):
size = ''
unit = ''
else:
size = fpath.size()
unit = 'B'
for u in ['kB', 'MB', 'GB', 'TB']:
if size > 1024:
size = round(size / 1024.0, 2)
unit = u
td4 = html.td('%s %s' % (size, unit), class_='size')
tr.append(td4)
return unicode(h)
开发者ID:mickg10,项目名称:DARLAB,代码行数:46,代码来源:html.py
示例14: findlinks_view
def findlinks_view(context, request):
title = "%s: all package links without root/pypi" % (context.stage.name)
projectnames = set()
for stage, names in context.stage.op_sro("list_projectnames_perstage"):
if stage.ixconfig["type"] == "mirror":
continue
projectnames.update(names)
all_links = []
basenames = set()
for projectname in sorted(projectnames):
for stage, res in context.stage.op_sro_check_pypi_whitelist(
"get_releaselinks_perstage", projectname=projectname):
if stage.ixconfig["type"] == "mirror":
continue
for link in res:
if link.eggfragment:
key = link.eggfragment
else:
key = link.basename
if key not in basenames:
basenames.add(key)
all_links.append(link)
links = []
for link in sorted(all_links, key=attrgetter('basename')):
href = url_for_entrypath(request, link.entrypath)
entry = link.entry
if entry.eggfragment:
href += "#egg=%s" % entry.eggfragment
elif entry.md5:
href += "#md5=%s" % entry.md5
links.extend([
"/".join(link.entrypath.split("/", 2)[:2]) + " ",
html.a(link.basename, href=href),
html.br(), "\n"])
if not links:
links = [html.p('No releases.')]
return Response(html.html(
html.head(
html.title(title)),
html.body(
html.h1(title), "\n",
links)).unicode(indent=2))
开发者ID:msabramo,项目名称:devpi-findlinks,代码行数:42,代码来源:main.py
示例15: generate_html
def generate_html(self):
generated = datetime.utcnow()
with open(os.path.join(base_path, "main.js")) as main_f:
doc = html.html(
self.head,
html.body(
html.script(raw(main_f.read())),
html.p('Report generated on %s at %s' % (
generated.strftime('%d-%b-%Y'),
generated.strftime('%H:%M:%S'))),
html.h2('Environment'),
html.table(
[html.tr(html.td(k), html.td(v)) for k, v in sorted(self.env.items()) if v],
id='environment'),
html.h2('Summary'),
html.p('%i tests ran in %.1f seconds.' % (sum(self.test_count.itervalues()),
(self.suite_times["end"] -
self.suite_times["start"]) / 1000.),
html.br(),
html.span('%i passed' % self.test_count["PASS"], class_='pass'), ', ',
html.span('%i skipped' % self.test_count["SKIP"], class_='skip'), ', ',
html.span('%i failed' % self.test_count["UNEXPECTED_FAIL"], class_='fail'), ', ',
html.span('%i errors' % self.test_count["UNEXPECTED_ERROR"], class_='error'), '.',
html.br(),
html.span('%i expected failures' % self.test_count["EXPECTED_FAIL"],
class_='expected_fail'), ', ',
html.span('%i unexpected passes' % self.test_count["UNEXPECTED_PASS"],
class_='unexpected_pass'), '.'),
html.h2('Results'),
html.table([html.thead(
html.tr([
html.th('Result', class_='sortable', col='result'),
html.th('Test', class_='sortable', col='name'),
html.th('Duration', class_='sortable numeric', col='duration'),
html.th('Links')]), id='results-table-head'),
html.tbody(self.result_rows, id='results-table-body')], id='results-table')))
return u"<!DOCTYPE html>\n" + doc.unicode(indent=2)
开发者ID:Andrel322,项目名称:gecko-dev,代码行数:39,代码来源:html.py
示例16: _generate_report
def _generate_report(self, session):
suite_stop_time = time.time()
suite_time_delta = suite_stop_time - self.suite_start_time
numtests = self.passed + self.failed + self.xpassed + self.xfailed
generated = datetime.datetime.now()
style_css = pkg_resources.resource_string(
__name__, os.path.join('resources', 'style.css'))
if PY3:
style_css = style_css.decode('utf-8')
head = html.head(
html.meta(charset='utf-8'),
html.title('Test Report'),
html.style(raw(style_css)))
class Outcome:
def __init__(self, outcome, total=0, label=None,
test_result=None, class_html=None):
self.outcome = outcome
self.label = label or outcome
self.class_html = class_html or outcome
self.total = total
self.test_result = test_result or outcome
self.generate_checkbox()
self.generate_summary_item()
def generate_checkbox(self):
checkbox_kwargs = {'data-test-result':
self.test_result.lower()}
if self.total == 0:
checkbox_kwargs['disabled'] = 'true'
self.checkbox = html.input(type='checkbox',
checked='true',
onChange='filter_table(this)',
name='filter_checkbox',
**checkbox_kwargs)
def generate_summary_item(self):
self.summary_item = html.span('{0} {1}'.
format(self.total, self.label),
class_=self.class_html)
outcomes = [Outcome('passed', self.passed),
Outcome('skipped', self.skipped),
Outcome('failed', self.failed),
Outcome('error', self.errors, label='errors'),
Outcome('xfailed', self.xfailed,
label='expected failures'),
Outcome('xpassed', self.xpassed,
label='unexpected passes'),
Outcome('rerun', self.rerun)]
summary = [html.h2('Summary'), html.p(
'{0} tests ran in {1:.2f} seconds. '.format(
numtests, suite_time_delta)),
html.p('(Un)check the boxes to filter the results.')]
for outcome in outcomes:
summary.append(outcome.checkbox)
summary.append(outcome.summary_item)
summary.append(' ')
results = [html.h2('Results'), html.table([html.thead(
html.tr([
html.th('Result',
class_='sortable initial-sort result',
col='result'),
html.th('Test', class_='sortable', col='name'),
html.th('Duration',
class_='sortable numeric',
col='duration'),
html.th('Links')]),
html.tr([
html.th('No results found. Try to check the filters',
colspan='5')],
id='not-found-message', hidden='true'),
id='results-table-head'),
self.test_logs], id='results-table')]
main_js = pkg_resources.resource_string(
__name__, os.path.join('resources', 'main.js'))
if PY3:
main_js = main_js.decode('utf-8')
body = html.body(
html.script(raw(main_js)),
html.p('Report generated on {0} at {1}'.format(
generated.strftime('%d-%b-%Y'),
generated.strftime('%H:%M:%S'))))
if session.config._environment:
environment = set(session.config._environment)
body.append(html.h2('Environment'))
body.append(html.table(
[html.tr(html.td(e[0]), html.td(e[1])) for e in sorted(
environment, key=lambda e: e[0]) if e[1]],
#.........这里部分代码省略.........
开发者ID:redixin,项目名称:pytest-html,代码行数:101,代码来源:plugin.py
示例17: pytest_sessionfinish
def pytest_sessionfinish(self, session, exitstatus, __multicall__):
self._make_report_dir()
logfile = py.std.codecs.open(self.logfile, 'w', encoding='utf-8')
suite_stop_time = time.time()
suite_time_delta = suite_stop_time - self.suite_start_time
numtests = self.passed + self.failed + self.xpassed + self.xfailed
server = self.config.option.sauce_labs_credentials_file and \
'Sauce Labs' or 'http://%s:%s' % (self.config.option.host, self.config.option.port)
browser = self.config.option.browser_name and \
self.config.option.browser_version and \
self.config.option.platform and \
'%s %s on %s' % (str(self.config.option.browser_name).title(),
self.config.option.browser_version,
str(self.config.option.platform).title()) or \
self.config.option.environment or \
self.config.option.browser
generated = datetime.datetime.now()
configuration = {
'Base URL': self.config.option.base_url,
'Build': self.config.option.build,
'Selenium API': self.config.option.api,
'Driver': self.config.option.driver,
'Firefox Path': self.config.option.firefox_path,
'Google Chrome Path': self.config.option.chrome_path,
'Selenium Server': server,
'Browser': browser,
'Timeout': self.config.option.webqatimeout,
'Capture Network Traffic': self.config.option.capture_network,
'Credentials': self.config.option.credentials_file,
'Sauce Labs Credentials': self.config.option.sauce_labs_credentials_file}
import pytest_mozwebqa
doc = html.html(
html.head(
html.meta(charset='utf-8'),
html.title('Test Report'),
html.link(rel='stylesheet', href='style.css'),
html.script(src='jquery.js'),
html.script(src='main.js')),
html.body(
html.p('Report generated on %s at %s by pytest-mozwebqa %s' % (
generated.strftime('%d-%b-%Y'),
generated.strftime('%H:%M:%S'),
pytest_mozwebqa.__version__)),
html.h2('Configuration'),
html.table(
[html.tr(html.td(k), html.td(v)) for k, v in sorted(configuration.items()) if v],
id='configuration'),
html.h2('Summary'),
html.p(
'%i tests ran in %i seconds.' % (numtests, suite_time_delta),
html.br(),
html.span('%i passed' % self.passed, class_='passed'), ', ',
html.span('%i skipped' % self.skipped, class_='skipped'), ', ',
html.span('%i failed' % self.failed, class_='failed'), ', ',
html.span('%i errors' % self.errors, class_='error'), '.',
html.br(),
html.span('%i expected failures' % self.xfailed, class_='skipped'), ', ',
html.span('%i unexpected passes' % self.xpassed, class_='failed'), '.'),
html.h2('Results'),
html.table([
html.thead(html.tr([
html.th('Result', class_='sortable', col='result'),
html.th('Class', class_='sortable', col='class'),
html.th('Name', class_='sortable', col='name'),
html.th('Duration', class_='sortable numeric', col='duration'),
html.th('Links')]), id='results-table-head'),
html.tbody(*self.test_logs, id='results-table-body')], id='results-table')))
logfile.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">' + doc.unicode(indent=2))
logfile.close()
开发者ID:RonnyPfannschmidt,项目名称:pytest-mozwebqa,代码行数:74,代码来源:html_report.py
示例18: _generate_report
def _generate_report(self, session):
"""
The method writes HTML report to a temporary logfile.
"""
suite_stop_time = time.time()
suite_time_delta = suite_stop_time - self.suite_start_time
numtests = self.passed + self.failed + self.xpassed + self.xfailed
generated = datetime.datetime.now()
style_css = pkg_resources.resource_string(
pytest_html_path, os.path.join('resources', 'style.css'))
head = html.head(
html.meta(charset='utf-8'),
html.title('Test Report'),
html.style(raw(style_css)))
summary = [html.h2('Summary'), html.p(
'{0} tests ran in {1:.2f} seconds.'.format(
numtests, suite_time_delta),
html.br(),
html.span('{0} passed'.format(
self.passed), class_='passed'), ', ',
html.span('{0} skipped'.format(
self.skipped), class_='skipped'), ', ',
html.span('{0} failed'.format(
self.failed), class_='failed'), ', ',
html.span('{0} errors'.format(
self.errors), class_='error'), '.',
html.br(),
html.span('{0} expected failures'.format(
self.xfailed), class_='skipped'), ', ',
html.span('{0} unexpected passes'.format(
self.xpassed), class_='failed'), '.')]
results = [html.h2('Results'), html.table([html.thead(
html.tr([
html.th('Result',
class_='sortable initial-sort result',
col='result'),
html.th('Test', class_='sortable', col='name'),
html.th('Duration',
class_='sortable numeric',
col='duration'),
html.th('Links')]), id='results-table-head'),
html.tbody(*self.test_logs, id='results-table-body')],
id='results-table')]
main_js = pkg_resources.resource_string(
pytest_html_path, os.path.join('resources', 'main.js'))
body = html.body(
html.script(raw(main_js)),
html.p('Report generated on {0} at {1}'.format(
generated.strftime('%d-%b-%Y'),
generated.strftime('%H:%M:%S'))))
if session.config._environment:
environment = set(session.config._environment)
body.append(html.h2('Environment'))
body.append(html.table(
[html.tr(html.td(e[0]), html.td(e[1])) for e in sorted(
environment, key=lambda e: e[0]) if e[1]],
id='environment'))
body.extend(summary)
body.extend(results)
doc = html.html(head, body)
# A string which holds the complete report.
report_content = (
"Test executed on commit "
"[[https://www.github.com/tardis-sn/tardis/commit/{0}|{0}]]\n\n".format(
tardis.__githash__
)
)
report_content += doc.unicode(indent=2)
# Quick hack for preventing log to be placed in narrow left out space
report_content = report_content.replace(
u'class="log"', u'class="log" style="clear: both"'
)
return report_content
开发者ID:rithwiksv,项目名称:tardis,代码行数:84,代码来源:report.py
示例19: make_report
def make_report(self, results):
self.results = results
return html.html(
self.make_head(),
self.make_body()
)
开发者ID:Mozilla-TWQA,项目名称:fxos-certsuite,代码行数:6,代码来源:subsuite.py
示例20: _generate_report
def _generate_report(self, session):
suite_stop_time = time.time()
suite_time_delta = suite_stop_time - self.suite_start_time
numtests = self.passed + self.failed + self.xpassed + self.xfailed
generated = datetime.datetime.now()
self.style_css = pkg_resources.resource_string(
__name__, os.path.join('resources', 'style.css'))
if PY3:
self.style_css = self.style_css.decode('utf-8')
if ANSI:
ansi_css = [
'\n/******************************',
' * ANSI2HTML STYLES',
' ******************************/\n']
ansi_css.extend([str(r) for r in style.get_styles()])
self.style_css += '\n'.join(ansi_css)
# <DF> Add user-provided CSS
for path in self.config.getoption('css') or []:
self.style_css += '\n/******************************'
self.style_css += '\n * CUSTOM CSS'
self.style_css += '\n * {}'.format(path)
self.style_css += '\n ******************************/\n\n'
with open(path, 'r') as f:
self.style_css += f.read()
css_href = '{0}/{1}'.format('assets', 'style.css')
html_css = html.link(href=css_href, rel='stylesheet',
type='text/css')
if self.self_contained:
html_css = html.style(raw(self.style_css))
head = html.head(
html.meta(charset='utf-8'),
html.title('Test Report'),
html_css)
class Outcome:
def __init__(self, outcome, total=0, label=None,
test_result=None, class_html=None):
self.outcome = outcome
self.label = label or outcome
self.class_html = class_html or outcome
self.total = total
self.test_result = test_result or outcome
self.generate_checkbox()
self.generate_summary_item()
def generate_checkbox(self):
checkbox_kwargs = {'data-test-result':
self.test_result.lower()}
if self.total == 0:
checkbox_kwargs['disabled'] = 'true'
self.checkbox = html.input(type='checkbox',
checked='true',
onChange='filter_table(this)',
name='filter_checkbox',
class_='filter',
hidden='true',
**checkbox_kwargs)
def generate_summary_item(self):
self.summary_item = html.span('{0} {1}'.
format(self.total, self.label),
class_=self.class_html)
outcomes = [Outcome('passed', self.passed),
Outcome('skipped', self.skipped),
Outcome('failed', self.failed),
Outcome('error', self.errors, label='errors'),
Outcome('xfailed', self.xfailed,
label='expected failures'),
Outcome('xpassed', self.xpassed,
label='unexpected passes')]
if self.rerun is not None:
outcomes.append(Outcome('rerun', self.rerun))
summary = [html.p(
'{0} tests ran in {1:.2f} seconds. '.format(
numtests, suite_time_delta)),
html.p('(Un)check the boxes to filter the results.',
class_='filter',
hidden='true')]
for i, outcome in enumerate(outcomes, start=1):
summary.append(outcome.checkbox)
summary.append(outcome.summary_item)
if i < len(outcomes):
summary.append(', ')
cells = [
html.th('Result',
class_='sortable result initial-sort',
col='result'),
#.........这里部分代码省略.........
开发者ID:davehunt,项目名称:pytest-html,代码行数:101,代码来源:plugin.py
注:本文中的py.xml.html.html函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论