diff options
Diffstat (limited to 'tests/test_rst_compiler.py')
| -rw-r--r-- | tests/test_rst_compiler.py | 72 |
1 files changed, 11 insertions, 61 deletions
diff --git a/tests/test_rst_compiler.py b/tests/test_rst_compiler.py index 5bbd617..5b33db7 100644 --- a/tests/test_rst_compiler.py +++ b/tests/test_rst_compiler.py @@ -4,7 +4,7 @@ """ Test cases for Nikola ReST extensions. -A base class ReSTExtensionTestCase provides the tests basic behaivor. +A base class ReSTExtensionTestCase provides the tests basic behaviour. Subclasses must override the "sample" class attribute with the ReST markup. The sample will be rendered as HTML using publish_parts() by setUp(). One method is provided for checking the resulting HTML: @@ -44,12 +44,11 @@ import pytest import unittest import nikola.plugins.compile.rest -from nikola.plugins.compile.rest import gist from nikola.plugins.compile.rest import vimeo import nikola.plugins.compile.rest.listing from nikola.plugins.compile.rest.doc import Plugin as DocPlugin from nikola.utils import _reload -from .base import BaseTestCase, FakeSite +from .base import BaseTestCase, FakeSite, FakePost class ReSTExtensionTestCase(BaseTestCase): @@ -72,20 +71,20 @@ class ReSTExtensionTestCase(BaseTestCase): tmpdir = tempfile.mkdtemp() inf = os.path.join(tmpdir, 'inf') outf = os.path.join(tmpdir, 'outf') - depf = os.path.join(tmpdir, 'outf.dep') with io.open(inf, 'w+', encoding='utf8') as f: f.write(rst) + p = FakePost('', '') + p._depfile[outf] = [] + self.compiler.site.post_per_input_file[inf] = p self.html = self.compiler.compile_html(inf, outf) with io.open(outf, 'r', encoding='utf8') as f: self.html = f.read() os.unlink(inf) os.unlink(outf) - if os.path.isfile(depf): - with io.open(depf, 'r', encoding='utf8') as f: - self.assertEqual(self.deps, f.read()) - os.unlink(depf) - else: - self.assertEqual(self.deps, None) + depfile = [p for p in p._depfile[outf] if p != outf] + depfile = '\n'.join(depfile) + if depfile: + self.assertEqual(self.deps.strip(), depfile) os.rmdir(tmpdir) self.html_doc = html.parse(StringIO(self.html)) @@ -129,55 +128,6 @@ class MathTestCase(ReSTExtensionTestCase): text="\(e^{ix} = \cos x + i\sin x\)") -class GistTestCase(ReSTExtensionTestCase): - """ Test GitHubGist. - We will replace get_raw_gist() and get_raw_gist_with_filename() - monkeypatching the GitHubGist class for avoiding network dependency - - """ - gist_type = gist.GitHubGist - sample = '.. gist:: fake_id\n :file: spam.py' - sample_without_filename = '.. gist:: fake_id2' - - def setUp(self): - """ Patch GitHubGist for avoiding network dependency """ - super(GistTestCase, self).setUp() - self.gist_type.get_raw_gist_with_filename = lambda *_: 'raw_gist_file' - self.gist_type.get_raw_gist = lambda *_: "raw_gist" - _reload(nikola.plugins.compile.rest) - - @pytest.mark.skipif(True, reason="This test indefinitely skipped.") - def test_gist(self): - """ Test the gist directive with filename """ - self.setHtmlFromRst(self.sample) - output = 'https://gist.github.com/fake_id.js?file=spam.py' - self.assertHTMLContains("script", attributes={"src": output}) - self.assertHTMLContains("pre", text="raw_gist_file") - - @pytest.mark.skipif(True, reason="This test indefinitely skipped.") - def test_gist_without_filename(self): - """ Test the gist directive without filename """ - self.setHtmlFromRst(self.sample_without_filename) - output = 'https://gist.github.com/fake_id2.js' - self.assertHTMLContains("script", attributes={"src": output}) - self.assertHTMLContains("pre", text="raw_gist") - - -class GistIntegrationTestCase(ReSTExtensionTestCase): - """ Test requests integration. The gist plugin uses requests to fetch gist - contents and place it in a noscript tag. - - """ - sample = '.. gist:: 1812835' - - def test_gist_integration(self): - """ Fetch contents of the gist from GH and render in a noscript tag """ - self.basic_test() - text = ('Be alone, that is the secret of invention: be alone, that is' - ' when ideas are born. -- Nikola Tesla') - self.assertHTMLContains('pre', text=text) - - class SlidesTestCase(ReSTExtensionTestCase): """ Slides test case """ @@ -223,7 +173,7 @@ class VimeoTestCase(ReSTExtensionTestCase): """ Test Vimeo iframe tag generation """ self.basic_test() self.assertHTMLContains("iframe", - attributes={"src": ("//player.vimeo.com/" + attributes={"src": ("https://player.vimeo.com/" "video/VID"), "height": "400", "width": "600"}) @@ -237,7 +187,7 @@ class YoutubeTestCase(ReSTExtensionTestCase): """ Test Youtube iframe tag generation """ self.basic_test() self.assertHTMLContains("iframe", - attributes={"src": ("//www.youtube.com/" + attributes={"src": ("https://www.youtube.com/" "embed/YID?rel=0&hd=1&" "wmode=transparent"), "height": "400", "width": "600"}) |
