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)
Exemple #2
0
def entries():
    """
    Test `ParserEntry`s
    """
    return [
        ParserEntry(name=u'foo', type=u'Method', path=u'bar.html#foo'),
        ParserEntry(name=u'qux', type=u'Class', path=u'bar.html'),
    ]
Exemple #3
0
def entries():
    """
    Test `ParserEntry`s
    """
    return [
        ParserEntry(name="foo", type="Method", path="bar.html#foo"),
        ParserEntry(name="qux", type="Class", path="bar.html"),
    ]
Exemple #4
0
    def test_convert_type_override(self):
        """
        `convert_type` can be overridden.

        We check that we can hide some key of choice.
        """
        class MyInterSphinxParser(InterSphinxParser):
            def convert_type(self, inv_type):
                if inv_type == "py:method":
                    # hide method entries
                    return
                return super(MyInterSphinxParser, self).convert_type(inv_type)

        p = MyInterSphinxParser(doc_path=os.path.join(HERE))
        result = list(
            p._inv_to_entries({
                "py:method": {
                    "some_method": (None, None, "some_module.py", "-")
                },
                "std:constant": {
                    "SomeConstant": (
                        None,
                        None,
                        "some_other_module.py",
                        "-",
                    )
                },
            }))
        assert [
            ParserEntry(
                name="SomeConstant",
                type="Constant",
                path="some_other_module.py",
            )
        ] == result
Exemple #5
0
    def test_create_entry_none(self):
        """
        `create_entry` can return None.
        """
        class MyInterSphinxParser(InterSphinxParser):
            def create_entry(self, dash_type, key, inv_entry):
                if dash_type == "Option":
                    return
                return super(MyInterSphinxParser,
                             self).create_entry(dash_type, key, inv_entry)

        p = MyInterSphinxParser(doc_path=os.path.join(HERE))
        result = list(
            p._inv_to_entries({
                "py:method": {
                    "some_method": (None, None, "some_module.py", "-")
                },
                "std:option": {
                    "--destination": (
                        "doc2dash",
                        "2.0",
                        "index.html#document-usage#cmdoption--"
                        "destination",
                        "-",
                    )
                },
            }))
        assert [
            ParserEntry(name="some_method",
                        type="Method",
                        path="some_module.py")
        ] == result
Exemple #6
0
    def test_create_entry_override(self):
        """
        `create_entry` has the expected interface and can be overridden.

        We check that the name format can be adjusted.
        """
        class MyInterSphinxParser(InterSphinxParser):
            def create_entry(self, dash_type, key, inv_entry):
                path_str = inv_entry_to_path(inv_entry)
                return ParserEntry(name=f"!{key}!",
                                   type=dash_type,
                                   path=path_str)

        p = MyInterSphinxParser(doc_path=os.path.join(HERE))
        result = list(
            p._inv_to_entries({
                "py:method": {
                    "some_method": (None, None, "some_module.py", "-")
                }
            }))
        assert [
            ParserEntry(name="!some_method!",
                        type="Method",
                        path="some_module.py")
        ] == result
Exemple #7
0
 def test_inv_to_entries(self):
     """
     Inventory items are correctly converted.
     """
     p = InterSphinxParser(doc_path=os.path.join(HERE))
     result = list(
         p._inv_to_entries({
             "py:method": {
                 "some_method": (None, None, "some_module.py", "-")
             },
             "std:option": {
                 "--destination": (
                     "doc2dash",
                     "2.0",
                     "index.html#document-usage#cmdoption--"
                     "destination",
                     "-",
                 )
             },
             "std:constant": {
                 "SomeConstant": (
                     None,
                     None,
                     "some_other_module.py",
                     "-",
                 )
             },
         }))
     assert {
         ParserEntry(
             name="some_method",
             type="Method",
             path="some_module.py",
         ),
         ParserEntry(
             name="--destination",
             type="Option",
             path="index.html#cmdoption--destination",
         ),
         ParserEntry(
             name="SomeConstant",
             type="Constant",
             path="some_other_module.py",
         ),
     } == set(result)
 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"-"),
             }
         }))
     assert [
         ParserEntry(name=u'some_method',
                     type=u'Method',
                     path=u'some_module.py')
     ] == result
Exemple #9
0
from doc2dash.parsers.utils import IParser, TOCEntry, ParserEntry


HERE = os.path.dirname(__file__)


class TestPyDoctorParser(object):
    def test_interface(self):
        """
        PyDoctorParser fully implements IParser.
        """
        verifyObject(IParser, PyDoctorParser(doc_path=u"foo"))


EXAMPLE_PARSE_RESULT = [
    ParserEntry(name=t[0], type=t[1], path=t[2])
    for t in [
        (u'twisted.conch.insults.insults.ServerProtocol'
         u'.ControlSequenceParser.A', types.METHOD,
         u'twisted.conch.insults.insults.ServerProtocol'
         u'.ControlSequenceParser.html#A'),
        (u'twisted.test.myrebuilder1.A', types.CLASS,
         u'twisted.test.myrebuilder1.A.html'),
        (u'twisted.test.myrebuilder2.A', types.CLASS,
         u'twisted.test.myrebuilder2.A.html'),
        (u'twisted.test.test_jelly.A', types.CLASS,
         u'twisted.test.test_jelly.A.html'),
        (u'twisted.test.test_persisted.A', types.CLASS,
         u'twisted.test.test_persisted.A.html'),
        (u'twisted.internet.task.LoopingCall.a', types.VARIABLE,
         u'twisted.internet.task.LoopingCall.html#a'),
Exemple #10
0
 def parse(self):
     yield ParserEntry(name="testmethod", type="cm", path="testpath")
Exemple #11
0
 def create_entry(self, dash_type, key, inv_entry):
     path_str = inv_entry_to_path(inv_entry)
     return ParserEntry(name=f"!{key}!",
                        type=dash_type,
                        path=path_str)
Exemple #12
0
 def parse(self):
     yield ParserEntry(name=u'testmethod', type=u'cm', path=u'testpath')