Skip to content

Commit

Permalink
Merge pull request #75 from mcmtroffaes/feature/sphinx_testing
Browse files Browse the repository at this point in the history
Use the new sphinx_testing module.
  • Loading branch information
mcmtroffaes committed Mar 23, 2015
2 parents 46c5542 + 7f05b3f commit db77c97
Show file tree
Hide file tree
Showing 30 changed files with 238 additions and 740 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ branches:
only:
- develop
install:
- "pip install Tinkerer" # Tinkerer is required for tests
- "pip install sphinx-testing Tinkerer" # required for tests
- "pip install ."
- "if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then pip install coveralls check-manifest flake8; fi"
script:
Expand Down
198 changes: 0 additions & 198 deletions test/path.py

This file was deleted.

53 changes: 24 additions & 29 deletions test/test_bibfile_out_of_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,43 @@
Sphinx is run again.
"""

import os.path
import shutil
import re
import time
from sphinx_testing.util import path, with_app

from util import path, with_app

srcdir = path(__file__).parent.joinpath('bibfile_out_of_date').abspath()
srcdir = path(__file__).dirname().joinpath('bibfile_out_of_date').abspath()


def teardown_module():
(srcdir / '_build').rmtree(True)
os.remove(srcdir / 'test.bib')
(srcdir / 'test.bib').rmtree(True)


@with_app(srcdir=srcdir, warningiserror=True)
def test_encoding(app):
shutil.copyfile(
os.path.join(srcdir, 'test_old.bib'),
os.path.join(srcdir, 'test.bib'))
def test_encoding(app, status, warning):
shutil.copyfile((srcdir / 'test_old.bib'), (srcdir / 'test.bib'))
app.builder.build_all()
with open(os.path.join(app.outdir, "contents.html")) as stream:
assert re.search(
'<p id="bibtex-bibliography-contents-0">'
'.*<tr><td class="label">\\[1\\]</td><td>.*Akkerdju.*</td></tr>'
'.*<tr><td class="label">\\[2\\]</td><td>.*Bro.*</td></tr>'
'.*<tr><td class="label">\\[3\\]</td><td>.*Chap.*</td></tr>'
'.*<tr><td class="label">\\[4\\]</td><td>.*Dude.*</td></tr>'
'.*</p>',
stream.read(), re.MULTILINE | re.DOTALL)
output = (app.outdir / "contents.html").read_text()
assert re.search(
'<p id="bibtex-bibliography-contents-0">'
'.*<tr><td class="label">\\[1\\]</td><td>.*Akkerdju.*</td></tr>'
'.*<tr><td class="label">\\[2\\]</td><td>.*Bro.*</td></tr>'
'.*<tr><td class="label">\\[3\\]</td><td>.*Chap.*</td></tr>'
'.*<tr><td class="label">\\[4\\]</td><td>.*Dude.*</td></tr>'
'.*</p>',
output, re.MULTILINE | re.DOTALL)
# wait to ensure different timestamp
time.sleep(0.1)
shutil.copyfile(
os.path.join(srcdir, 'test_new.bib'),
os.path.join(srcdir, 'test.bib'))
shutil.copyfile((srcdir / 'test_new.bib'), (srcdir / 'test.bib'))
app.builder.build_all()
with open(os.path.join(app.outdir, "contents.html")) as stream:
assert re.search(
'<p id="bibtex-bibliography-contents-0">'
'.*<tr><td class="label">\\[1\\]</td><td>.*Eminence.*</td></tr>'
'.*<tr><td class="label">\\[2\\]</td><td>.*Frater.*</td></tr>'
'.*<tr><td class="label">\\[3\\]</td><td>.*Giggles.*</td></tr>'
'.*<tr><td class="label">\\[4\\]</td><td>.*Handy.*</td></tr>'
'.*</p>',
stream.read(), re.MULTILINE | re.DOTALL)
output = (app.outdir / "contents.html").read_text()
assert re.search(
'<p id="bibtex-bibliography-contents-0">'
'.*<tr><td class="label">\\[1\\]</td><td>.*Eminence.*</td></tr>'
'.*<tr><td class="label">\\[2\\]</td><td>.*Frater.*</td></tr>'
'.*<tr><td class="label">\\[3\\]</td><td>.*Giggles.*</td></tr>'
'.*<tr><td class="label">\\[4\\]</td><td>.*Handy.*</td></tr>'
'.*</p>',
output, re.MULTILINE | re.DOTALL)
14 changes: 6 additions & 8 deletions test/test_bibfilenotfound.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,18 @@
"""

import re
from six import StringIO
from sphinx_testing.util import path, with_app

from util import path, with_app

srcdir = path(__file__).parent.joinpath('bibfilenotfound').abspath()
warnfile = StringIO()
srcdir = path(__file__).dirname().joinpath('bibfilenotfound').abspath()


def teardown_module():
(srcdir / '_build').rmtree(True)


@with_app(srcdir=srcdir, warning=warnfile)
def test_bibfilenotfound(app):
@with_app(srcdir=srcdir)
def test_bibfilenotfound(app, status, warning):
app.builder.build_all()
warnings = warnfile.getvalue()
assert re.search('could not open bibtex file .*unknown[.]bib', warnings)
assert re.search(
'could not open bibtex file .*unknown[.]bib', warning.getvalue())
13 changes: 5 additions & 8 deletions test/test_citationnotfound.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,17 @@
"""

import re
from six import StringIO
from sphinx_testing.util import path, with_app

from util import path, with_app

srcdir = path(__file__).parent.joinpath('citationnotfound').abspath()
warnfile = StringIO()
srcdir = path(__file__).dirname().joinpath('citationnotfound').abspath()


def teardown_module():
(srcdir / '_build').rmtree(True)


@with_app(srcdir=srcdir, warning=warnfile)
def test_citationnotfound(app):
@with_app(srcdir=srcdir)
def test_citationnotfound(app, status, warning):
app.builder.build_all()
warnings = warnfile.getvalue()
assert re.search('citation not found: nosuchkey', warnings)
assert re.search('citation not found: nosuchkey', warning.getvalue())
16 changes: 7 additions & 9 deletions test/test_custom_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,21 @@
Test a custom style.
"""

import os.path
import re

from util import path, with_app
from sphinx_testing.util import path, with_app

srcdir = path(__file__).parent.joinpath('custom_style').abspath()
srcdir = path(__file__).dirname().joinpath('custom_style').abspath()


def teardown_module():
(srcdir / '_build').rmtree(True)


@with_app(srcdir=srcdir, warningiserror=True)
def test_custom_style(app):
def test_custom_style(app, status, warning):
app.builder.build_all()
with open(os.path.join(app.outdir, "contents.html")) as stream:
output = stream.read()
# the custom style suppresses web links
assert not re.search('http://arxiv.org', output)
assert not re.search('http://dx.doi.org', output)
output = (app.outdir / "contents.html").read_text()
# the custom style suppresses web links
assert not re.search('http://arxiv.org', output)
assert not re.search('http://dx.doi.org', output)

0 comments on commit db77c97

Please sign in to comment.