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")
def test_script_tags(app, 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" ] assert len(elements) == 1
def setUpClass(cls): # noqa cls.app = TestApp( srcdir=str(PROJECT_ROOT / "demo/revealjs4"), buildername="revealjs", copy_srcdir_to_tmpdir=True, ) cls.soup = soup_html(cls.app, "index.html")
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)
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)
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 )
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)
def test_revealjs_style_theme_custom(app, 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"] ] assert len(links) == 1
def test_revealjs_script_plugins(app, status, warning): # noqa soup = soup_html(app, "index.html") script = str(soup.find_all("script")[-1]) assert "RevealNotes" in 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] assert "_static/revealjs4/plugin/notes/notes.js" in scripts
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)
def test_revealjs_css_files_local(app, 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"] ] assert len(links) == 1 assert (app.outdir / "_static/custom.css").exists()
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)
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)
def test_override_font(app, 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") ] assert len(css_hrefs) == 1 styles = "\n".join([str(e) for e in soup.find_all("style")]) assert "'M PLUS 1p'" in styles
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())
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)
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)
def test_priority_html_and_revealjs_js_files(app, status, warning): # noqa soup = soup_html(app, "index.html") elm = soup.find( "script", src="https://cdnjs.cloudflare.com/ajax/libs/dayjs/1.10.6/dayjs.min.js") assert elm is not None elm = soup.find( "script", src="https://cdnjs.cloudflare.com/ajax/libs/dayjs/1.10.7/dayjs.min.js") assert elm is None
def test_specified_theme_css_comes_before_custom_css(app, status, warning): # noqa 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") assert specified_theme_index < custom_css_index
def test_google_fonts_with_generic(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") ] assert len(link) == 1 style = soup.find_all("style")[-1] assert "Noto Sans JP" in str(style) assert "cursive" in str(style)
def test_google_fonts(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") ] assert len(link) == 1 style = soup.find_all("style")[-1] assert ".reveal" in str(style) assert "Noto Sans JP" in str(style) assert "sans-serif;" in str(style)
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))
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", soup.find_all("script")[-1].text, ) self.assertIn( '"transition": "none"\n', soup.find_all("script")[-1].text, ) self.assertIn( "});", soup.find_all("script")[-1].text, )
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")
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)
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, )
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)
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)
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)
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]), )