예제 #1
0
 def setUp(self):
     self.code1 = CodeParser(os.path.join(DATA_PATH, "module1.py"))
예제 #2
0
class TestCodeParser(object):
    def setUp(self):
        self.code1 = CodeParser(os.path.join(DATA_PATH, "module1.py"))

    def test_modules(self):
        assert self.code1.modules == ["module1"]

    def test_classes(self):
        assert self.code1.classes == ["module1.Class1", "module1.Class2", "module1.Class3"]

    def test_methods(self):
        assert self.code1.methods == [
            "module1.Class1.__init__",
            "module1.Class1.__another_method__",
            "module1.Class1.method1",
            "module1.Class1.method2",
            "module1.Class1.method3",
            "module1.Class1.method4",
            "module1.Class1.method5",
        ]

    def test_functions(self):
        assert self.code1.functions == [
            "module1.func1",
            "module1.func2",
            "module1.func3",
            "module1.func4",
            "module1.__func5__",
            "module1.func6",
            "module1.func7",
            "module1.func8",
            "module1.outer_function",
            "module1.outer_function.inner_function",
        ]

    def test_count(self):
        assert self.code1.object_count() == 21
        assert self.code1.docstring_count() == 17
        assert self.code1.docstring_count_by_type("reST") == 2
        assert self.code1.docstring_count_by_type("epytext") == 3
        assert self.code1.docstring_count_by_type("javadoc") == 2

    def test_docstrings(self):
        objects_with_docstrings = [
            "module1",
            "module1.Class1",
            "module1.Class2",
            "module1.Class3",
            "module1.Class1.__init__",
            "module1.Class1.__another_method__",
            "module1.Class1.method1",
            "module1.Class1.method2",
            "module1.Class1.method3",
            "module1.Class1.method5",
            "module1.func1",
            "module1.func2",
            "module1.func3",
            "module1.__func5__",
            "module1.func7",
            "module1.func8",
            "module1.outer_function.inner_function",
        ]
        objects_with_rest_docstrings = ["module1.Class1.method5", "module1.func7"]
        objects_with_epytext_docstrings = ["module1", "module1.Class3", "module1.func8"]
        objects_with_javadoc_docstrings = ["module1.Class1", "module1.func8"]  # intentional overlap with epytext

        print(self.code1.docstrings)

        assert set(objects_with_docstrings) == set(self.code1.docstrings)
        assert set(objects_with_rest_docstrings) == set(self.code1.docstrings_by_format["reST"])
        assert set(objects_with_epytext_docstrings) == set(self.code1.docstrings_by_format["epytext"])
        assert set(objects_with_javadoc_docstrings) == set(self.code1.docstrings_by_format["javadoc"])