<commit_before>"""Tests for ``_sphinx`` module."""
# pylint: disable=protected-access
import typing as t

import docutils.parsers.rst.directives as docutils_directives
import docutils.parsers.rst.roles as docutils_roles
import pytest

from rstcheck import _extras, _sphinx


if _extras.SPHINX_INSTALLED:
    import sphinx.application


class TestContextManager:
    """Test ``load_sphinx_if_available`` context manager."""

    @staticmethod  # noqa: AAA01
    @pytest.mark.skipif(_extras.SPHINX_INSTALLED, reason="Test without sphinx extra.")
    @pytest.mark.usefixtures("patch_docutils_directives_and_roles_dict")
    def test_yield_nothing_with_sphinx_missing() -> None:
        """Test for ``None`` yield and no action when sphinx is missing."""
        with _sphinx.load_sphinx_if_available() as ctx_manager:

            assert ctx_manager is None
            assert not docutils_directives._directives
            assert not docutils_roles._roles

    @staticmethod  # noqa: AAA01
    @pytest.mark.skipif(not _extras.SPHINX_INSTALLED, reason="Depends on sphinx extra.")
    @pytest.mark.usefixtures("patch_docutils_directives_and_roles_dict")
    def test_yield_nothing_with_sphinx_installed() -> None:
        """Test for ``None`` yield but action when sphinx is installed."""
        len_before = len(sphinx.application.builtin_extensions)
        with _sphinx.load_sphinx_if_available() as ctx_manager:

            assert ctx_manager is None
            assert docutils_directives._directives
            assert docutils_roles._roles
            assert len_before - 1 == len(sphinx.application.builtin_extensions)


class TestSphinxDirectiveAndRoleGetter:<commit_msg>fix test for sphinx.addnodes removal<commit_after>"""Tests for ``_sphinx`` module."""
# pylint: disable=protected-access
import typing as t

import docutils.parsers.rst.directives as docutils_directives
import docutils.parsers.rst.roles as docutils_roles
import pytest

from rstcheck import _extras, _sphinx


if _extras.SPHINX_INSTALLED:
    import sphinx.application


class TestContextManager:
    """Test ``load_sphinx_if_available`` context manager."""

    @staticmethod  # noqa: AAA01
    @pytest.mark.skipif(_extras.SPHINX_INSTALLED, reason="Test without sphinx extra.")
    @pytest.mark.usefixtures("patch_docutils_directives_and_roles_dict")
    def test_yield_nothing_with_sphinx_missing() -> None:
        """Test for ``None`` yield and no action when sphinx is missing."""
        with _sphinx.load_sphinx_if_available() as ctx_manager:

            assert ctx_manager is None
            assert not docutils_directives._directives
            assert not docutils_roles._roles

    @staticmethod  # noqa: AAA01
    @pytest.mark.skipif(not _extras.SPHINX_INSTALLED, reason="Depends on sphinx extra.")
    @pytest.mark.usefixtures("patch_docutils_directives_and_roles_dict")
    def test_yield_nothing_with_sphinx_installed() -> None:
        """Test for ``None`` yield but action when sphinx is installed."""
        with _sphinx.load_sphinx_if_available() as ctx_manager:

            assert ctx_manager is None
            assert docutils_directives._directives
            assert docutils_roles._roles
            assert "sphinx.addnodes" not in sphinx.application.builtin_extensions


class TestSphinxDirectiveAndRoleGetter:
{'fraction_non_alphanumeric': 0.0819523952997891, 'fraction_numerical': 0.0027116601385959627, 'mean_word_length': 3.970059880239521, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1641708', 'n_tokens_mistral': 1074, 'n_tokens_neox': 1035, 'n_words': 232}