class BuildHtmlTests(unittest.TestCase): # noqa @with_app(**gen_app_conf()) def test_override_theme(self, app: TestApp, status, warning): # noqa soup = soup_html(app, "with_theme.html") css_hrefs = [ elm["href"] for elm in soup.find_all("link", rel="stylesheet") ] self.assertIn("_static/custom.css", css_hrefs) @with_app(**gen_app_conf()) def test_override_font(self, app: TestApp, status, warning): # noqa soup = soup_html(app, "with_googlefont.html") css_hrefs = [ elm["href"] for elm in soup.find_all("link", rel="stylesheet") if elm["href"].startswith("https://fonts.googleapis.com") ] self.assertEqual(len(css_hrefs), 1) styles = "\n".join([str(e) for e in soup.find_all("style")]) self.assertIn("'M PLUS 1p'", styles) @with_app(**gen_app_conf()) def test_config(self, app: TestApp, status, warning): # noqa soup = soup_html(app, "with_conf.html") self.assertIn( 'Object.assign(revealjsConfig, {"transition": "none"});', str(soup.find_all("script")[-1]), ) @with_app(**gen_app_conf()) def test_config_as_content(self, app: TestApp, status, warning): # noqa soup = soup_html(app, "with_conf_content.html") self.assertIn( "Object.assign(revealjsConfig, {\n", str(soup.find_all("script")[-1]), ) self.assertIn( '"transition": "none"\n', str(soup.find_all("script")[-1]), ) self.assertIn( "});", str(soup.find_all("script")[-1]), )
class RevealjsSectionTests(unittest.TestCase): # noqa @with_app(**gen_app_conf()) def test_render_section1_bg(self, app: TestApp, status, warning): # noqa soup = soup_html(app, "has_section_directive.html") section_tag = soup.h1.parent self.assertIn("data-background-color", section_tag.attrs) self.assertEqual(section_tag["data-background-color"], "#000001") @with_app(**gen_app_conf()) def test_render_section2_bg(self, app: TestApp, status, warning): # noqa soup = soup_html(app, "has_section_directive.html") section_tag = soup.h2.parent self.assertIn("data-background-color", section_tag.attrs) self.assertEqual(section_tag["data-background-color"], "#000101") @with_app(**gen_app_conf()) def test_no_render_parent_bg(self, app: TestApp, status, warning): # noqa soup = soup_html(app, "has_section_directive.html") section_tag = soup.h2.parent.parent self.assertNotIn("data-background-color", section_tag.attrs)
class BuildHtmlTests(unittest.TestCase): # noqa @with_app(**gen_app_conf( confoverrides={"revealjs_script_files": ["js/test.js"]})) def test_script_tags(self, app: TestApp, status, warning): # noqa soup = soup_html(app, "index.html") elements = [ e for e in soup.find_all("script") if e.get("src") == "_static/js/test.js" ] self.assertEqual(len(elements), 1) @with_app(**gen_app_conf( confoverrides={"revealjs_google_fonts": ["Noto Sans JP"]})) def test_google_fonts(self, app, status, warning): # noqa soup = soup_html(app, "index.html") link = [ e for e in soup.find_all("link", rel="stylesheet") if e["href"].startswith("https://fonts.googleapi") ] self.assertEqual(len(link), 1) style = soup.find_all("style")[-1] self.assertIn("Noto Sans JP", style.text) self.assertIn("sans-serif;", style.text) @with_app(**gen_app_conf( confoverrides={ "revealjs_google_fonts": ["Noto Sans JP"], "revealjs_generic_font": "cursive", })) def test_google_fonts_with_generic(self, app, status, warning): # noqa soup = soup_html(app, "index.html") link = [ e for e in soup.find_all("link", rel="stylesheet") if e["href"].startswith("https://fonts.googleapi") ] self.assertEqual(len(link), 1) style = soup.find_all("style")[-1] self.assertIn("Noto Sans JP", style.text) self.assertIn("cursive", style.text) @with_app(**gen_app_conf( confoverrides={"revealjs_generic_font": "cursive"})) def test_generic_font_only(self, app, status, warning): # noqa soup = soup_html(app, "index.html") styles = soup.find_all("style") self.assertEqual(len(styles), 0) @with_app(**gen_app_conf( confoverrides={"revealjs_script_files": ["js/test.js"]})) def test_script_tags(self, app: TestApp, status, warning): # noqa soup = soup_html(app, "index.html") elements = [ e for e in soup.find_all("script") if e.get("src") == "_static/js/test.js" ] self.assertEqual(len(elements), 1) @with_app(**gen_app_conf(confoverrides={ "revealjs_script_files": ["https://example.com/test.js"] })) def test_script_tags_https(self, app: TestApp, status, warning): # noqa soup = soup_html(app, "index.html") elements = [ e for e in soup.find_all("script") if e.get("src") == "https://example.com/test.js" ] self.assertEqual(len(elements), 1) @with_app(**gen_app_conf( confoverrides={"revealjs_script_conf": '{transition:"none"}'})) def test_revealjs_script_conf(self, app: TestApp, status, warning): # noqa soup = soup_html(app, "index.html") self.assertIn( 'Object.assign(revealjsConfig, {transition:"none"});', soup.find_all("script")[-1].text, ) @with_app(**gen_app_conf( confoverrides={ "revealjs_script_plugins": [{ "src": "revealjs/plugin/notes/notes.js", "options": """ {async: true} """, }] })) def test_revealjs_script_plugins(self, app: TestApp, status, warning): # noqa soup = soup_html(app, "index.html") script = soup.find_all("script")[-1].text self.assertIn("plugin_0 = {async: true}", script) self.assertIn( 'plugin_0.src = "_static/revealjs/plugin/notes/notes.js"', script) self.assertIn("revealjsConfig.dependencies.push(plugin_0);", script) @with_app(**gen_app_conf( confoverrides={ "revealjs_script_plugins": [ { "src": "revealjs/plugin/notes/notes.js", "options": "{async: true}", }, { "src": "revealjs/plugin/highlight/highlight.js" }, ] })) def test_revealjs_script_plugins(self, app: TestApp, status, warning): # noqa soup = soup_html(app, "index.html") script = soup.find_all("script")[-1].text self.assertIn("plugin_1 = {};", script) self.assertIn( 'plugin_1.src = "_static/revealjs/plugin/highlight/highlight.js"', script) @with_app(**gen_app_conf(confoverrides={"revealjs_style_theme": "moon"})) def test_revealjs_style_theme(self, app: TestApp, status, warning): # noqa soup = soup_html(app, "index.html") links = [ e for e in soup.find_all("link", rel="stylesheet") if "_static/revealjs/css/theme/moon.css" in e["href"] ] self.assertEqual(len(links), 1) @with_app(**gen_app_conf( confoverrides={"revealjs_style_theme": "custom.css"})) def test_revealjs_style_theme(self, app: TestApp, status, warning): # noqa soup = soup_html(app, "index.html") links = [ e for e in soup.find_all("link", rel="stylesheet") if "_static/custom.css" in e["href"] ] self.assertEqual(len(links), 1)
class BuildHtmlTests(unittest.TestCase): # noqa @with_app(**gen_app_conf( confoverrides={"revealjs_script_files": ["js/test.js"]})) def test_script_tags(self, app: TestApp, status, warning): # noqa soup = soup_html(app, "index.html") elements = [ e for e in soup.find_all("script") if e.get("src") == "_static/js/test.js" ] self.assertEqual(len(elements), 1) @with_app(**gen_app_conf( confoverrides={"revealjs_google_fonts": ["Noto Sans JP"]})) def test_google_fonts(self, app, status, warning): # noqa soup = soup_html(app, "index.html") link = [ e for e in soup.find_all("link", rel="stylesheet") if e["href"].startswith("https://fonts.googleapis.com/css2") ] self.assertEqual(len(link), 1) style = soup.find_all("style")[-1] self.assertIn(".reveal", style.text) self.assertIn("Noto Sans JP", style.text) self.assertIn("sans-serif;", style.text) @with_app(**gen_app_conf( confoverrides={ "revealjs_google_fonts": ["Noto Sans JP"], "revealjs_generic_font": "cursive", })) def test_google_fonts_with_generic(self, app, status, warning): # noqa soup = soup_html(app, "index.html") link = [ e for e in soup.find_all("link", rel="stylesheet") if e["href"].startswith("https://fonts.googleapi") ] self.assertEqual(len(link), 1) style = soup.find_all("style")[-1] self.assertIn("Noto Sans JP", style.text) self.assertIn("cursive", style.text) @with_app(**gen_app_conf( confoverrides={"revealjs_generic_font": "cursive"})) def test_generic_font_only(self, app, status, warning): # noqa soup = soup_html(app, "index.html") styles = soup.find_all("style") self.assertEqual(len(styles), 0) @with_app(**gen_app_conf( confoverrides={"revealjs_script_files": ["js/test.js"]})) def test_script_tags(self, app: TestApp, status, warning): # noqa soup = soup_html(app, "index.html") elements = [ e for e in soup.find_all("script") if e.get("src") == "_static/js/test.js" ] self.assertEqual(len(elements), 1) @with_app(**gen_app_conf(confoverrides={ "revealjs_script_files": ["https://example.com/test.js"] })) def test_script_tags_https(self, app: TestApp, status, warning): # noqa soup = soup_html(app, "index.html") elements = [ e for e in soup.find_all("script") if e.get("src") == "https://example.com/test.js" ] self.assertEqual(len(elements), 1) @with_app(**gen_app_conf( confoverrides={"revealjs_script_conf": '{transition:"none"}'})) def test_revealjs_script_conf(self, app: TestApp, status, warning): # noqa soup = soup_html(app, "index.html") self.assertIn( 'Object.assign(revealjsConfig, {transition:"none"});', soup.find_all("script")[-1].text, ) @with_app(**gen_app_conf( confoverrides={ "revealjs_script_plugins": [{ "name": "RevealNotes", "src": "revealjs4/plugin/notes/notes.js", }] })) def test_revealjs_script_plugins(self, app: TestApp, status, warning): # noqa soup = soup_html(app, "index.html") script = soup.find_all("script")[-1].text self.assertIn("RevealNotes", script) for d in soup.find_all("script"): print(d) scripts = [ d["src"] for d in soup.find_all("script") if "src" in d.attrs ] self.assertIn("_static/revealjs4/plugin/notes/notes.js", scripts) @with_app(**gen_app_conf(confoverrides={"revealjs_style_theme": "moon"})) def test_revealjs_style_theme(self, app: TestApp, status, warning): # noqa soup = soup_html(app, "index.html") links = [ e for e in soup.find_all("link", rel="stylesheet") if "_static/revealjs/css/theme/moon.css" in e["href"] ] self.assertEqual(len(links), 1) @with_app(**gen_app_conf( confoverrides={"revealjs_style_theme": "custom.css"})) def test_revealjs_style_theme(self, app: TestApp, status, warning): # noqa soup = soup_html(app, "index.html") links = [ e for e in soup.find_all("link", rel="stylesheet") if "_static/custom.css" in e["href"] ] self.assertEqual(len(links), 1) @with_app(**gen_app_conf(confoverrides={ "revealjs_css_files": ["https://example.com/example.css"] })) def test_revealjs_css_files(self, app: TestApp, status, warning): # noqa soup = soup_html(app, "index.html") links = [ e for e in soup.find_all("link", rel="stylesheet") if "https://example.com/example.css" in e["href"] ] self.assertEqual(len(links), 1) @with_app(**gen_app_conf( confoverrides={ "revealjs_static_path": ["_static"], "revealjs_css_files": ["custom.css"], })) def test_revealjs_css_files_local(self, app: TestApp, status, warning): # noqa soup = soup_html(app, "index.html") links = [ e for e in soup.find_all("link", rel="stylesheet") if "_static/custom.css" in e["href"] ] self.assertEqual(len(links), 1) self.assertTrue((app.outdir / "_static/custom.css").exists())
class BuildHtmlTests(unittest.TestCase): # noqa @with_app(**gen_app_conf()) def test_fragments_generate(self, app: TestApp, status, warning): # noqa soup = soup_html(app, "has_fragments.html") self.assertEqual(len(soup.find_all(attrs={"fragment"})), 3)
class BuildHtmlTests(unittest.TestCase): # noqa @with_app(**gen_app_conf()) def test_defaults(self, app: TestApp, status, warning): # noqa soup = soup_html(app, "index.html") for e in soup.find_all("section"): self.assertNotIn("id", e.attrs) @with_app(**gen_app_conf(confoverrides={"revealjs_script_files": ["js/test.js"]})) def test_script_tags(self, app: TestApp, status, warning): # noqa soup = soup_html(app, "index.html") elements = [ e for e in soup.find_all("script") if e.get("src") == "_static/js/test.js" ] self.assertEqual(len(elements), 1) @with_app(**gen_app_conf(confoverrides={"revealjs_google_fonts": ["Noto Sans JP"]})) def test_google_fonts(self, app, status, warning): # noqa soup = soup_html(app, "index.html") link = [ e for e in soup.find_all("link", rel="stylesheet") if e["href"].startswith("https://fonts.googleapis.com/css2") ] self.assertEqual(len(link), 1) style = soup.find_all("style")[-1] self.assertIn(".reveal", str(style)) self.assertIn("Noto Sans JP", str(style)) self.assertIn("sans-serif;", str(style)) @with_app( **gen_app_conf( confoverrides={ "revealjs_google_fonts": ["Noto Sans JP"], "revealjs_generic_font": "cursive", } ) ) def test_google_fonts_with_generic(self, app, status, warning): # noqa soup = soup_html(app, "index.html") link = [ e for e in soup.find_all("link", rel="stylesheet") if e["href"].startswith("https://fonts.googleapi") ] self.assertEqual(len(link), 1) style = soup.find_all("style")[-1] self.assertIn("Noto Sans JP", str(style)) self.assertIn("cursive", str(style)) @with_app(**gen_app_conf(confoverrides={"revealjs_generic_font": "cursive"})) def test_generic_font_only(self, app, status, warning): # noqa soup = soup_html(app, "index.html") styles = soup.find_all("style") self.assertEqual(len(styles), 0) @with_app(**gen_app_conf(confoverrides={"revealjs_script_files": ["js/test.js"]})) def test_script_tags(self, app: TestApp, status, warning): # noqa soup = soup_html(app, "index.html") elements = [ e for e in soup.find_all("script") if e.get("src") == "_static/js/test.js" ] self.assertEqual(len(elements), 1) @with_app( **gen_app_conf( confoverrides={"revealjs_script_files": ["https://example.com/test.js"]} ) ) def test_script_tags_https(self, app: TestApp, status, warning): # noqa soup = soup_html(app, "index.html") elements = [ e for e in soup.find_all("script") if e.get("src") == "https://example.com/test.js" ] self.assertEqual(len(elements), 1) @with_app( **gen_app_conf(confoverrides={"revealjs_script_conf": '{transition:"none"}'}) ) def test_revealjs_script_conf(self, app: TestApp, status, warning): # noqa soup = soup_html(app, "index.html") self.assertIn( 'Object.assign(revealjsConfig, {transition:"none"});', str(soup.find_all("script")[-1]), ) @with_app( **gen_app_conf( confoverrides={ "revealjs_script_plugins": [ { "name": "RevealNotes", "src": "revealjs4/plugin/notes/notes.js", } ] } ) ) def test_revealjs_script_plugins(self, app: TestApp, status, warning): # noqa soup = soup_html(app, "index.html") script = str(soup.find_all("script")[-1]) self.assertIn("RevealNotes", script) for d in soup.find_all("script"): print(d) scripts = [d["src"] for d in soup.find_all("script") if "src" in d.attrs] self.assertIn("_static/revealjs4/plugin/notes/notes.js", scripts) @with_app(**gen_app_conf(confoverrides={"revealjs_style_theme": "moon"})) def test_revealjs_style_theme_builtin(self, app: TestApp, status, warning): # noqa soup = soup_html(app, "index.html") links = [ e for e in soup.find_all("link", rel="stylesheet") if "_static/revealjs4/dist/theme/moon.css" in e["href"] ] self.assertEqual(len(links), 1) @with_app(**gen_app_conf(confoverrides={"revealjs_style_theme": "custom.css"})) def test_revealjs_style_theme_custom(self, app: TestApp, status, warning): # noqa soup = soup_html(app, "index.html") links = [ e for e in soup.find_all("link", rel="stylesheet") if "_static/custom.css" in e["href"] ] self.assertEqual(len(links), 1) @with_app( **gen_app_conf( confoverrides={"revealjs_css_files": ["https://example.com/example.css"]} ) ) def test_revealjs_css_files(self, app: TestApp, status, warning): # noqa soup = soup_html(app, "index.html") links = [ e for e in soup.find_all("link", rel="stylesheet") if "https://example.com/example.css" in e["href"] ] self.assertEqual(len(links), 1) @with_app( **gen_app_conf( confoverrides={ "revealjs_static_path": ["_static"], "revealjs_css_files": ["custom.css"], } ) ) def test_revealjs_css_files_local(self, app: TestApp, status, warning): # noqa soup = soup_html(app, "index.html") links = [ e for e in soup.find_all("link", rel="stylesheet") if "_static/custom.css" in e["href"] ] self.assertEqual(len(links), 1) self.assertTrue((app.outdir / "_static/custom.css").exists()) @with_app( **gen_app_conf( confoverrides={ "revealjs_static_path": ["_static"], "revealjs_css_files": ["custom.css"], } ) ) def test_default_theme_css_comes_before_custom_css( self, app: TestApp, status, warning ): soup = soup_html(app, "index.html") stylesheet_href_list = [ e["href"] for e in soup.find_all("link", rel="stylesheet") ] default_theme_index = stylesheet_href_list.index( "_static/revealjs4/dist/theme/black.css" ) custom_css_index = stylesheet_href_list.index("_static/custom.css") self.assertTrue(default_theme_index < custom_css_index) @with_app( **gen_app_conf( confoverrides={ "revealjs_style_theme": "moon", "revealjs_static_path": ["_static"], "revealjs_css_files": ["other_custom.css"], } ) ) def test_specified_theme_css_comes_before_custom_css( self, app: TestApp, status, warning ): soup = soup_html(app, "index.html") stylesheet_href_list = [ e["href"] for e in soup.find_all("link", rel="stylesheet") ] specified_theme_index = stylesheet_href_list.index( "_static/revealjs4/dist/theme/moon.css" ) custom_css_index = stylesheet_href_list.index("_static/other_custom.css") self.assertTrue(specified_theme_index < custom_css_index) @with_app( **gen_app_conf( confoverrides={ "revealjs_use_section_ids": True, } ) ) def test_inject_id_to_all_sections(self, app: TestApp, status, warning): # noqa soup = soup_html(app, "index.html") for e in soup.find_all("section"): children = set([c.name for c in e.children]) if children & {"h1", "h2", "h3"}: self.assertIn("id", e.attrs) @with_app( **gen_app_conf( confoverrides={ "revealjs_use_section_ids": True, } ) ) def test_inject_id_to_all_sections_with_label( self, app: TestApp, status, warning ): # noqa soup = soup_html(app, "with_label.html") h2_section = soup.h2.parent self.assertIn("id", h2_section.attrs) self.assertEqual(h2_section["id"], "override-label")