11"""Test cases for ``oembedpy.adapters.mkdocs``."""
22
33import textwrap
4+ from typing import Any , Callable , Optional
45
56import pytest
67from markdown import Markdown
910
1011
1112@pytest .fixture (scope = "module" )
12- def plugin () -> t .OembedPlugin :
13- plugin = t .OembedPlugin ()
14- plugin .on_startup (command = "build" , dirty = False )
15- return plugin
13+ def get_plugin () -> Callable [[dict [str , Any ]], t .OembedPlugin ]:
14+ def _get_plugin (config : Optional [dict [str , Any ]] = None ) -> t .OembedPlugin :
15+ plugin = t .OembedPlugin ()
16+ plugin .config = config or {"fallback_type" : False }
17+ plugin .on_startup (command = "build" , dirty = False )
18+ return plugin
19+
20+ return _get_plugin
1621
1722
1823@pytest .fixture (scope = "module" )
@@ -27,7 +32,8 @@ def md() -> Markdown:
2732 return md
2833
2934
30- def test_skip_other_lang_code (plugin : t .OembedPlugin , md : Markdown ):
35+ def test_skip_other_lang_code (get_plugin , md : Markdown ):
36+ plugin = get_plugin ()
3137 source = textwrap .dedent ("""
3238 # Help
3339
@@ -41,7 +47,8 @@ def test_skip_other_lang_code(plugin: t.OembedPlugin, md: Markdown):
4147
4248
4349@pytest .mark .webtest
44- def test_oembed_code__no_content (plugin : t .OembedPlugin , md : Markdown ):
50+ def test_oembed_code__no_content (get_plugin , md : Markdown ):
51+ plugin = get_plugin ()
4552 source = textwrap .dedent ("""
4653 # Help
4754
@@ -55,7 +62,8 @@ def test_oembed_code__no_content(plugin: t.OembedPlugin, md: Markdown):
5562
5663
5764@pytest .mark .webtest
58- def test_oembed_code__valid_content (plugin : t .OembedPlugin , md : Markdown ):
65+ def test_oembed_code__valid_content (get_plugin , md : Markdown ):
66+ plugin = get_plugin ()
5967 source = textwrap .dedent ("""
6068 # Help
6169
@@ -66,3 +74,33 @@ def test_oembed_code__valid_content(plugin: t.OembedPlugin, md: Markdown):
6674 html = md .convert (source )
6775 output = plugin .on_page_content (html )
6876 assert html != output
77+
78+
79+ @pytest .mark .webtest
80+ def test_oembed_code__invalid_content (get_plugin , md : Markdown ):
81+ plugin = get_plugin ()
82+ source = textwrap .dedent ("""
83+ # Help
84+
85+ ```oembed
86+ url = 'https://www.reddit.com/r/Python/comments/vdopqj/sphinxrevealjs_html_presentation_builder_for/'
87+ ```
88+ """ )
89+ html = md .convert (source )
90+ output = plugin .on_page_content (html )
91+ assert html == output
92+
93+
94+ @pytest .mark .webtest
95+ def test_oembed_code__fallback_invalid_content (get_plugin , md : Markdown ):
96+ plugin = get_plugin ({"fallback_type" : True })
97+ source = textwrap .dedent ("""
98+ # Help
99+
100+ ```oembed
101+ url = 'https://www.reddit.com/r/Python/comments/vdopqj/sphinxrevealjs_html_presentation_builder_for/'
102+ ```
103+ """ )
104+ html = md .convert (source )
105+ output = plugin .on_page_content (html )
106+ assert html != output
0 commit comments