<commit_before>from __future__ import absolute_import, division, print_function

import codecs
import os

from bs4 import BeautifulSoup
from zope.interface.verify import verifyObject

from doc2dash.parsers.intersphinx import (
    InterSphinxParser,
    find_and_patch_entry,
    _inv_to_entries,
)
from doc2dash.parsers.utils import IParser, ParserEntry, TOCEntry


HERE = os.path.dirname(__file__)


class TestInterSphinxParser(object):
    def test_interface(self):
        """
        InterSphinxParser fully implements IParser.
        """
        verifyObject(IParser, InterSphinxParser(doc_path="foo"))

    def test_parses(self):
        """
        Parsing of the example objects.inv in the current directory does not
        fail.
        """
        p = InterSphinxParser(doc_path=os.path.join(HERE))
        assert [] != list(p.parse())

    def test_inv_to_entries(self):
        """
        Inventory items are correctly converted.
        """
        result = list(
            _inv_to_entries({"py:method": {
                u"some_method": (None, None, u"some_module.py", u"-"),
            }, "std:option": {
                u"--destination": (
                    u"doc2dash",
                    u"2.0",
                    u"index.html#document-usage#cmdoption--destination",
                    u"-"
                )
            }, "std:constant": {
                u"SomeConstant": (None, None, u"some_other_module.py", u"-")
            }})
        )
        assert set([ParserEntry(
            name=u'some_method', type=u'Method', path=u'some_module.py'
            ),
            ParserEntry(
                name=u'--destination',
                type=u'Option',
                path=u'index.html#cmdoption--destination'
            ),
            ParserEntry(
            name=u'SomeConstant', type=u'Constant', path=u'some_other_module.py'
            )
        ]) == set(result)


class TestFindAndPatchEntry(object):
    def test_patch_method(self):
        """
        Patching a method adds a TOC entry.
        """<commit_msg>Pacify flake8<commit_after>from __future__ import absolute_import, division, print_function

import codecs
import os

from bs4 import BeautifulSoup
from zope.interface.verify import verifyObject

from doc2dash.parsers.intersphinx import (
    InterSphinxParser,
    find_and_patch_entry,
    _inv_to_entries,
)
from doc2dash.parsers.utils import IParser, ParserEntry, TOCEntry


HERE = os.path.dirname(__file__)


class TestInterSphinxParser(object):
    def test_interface(self):
        """
        InterSphinxParser fully implements IParser.
        """
        verifyObject(IParser, InterSphinxParser(doc_path="foo"))

    def test_parses(self):
        """
        Parsing of the example objects.inv in the current directory does not
        fail.
        """
        p = InterSphinxParser(doc_path=os.path.join(HERE))
        assert [] != list(p.parse())

    def test_inv_to_entries(self):
        """
        Inventory items are correctly converted.
        """
        result = list(
            _inv_to_entries({"py:method": {
                u"some_method": (None, None, u"some_module.py", u"-"),
            }, "std:option": {
                u"--destination": (
                    u"doc2dash",
                    u"2.0",
                    u"index.html#document-usage#cmdoption--destination",
                    u"-"
                )
            }, "std:constant": {
                u"SomeConstant": (None, None, u"some_other_module.py", u"-")
            }})
        )
        assert set([ParserEntry(
            name=u'some_method', type=u'Method', path=u'some_module.py'
            ),
            ParserEntry(
                name=u'--destination',
                type=u'Option',
                path=u'index.html#cmdoption--destination'
            ),
            ParserEntry(
                name=u'SomeConstant',
                type=u'Constant',
                path=u'some_other_module.py',
            )
        ]) == set(result)


class TestFindAndPatchEntry(object):
    def test_patch_method(self):
        """
        Patching a method adds a TOC entry.
        """
{'fraction_non_alphanumeric': 0.11271329007450132, 'fraction_numerical': 0.0031242489786109107, 'mean_word_length': 1.902370990237099, 'pattern_counts': {'":': 12, '<': 3, '<?xml version=': 0, '>': 3, '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': '5822331', 'n_tokens_mistral': 1235, 'n_tokens_neox': 1182, 'n_words': 225}