diff --git a/README.rst b/README.rst index f498497..698454f 100644 --- a/README.rst +++ b/README.rst @@ -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 ------------------ diff --git a/sphinxcontrib/disqus.py b/sphinxcontrib/disqus.py index aea86b2..29ddf22 100644 --- a/sphinxcontrib/disqus.py +++ b/sphinxcontrib/disqus.py @@ -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): @@ -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)) diff --git a/tests/test_command.py b/tests/test_command.py index e2f117a..b88fa24 100644 --- a/tests/test_command.py +++ b/tests/test_command.py @@ -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::') @@ -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)) @@ -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