Skip to content

Commit

Permalink
Removed optional_arguments class variable.
Browse files Browse the repository at this point in the history
Don't actually need this variable.

Reformatted tests and testing for javascript file inclusion.

Fixes #1
  • Loading branch information
Robpol86 committed Aug 3, 2016
1 parent e148452 commit f237aa2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Added
Fixed
* easy_install: https://bitbucket.org/birkenfeld/sphinx-contrib/issues/155/
* https://github.com/Robpol86/sphinxcontrib-disqus/issues/2
* https://github.com/Robpol86/sphinxcontrib-disqus/issues/1

1.0.0 - 2015-07-31
------------------
Expand Down
6 changes: 1 addition & 5 deletions sphinxcontrib/disqus.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ def depart(spht, _):
class DisqusDirective(Directive):
"""Disqus ".. disqus::" rst directive."""

optional_arguments = 1
option_spec = dict(disqus_identifier=str)

def get_shortname(self):
Expand Down Expand Up @@ -103,10 +102,7 @@ def run(self):
def event_builder_inited(app):
"""Update the Sphinx builder.
http://sphinx-doc.org/extdev/appapi.html#event-builder-inited
From: https://github.com/sphinx-doc/sphinx/blob/master/sphinx/ext/mathjax.py
:param app: Sphinx application object.
:param sphinx.application.Sphinx app: Sphinx application object.
"""
# Insert Disqus read-only javascript into the document body during the builder-inited event.
app.config.html_static_path.append(os.path.relpath(STATIC_DIR, app.confdir))
Expand Down
37 changes: 27 additions & 10 deletions tests/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@

@pytest.mark.parametrize('tail,expected_error', SHORTNAME_PARAMS)
def test_shortname(tmpdir, tail, expected_error):
"""Test working and errors for disqus_shortname configuration."""
"""Test working and errors for disqus_shortname configuration.
:param tmpdir: pytest fixture.
:param str tail: Append to conf.py.
:param str expected_error: Expected error message.
"""
tmpdir.join('conf.py').write(BASE_CONFIG.format(py.path.local(__file__).join('..', '..')))
tmpdir.join('conf.py').write(tail, mode='a')
tmpdir.join('index.rst').write('====\nMain\n====\n\n.. toctree::\n :maxdepth: 2\n.. disqus::')
Expand All @@ -34,13 +39,23 @@ def test_shortname(tmpdir, tail, expected_error):
check_output(command, cwd=str(tmpdir), stderr=STDOUT)
error_message = exc.value.output.decode('utf-8')
assert expected_error in error_message
else:
check_output(command, cwd=str(tmpdir))
return

stdout = check_output(command, cwd=str(tmpdir), stderr=STDOUT).decode('utf-8')
assert 'warning' not in stdout
body_index = tmpdir.join('_build', 'html', 'index.html').read()
assert 'id="disqus_thread"' in body_index
assert 'data-disqus-identifier="Main"' in body_index
assert 'disqus.js' in body_index


@pytest.mark.parametrize('rst_title', ['====\nMain\n====\n\n', ''])
def test_identifier(tmpdir, rst_title):
"""Test working and errors for disqus_identifier configuration."""
"""Test working and errors for disqus_identifier configuration.
:param tmpdir: pytest fixture.
:param str rst_title: Title of index.rst.
"""
tmpdir.join('conf.py').write(BASE_CONFIG.format(py.path.local(__file__).join('..', '..')))
tmpdir.join('conf.py').write("disqus_shortname = 'good'", mode='a')
tmpdir.join('index.rst').write('{}.. toctree::\n :maxdepth: 2\n.. disqus::'.format(rst_title))
Expand All @@ -52,9 +67,11 @@ def test_identifier(tmpdir, rst_title):
error_message = exc.value.output.decode('utf-8')
expected_error = 'No title nodes found in document, cannot derive disqus_identifier config value.'
assert expected_error in error_message
else:
stdout = check_output(command, cwd=str(tmpdir), stderr=STDOUT).decode('utf-8')
html_body = tmpdir.join('_build', 'html', 'index.html').read()
assert 'warning' not in stdout
assert 'id="disqus_thread"' in html_body
assert 'data-disqus-identifier="Main"' in html_body
return

stdout = check_output(command, cwd=str(tmpdir), stderr=STDOUT).decode('utf-8')
assert 'warning' not in stdout
body_index = tmpdir.join('_build', 'html', 'index.html').read()
assert 'id="disqus_thread"' in body_index
assert 'data-disqus-identifier="Main"' in body_index
assert 'disqus.js' in body_index

0 comments on commit f237aa2

Please sign in to comment.