From 6fcecc5ee2c919c23ceffd5a677bac6474e579c1 Mon Sep 17 00:00:00 2001 From: Timo Cornelius Metzger <39711796+tcmetzger@users.noreply.github.com> Date: Thu, 23 Feb 2023 16:55:04 -0800 Subject: [PATCH] Update tests (#37) * Update static image test * Add msapp test * add cov report to nox and github testing * lint --------- Co-authored-by: Pierrick Rambaud --- .github/workflows/basic-ci.yml | 6 ++--- noxfile.py | 2 +- pyproject.toml | 8 ++++-- tests/__init__.py | 0 tests/conftest.py | 12 +++++++++ tests/roots/test-msapp_meta/conf.py | 13 ++++++++++ .../test-msapp_meta/gfx/mstile-150x150.png | Bin 0 -> 3961 bytes tests/roots/test-msapp_meta/index.rst | 1 + tests/roots/test-static_files/conf.py | 9 +++---- tests/test_options.py | 24 ++++++++++++++++-- 10 files changed, 61 insertions(+), 14 deletions(-) create mode 100644 tests/__init__.py create mode 100644 tests/roots/test-msapp_meta/conf.py create mode 100644 tests/roots/test-msapp_meta/gfx/mstile-150x150.png create mode 100644 tests/roots/test-msapp_meta/index.rst diff --git a/.github/workflows/basic-ci.yml b/.github/workflows/basic-ci.yml index 7eb4bf0..1440566 100644 --- a/.github/workflows/basic-ci.yml +++ b/.github/workflows/basic-ci.yml @@ -14,7 +14,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 with: - python-version: '3.8' + python-version: '3.8' - uses: pre-commit/action@v3.0.0 test: @@ -36,9 +36,9 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install dependencies run: pip install .[test] - - name: MyPy checks + - name: MyPy checks run: | pip install mypy mypy --ignore-missing-imports --install-types --non-interactive sphinx_favicon - name: Run Tests for ${{ matrix.python-version }} - run: pytest --color=yes tests + run: pytest --color=yes --cov --cov-report=xml tests diff --git a/noxfile.py b/noxfile.py index 8e1d324..29126b5 100644 --- a/noxfile.py +++ b/noxfile.py @@ -8,7 +8,7 @@ def test(session): """Apply the tests on the lib.""" session.install(".[test]") test_files = session.posargs or ["tests"] - session.run("pytest", "--color=yes", *test_files) + session.run("pytest", "--color=yes", "--cov", "--cov-report=html", *test_files) @nox.session(name="mypy", reuse_venv=True) diff --git a/pyproject.toml b/pyproject.toml index 1778a09..bccc330 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -47,20 +47,24 @@ Download = "https://github.com/tcmetzger/sphinx-favicon/archive/v${metadata:vers [project.optional-dependencies] dev = ["pre-commit", "nox"] -test = ["pytest", "beautifulsoup4"] +test = ["pytest", "beautifulsoup4", "pytest-cov"] doc = ["sphinx<6", "pydata-sphinx-theme", "sphinx-copybutton", "sphinx-design"] [tool.setuptools] license-files = ["LICENSE"] +packages = ["sphinx_favicon"] [tool.ruff] fix = true select = ["E", "F", "W", "I", "D", "RUF"] ignore = ["E501"] # line too long | Black take care of it -exclude = ["setup.py", "tests/roots/*"] +exclude = ["setup.py", "tests/roots/*", "tests/__init__.py"] [tool.ruff.flake8-quotes] docstring-quotes = "double" [tool.ruff.pydocstyle] convention = "google" + +[tool.coverage.run] +source = ["sphinx_favicon"] diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/conftest.py b/tests/conftest.py index 521d99f..3725fff 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -35,12 +35,24 @@ def _favicon_tags(content, page="index.html"): ] +def _meta_tags(content, page): + """Link tags in a page content.""" + c = (content.outdir / page).read_text() + return BeautifulSoup(c, "html.parser").find_all("meta") + + @pytest.fixture() def link_tags(content): """Link tags in index.html page.""" return _link_tags(content, "index.html") +@pytest.fixture() +def meta_tags(content): + """Meta tags in index.html page.""" + return _meta_tags(content, "index.html") + + @pytest.fixture() def favicon_tags(content): """Favicon tags in index.html page.""" diff --git a/tests/roots/test-msapp_meta/conf.py b/tests/roots/test-msapp_meta/conf.py new file mode 100644 index 0000000..759456f --- /dev/null +++ b/tests/roots/test-msapp_meta/conf.py @@ -0,0 +1,13 @@ +extensions = ["sphinx_favicon"] + +master_doc = "index" +exclude_patterns = ["_build"] + +html_theme = "basic" +html_static_path = ["gfx"] + +favicons = [ + "mstile-150x150.png", + {"name": "msapplication-TileColor", "content": "#2d89ef"}, + {"name": "theme-color", "content": "#ffffff"}, +] diff --git a/tests/roots/test-msapp_meta/gfx/mstile-150x150.png b/tests/roots/test-msapp_meta/gfx/mstile-150x150.png new file mode 100644 index 0000000000000000000000000000000000000000..c0f08bd768593c37c4c8b7ff013ba6061cac5426 GIT binary patch literal 3961 zcmb7Hz6P>A|KVZg?U~19I%Lq|U4E{2vWJkvskS)ygQPcBY%dX4u z1XnR!>&5D-U!2`W$A&+-V^@upXvAZ$&=oVuNd*j~a z3TdD>^|x2rLa)-@Go<{b_$yC?85XtP_4Am0>%{=kC^hTcDMvt}tw>1Y!pAzFDx3ul zqJtN7{?b{8T3W5M_Nogp{oC)N;V^Je(`|G(;gU#6s5P>~qCO2@1tLT5S99+_yV|=%NU7uYSKl zE+*e}V$WAJ5Jc@m%sk_3yhJP(7PE5KQ3|GaJPA$KA>5?)3W2E?iO{tN3-((IXh4%p zZ8FEQZ+}zoC^Zx;up+k10{AZ%Qlz1tHsBht0q8nnGr9byP@wef zg8oG~^FIJJ1z&~#6Ul<%#yVtMKn_xRS|q_t_@5U7*VeEMpWiQx$gujv_)LxT5zm*+ z*knQO6io(T91$^ZIYAdGQ!ZeQ^eoTLs7i8&LBAU4*Wv0BFFM}3>wDV0lSn2_g-XT> zzSUnKPrMhqN>08j5%UfCS7FQj^HA#HZ!~&&|4PBxYNpxkkyF_6^8UuDV&z8(>Vf~? zrM}&EaU2ul#Ps&L_R+mX+}?)1y>mhR7^DhpBjWO|ZpBKw0<(c}F?<-l77ki!knqFn zo+pg9G>uptJ1P+?je7%!L9oCBT916_iZsrKF4GPBbVjAJ7&&= zNP-g~uJ5WTMDg=^Vn|-^MsX9ZB==^hwgZQpG&=Z3f=-ckw*mRHy1Z2~RQX7#kyX;x z4=A^b^{F?h6{Ff1fRr9G5W+b(G&dUhI#m;7sl)lr*he%S#WzanB`oD3dfu!R7Tu<7 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=A;K6(M$ zy@~54UcxZr5=i_OwFH$jwL5t__eGLz&z&Fi8;w`r^NyXbpgOrB{y8bgj1Ut_D0ES! z)m+6laaYmkmxav4Tm|XG%bh*~BcVsg7^Ii_eZ(m5oZ$rem(`uxAMoE}%8vzhM>bEg zNzN(`jxOEmZs#2y$|BnhV+x2Wc4h2rV3PF@;#_6tRI<@cg>By@;5TYk`d@B>VXzyT z_1Q`~2%dY+-cJ)drP8QJ!oHCxYr32hq*jg&{dOEcCjUYJCdb-ir#FOikP898Q|G-D+qC&)VU7XDvL=4dz? Z*zk9_lvv#T-#7yR;5sJSSWTDM{{wISXBPkf literal 0 HcmV?d00001 diff --git a/tests/roots/test-msapp_meta/index.rst b/tests/roots/test-msapp_meta/index.rst new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/roots/test-msapp_meta/index.rst @@ -0,0 +1 @@ + diff --git a/tests/roots/test-static_files/conf.py b/tests/roots/test-static_files/conf.py index ae261a1..ddcc55e 100644 --- a/tests/roots/test-static_files/conf.py +++ b/tests/roots/test-static_files/conf.py @@ -9,14 +9,11 @@ favicons = [ { "sizes": "32x32", - "static-file": "square.svg", + "href": "square.svg", # use href }, { "sizes": "128x128", - "static-file": "nested/triangle.svg", - }, - { - "sizes": "32x32", - "href": "circle.svg", + "static-file": "nested/triangle.svg", # use outdated static-file }, + "circle.svg", # use nothing but filename ] diff --git a/tests/test_options.py b/tests/test_options.py index 63c2145..39a7de8 100644 --- a/tests/test_options.py +++ b/tests/test_options.py @@ -117,12 +117,11 @@ def test_static_files(app, favicon_tags, favicon_tags_for_nested): # this test should have 2 favicons assert len(favicon_tags) == 3 - # all favicons should have rel, href, type, and sizes attributes + # all favicons should have rel, href, and type attributes for favicon_tag in chain(favicon_tags, favicon_tags_for_nested): assert favicon_tag["rel"] == ["icon"] assert "_static" in favicon_tag["href"] assert favicon_tag["type"] == "image/svg+xml" - assert favicon_tag["sizes"] assert "static-file" not in favicon_tag for favicon_tag in favicon_tags: @@ -167,3 +166,24 @@ def test_href_and_static(app, favicon_tags, favicon_tags_for_nested): static = Path(app.outdir, "_static") assert (static / "square.svg").exists() assert (static / "nested/triangle.svg").exists() + + +@pytest.mark.sphinx("html", testroot="msapp_meta") +def test_msapp_meta(favicon_tags, meta_tags): + """Run tests on a favicon configuration with meta. + + Args: + favicon_tags: Favicon tags in index.html page. + meta_tags: Meta tags in index.html page. + """ + # this test should have 1 link tag + assert len(favicon_tags) == 1 + + # get all values from meta tags and check for expected values + tag_values = [] + for tag in meta_tags: + tag_values.extend(list(tag.attrs.values())) + assert "msapplication-TileColor" in tag_values + assert "#2d89ef" in tag_values + assert "theme-color" in tag_values + assert "#ffffff" in tag_values