Escape log sections in HTML report. Fixes #100

This commit is contained in:
Dave Hunt 2017-02-23 19:43:32 +00:00
parent 0ac9166703
commit 67e8f28bbd
No known key found for this signature in database
GPG Key ID: 4000D32ABB02F959
5 changed files with 44 additions and 16 deletions

View File

@ -14,6 +14,9 @@ matrix:
- language: python
python: 2.7
env: TOXENV=pytest30
- language: python
python: 2.7
env: TOXENV=pytest30-ansi2html
- language: python
python: 3.6
env: TOXENV=flake8
@ -23,24 +26,36 @@ matrix:
- language: python
python: 3.6
env: TOXENV=pytest30
- language: python
python: 3.6
env: TOXENV=pytest30-ansi2html
- language: python
python: pypy
env: TOXENV=pytest29
- language: python
python: pypy
env: TOXENV=pytest30
- language: python
python: pypy
env: TOXENV=pytest30-ansi2html
- language: python
python: pypy3
env: TOXENV=pytest29
- language: python
python: pypy3
env: TOXENV=pytest30
- language: python
python: pypy3
env: TOXENV=pytest30-ansi2html
- language: python
python: nightly
env: TOXENV=pytest29
- language: python
python: nightly
env: TOXENV=pytest30
- language: python
python: nightly
env: TOXENV=pytest30-ansi2html
install:
- pip install tox-travis
script:

View File

@ -1,6 +1,10 @@
Release Notes
-------------
**1.14.0 (unreleased)**
* Escape contents of log sections
**1.13.0 (2016-12-19)**
* Disable ANSI codes support by default due to dependency on

View File

@ -236,11 +236,12 @@ class HTMLReport(object):
log.append(raw(escape(line)))
log.append(html.br())
for header, content in report.sections:
for section in report.sections:
header, content = map(escape, section)
log.append(' {0} '.format(header).center(80, '-'))
log.append(html.br())
if ANSI:
converter = Ansi2HTMLConverter(inline=False)
converter = Ansi2HTMLConverter(inline=False, escaped=False)
content = converter.convert(content, full=False)
log.append(raw(content))

View File

@ -207,18 +207,17 @@ class TestHTML:
regex_css_link = '<link href="assets/style.css" rel="stylesheet"'
assert re.search(regex_css_link, html) is not None
def test_stdout(self, testdir):
content = (str(random.random()), str(random.random()))
@pytest.mark.parametrize('result', ['pass', 'fail'])
def test_stdout(self, testdir, result):
content = '<spam>ham</spam>'
escaped = '&lt;spam&gt;ham&lt;/spam&gt;'
testdir.makepyfile("""
def test_pass():
print({0})
def test_fail():
print({1})
assert False""".format(*content))
result, html = run(testdir)
assert result.ret
for c in content:
assert c in html
def test_stdout():
print('{0}')
assert '{1}' == 'pass'""".format(content, result))
_, html = run(testdir)
assert content not in html
assert escaped in html
def test_extra_html(self, testdir):
content = str(random.random())
@ -490,6 +489,12 @@ class TestHTML:
assert_results(html, passed=1)
def test_ansi_color(self, testdir):
try:
import ansi2html # NOQA
ANSI = True
except ImportError:
# ansi2html is not installed
ANSI = False
pass_content = ["<span class=\"ansi31\">RCOLOR",
"<span class=\"ansi32\">GCOLOR",
"<span class=\"ansi33\">YCOLOR"]
@ -503,4 +508,7 @@ class TestHTML:
result, html = run(testdir, 'report.html', '--self-contained-html')
assert result.ret == 0
for content in pass_content:
assert content in html
if ANSI:
assert content in html
else:
assert content not in html

View File

@ -4,16 +4,16 @@
# and then run "tox" from this directory.
[tox]
envlist = py{27,36,py,py3}-pytest{29,30}, flake8
envlist = py{27,36,py,py3}-pytest{29,30}{,-ansi2html}, flake8
[testenv]
commands = py.test -v -r a {posargs}
deps =
ansi2html==1.1.1
pytest29: pytest==2.9.2
pytest30: pytest==3.0.4
pytest-xdist
pytest-rerunfailures
py{27,36,py,py3}-pytest{29,30}-ansi2html: ansi2html==1.1.1
[testenv:flake8]
skip_install = true