Skip to content

Commit

Permalink
[refactor] Parametrize builder to make DRY
Browse files Browse the repository at this point in the history
  • Loading branch information
ftnext committed Oct 10, 2023
1 parent 0eb5942 commit 741dd8c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 39 deletions.
13 changes: 0 additions & 13 deletions tests/sphinx_new_tab_link/test_build_dirhtml.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,3 @@ def test_should_open_new_tab(
assert "external" in ref["class"]
assert ref["target"] == "_blank"
assert ref["rel"] == ["noopener", "noreferrer"]


@pytest.mark.sphinx("dirhtml", testroot="default")
def test_internal_link_should_not_open_new_tab(app: SphinxTestApp):
app.build()
html = (app.outdir / "index.html").read_text()
soup = BeautifulSoup(html, "html.parser")
references = soup.find_all("a", {"class": "reference"})

ref = references[-1]
assert "internal" in ref["class"]
assert "target" not in ref.attrs
assert "rel" not in ref.attrs
13 changes: 0 additions & 13 deletions tests/sphinx_new_tab_link/test_build_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,3 @@ def test_should_open_new_tab(
assert "external" in ref["class"]
assert ref["target"] == "_blank"
assert ref["rel"] == ["noopener", "noreferrer"]


@pytest.mark.sphinx("html", testroot="default")
def test_internal_link_should_not_open_new_tab(app: SphinxTestApp):
app.build()
html = (app.outdir / "index.html").read_text()
soup = BeautifulSoup(html, "html.parser")
references = soup.find_all("a", {"class": "reference"})

ref = references[-1]
assert "internal" in ref["class"]
assert "target" not in ref.attrs
assert "rel" not in ref.attrs
13 changes: 0 additions & 13 deletions tests/sphinx_new_tab_link/test_build_singlehtml.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,3 @@ def test_should_open_new_tab(
assert "external" in ref["class"]
assert ref["target"] == "_blank"
assert ref["rel"] == ["noopener", "noreferrer"]


@pytest.mark.sphinx("singlehtml", testroot="default")
def test_internal_link_should_not_open_new_tab(app: SphinxTestApp):
app.build()
html = (app.outdir / "index.html").read_text()
soup = BeautifulSoup(html, "html.parser")
references = soup.find_all("a", {"class": "reference"})

ref = references[-1]
assert "internal" in ref["class"]
assert "target" not in ref.attrs
assert "rel" not in ref.attrs
27 changes: 27 additions & 0 deletions tests/test_sphinx_new_tab_link.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import shutil

import pytest
from bs4 import BeautifulSoup


@pytest.mark.parametrize("builder", ["html", "singlehtml", "dirhtml"])
def test_internal_link_should_not_open_new_tab(
make_app, sphinx_test_tempdir: str, rootdir: str, builder: str
):
testroot = "default"
srcdir = sphinx_test_tempdir / testroot
if not srcdir.exists():
testroot_path = rootdir / f"test-{testroot}"
shutil.copytree(testroot_path, srcdir)

app = make_app(builder, srcdir=srcdir)
app.build()

html = (app.outdir / "index.html").read_text()
soup = BeautifulSoup(html, "html.parser")
references = soup.find_all("a", {"class": "reference"})

ref = references[-1]
assert "internal" in ref["class"]
assert "target" not in ref.attrs
assert "rel" not in ref.attrs

0 comments on commit 741dd8c

Please sign in to comment.