def test_no_requirements_demo(
    page: BeautifulSoup,
    html_regression: HTMLRegressionFixture,
) -> None:
    # Make sure the page title is what you expect
    title = page.find("h1").contents[0].strip()
    assert "No Requirements Demo" == title

    # Now test the directive
    for div in page.findAll("div"):
        assert not div.get("id", '').startswith("extras_require")

    html_regression.check(page, jinja2=True)
def _do_test_directive(
    page: BeautifulSoup,
    requirements: List[str],
    extra: str,
    html_regression: HTMLRegressionFixture,
) -> None:

    div_count = 0

    for div in page.findAll("div"):
        if not div.get("id", '').startswith("extras_require"):
            continue

        assert div.findAll('p')[0].contents == ["Attention"]
        assert div.findAll('p')[0]["class"] == ["admonition-title"]
        assert div.findAll('p')[1].contents == [
            "This module has the following additional requirements:"
        ]

        assert div.div["class"] == ["highlight-text", "notranslate"]
        assert div.div.div["class"] == ["highlight"]
        assert div.div.div.pre.contents[1:] == ['\n'.join(requirements) + '\n']

        assert div.findAll('p')[2].contents == [
            "These can be installed as follows:"
        ]

        assert div.blockquote.div.div["class"] == [
            "highlight-default", "notranslate"
        ]
        assert div.blockquote.div.div.div["class"] == ["highlight"]

        expected_instructions = [
            Tag(name="span"), "$ python -m pip install Python",
            Tag(name="span", attrs={"class": ['o']}), extra,
            Tag(name="span", attrs={"class": ['o']}), '\n'
        ]
        expected_instructions[2].string = '['
        expected_instructions[4].string = ']'

        assert div.blockquote.div.div.div.pre.contents == expected_instructions

        div_count += 1

    assert div_count == 1

    html_regression.check(page, jinja2=True)
Exemplo n.º 3
0
def test_html_output(testing_app, html_regression: HTMLRegressionFixture):
    """
	Parametrize new files here rather than as their own function.
	"""

    with pytest.warns(UserWarning,
                      match="(No codes specified|No such code 'F401')"):
        testing_app.build(force_all=True)

    caught_exceptions: List[BaseException] = []

    for page in pages_to_check:
        pagename: str = page.values[0]  # type: ignore
        is_template: bool = page.values[1]  # type: ignore
        page_id: str = page.id or pagename

        for mark in page.marks:
            if mark.kwargs.get("condition", False):
                if "reason" in mark.kwargs:
                    print(f"Skipping {page_id!r}: {mark.kwargs['reason']}")

                    break
                else:
                    print(f"Skipping {page_id!r}")
                    break
        else:
            print(f"Checking output for {page_id}")
            page_id = page_id.replace('.', '_').replace('-', '_')
            content = (testing_app.outdir / pagename).read_text()
            try:
                html_regression.check(
                    BeautifulSoup(content, "html5lib"),
                    extension=f"_{page_id}_.html",
                    jinja2=is_template,
                )
            except BaseException as e:
                caught_exceptions.append(e)

        continue

    print(caught_exceptions)

    for exception in caught_exceptions:
        raise exception
def test_html_output(gh_src_app, html_regression: HTMLRegressionFixture):
    """
	Parametrize new files here rather than as their own function.
	"""

    gh_src_app.build(force_all=True)

    caught_exceptions: List[BaseException] = []

    for page in pages_to_check:
        if isinstance(page, str):
            page = pytest.param(page, id=page)

        pagename: str = page.values[0]  # type: ignore
        page_id: str = page.id or pagename
        for mark in page.marks:
            if mark.kwargs.get("condition", False):
                if "reason" in mark.kwargs:
                    print(f"Skipping {page_id!r}: {mark.kwargs['reason']}")

                    break
                else:
                    print(f"Skipping {page_id!r}")
                    break
        else:
            print(f"Checking output for {page_id}")
            page_id = page_id.replace('.', '_').replace('-', '_')
            content = (gh_src_app.outdir / pagename).read_text()
            try:
                html_regression.check(
                    BeautifulSoup(content, "html5lib"),
                    extension=f"_{page_id}_.html",
                    jinja2=True,
                )
            except BaseException as e:
                caught_exceptions.append(e)

        continue

    print(caught_exceptions)

    for exception in caught_exceptions:
        raise exception
def test_output_sphinx(sphinx_source_page: BeautifulSoup, html_regression: HTMLRegressionFixture):
	# Make sure the page title is what you expect
	title = sphinx_source_page.find("h1").contents[0].strip()
	assert "sphinx-toolbox Demo - Sphinx source" == title

	tag_count = 0

	for a_tag in sphinx_source_page.select("a.reference.internal"):
		if tag_count == 0:
			if a_tag.contents[0] == "sphinx_toolbox/config.py":
				assert a_tag["href"] == "_modules/sphinx_toolbox/config.html#sphinx_toolbox/config.py"
		elif tag_count == 1:
			if a_tag.contents[0] == "source code":
				assert a_tag["href"] == "_modules/sphinx_toolbox/config.html#sphinx_toolbox/config.py"
		tag_count += 1

	assert tag_count == 4

	html_regression.check(sphinx_source_page)
def test_output_github(github_source_page: BeautifulSoup,
                       html_regression: HTMLRegressionFixture):
    # Make sure the page title is what you expect
    title = github_source_page.find("h1").contents[0].strip()
    assert "sphinx-toolbox Demo" == title

    tag_count = 0

    for a_tag in github_source_page.select("a.reference.external"):
        if tag_count == 0:
            if a_tag.contents[0] == "sphinx_toolbox/config.py":
                assert a_tag[
                    "href"] == "https://github.com/domdfcoding/sphinx-toolbox/blob/master/sphinx_toolbox/config.py"
        elif tag_count == 1:
            if a_tag.contents[0] == "source code":
                assert a_tag[
                    "href"] == "https://github.com/domdfcoding/sphinx-toolbox/blob/master/sphinx_toolbox/config.py"
        tag_count += 1

    assert tag_count == 2

    html_regression.check(github_source_page)
def test_output_github(github_source_page: BeautifulSoup,
                       html_regression: HTMLRegressionFixture):
    # Make sure the page title is what you expect
    title = github_source_page.find("h1").contents[0].strip()
    assert "sphinx-toolbox Demo - GitHub Issues" == title

    links = github_source_page.select('p')
    assert len(links) == 7

    assert links[1] == links[2]

    assert links[0].abbr["title"] == "Example Issue"  # check the abbr tag
    assert links[0].abbr.a["class"] == ["reference",
                                        "external"]  # check the a tag's class
    assert links[0].abbr.a[
        "href"] == "https://github.com/domdfcoding/sphinx-toolbox/issues/1"  # check the a tag's href
    assert links[0].abbr.a.contents[0] == "#1"  # check the body

    assert [str(x) for x in links] == [
        '<p><abbr title="Example Issue"><a class="reference external" '
        'href="https://github.com/domdfcoding/sphinx-toolbox/issues/1">#1</a></abbr></p>',
        '<p><abbr title="Example Pull Request"><a class="reference external" '
        'href="https://github.com/domdfcoding/sphinx-toolbox/pull/2">#2</a></abbr></p>',
        '<p><abbr title="Example Pull Request"><a class="reference external" '
        'href="https://github.com/domdfcoding/sphinx-toolbox/pull/2">#2</a></abbr></p>',
        '<p><abbr title="Add --log-cli option"><a class="reference external" '
        'href="https://github.com/pytest-dev/pytest/issues/7680">pytest-dev/pytest#7680</a></abbr></p>',
        '<p><abbr title="RFC: python: skip work pytest_pycollect_makeitem work on certain names"><a '
        'class="reference external" href="https://github.com/pytest-dev/pytest/issues/7671">pytest-dev/pytest#7671</a></abbr></p>',
        '<p><a class="reference external" '
        'href="https://github.com/domdfcoding/sphinx-toolbox/blob/master/sphinx_toolbox/source.py">sphinx_toolbox/source.py</a></p>',
        '<p><a class="reference external" '
        'href="https://github.com/domdfcoding/sphinx-toolbox/blob/master/sphinx_toolbox/more_autodoc/__init__.py">sphinx_toolbox/more_autodoc/__init__.py</a></p>',
    ]

    html_regression.check(github_source_page)
def test_output(page: BeautifulSoup,
                html_regression: HTMLRegressionFixture) -> None:

    html_regression.check(page, jinja2=True)