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 0000000..c0f08bd Binary files /dev/null and b/tests/roots/test-msapp_meta/gfx/mstile-150x150.png differ 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