Skip to content

Commit

Permalink
Update tests (#37)
Browse files Browse the repository at this point in the history
* Update static image test

* Add msapp test

* add cov report to nox and github testing

* lint

---------

Co-authored-by: Pierrick Rambaud <[email protected]>
  • Loading branch information
tcmetzger and 12rambau authored Feb 24, 2023
1 parent 7fd259f commit 6fcecc5
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 14 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/basic-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]

test:
Expand All @@ -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
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Empty file added tests/__init__.py
Empty file.
12 changes: 12 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
13 changes: 13 additions & 0 deletions tests/roots/test-msapp_meta/conf.py
Original file line number Diff line number Diff line change
@@ -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"},
]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tests/roots/test-msapp_meta/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

9 changes: 3 additions & 6 deletions tests/roots/test-static_files/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
24 changes: 22 additions & 2 deletions tests/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

0 comments on commit 6fcecc5

Please sign in to comment.