root/branches/mk/tests/test_code_parser.py

Revision 32, 1.9 kB (checked in by mk, 4 years ago)

Don't count empty docstrings (closes ticket #9).

Line 
1 import os
2
3 import _path_cheesecake
4 from cheesecake.codeparser import CodeParser
5
6 datadir = os.path.abspath(os.path.join(os.path.dirname(__file__), "data"))
7
8 class TestCodeParser(object):
9     def setUp(self):
10         self.code1 = CodeParser(os.path.join(datadir, "module1.py"))
11
12     def test_modules(self):
13         assert self.code1.modules == ["module1"]
14
15     def test_classes(self):
16         assert self.code1.classes == ["module1.Class1", "module1.Class2"]
17
18     def test_methods(self):
19         assert self.code1.methods == ["module1.Class1.__init__",
20         "module1.Class1.__another_method__",
21         "module1.Class1.method1",
22         "module1.Class1.method2",
23         "module1.Class1.method3",
24         "module1.Class1.method4"]
25
26     def test_functions(self):
27         assert self.code1.functions == [
28         "module1.func1",
29         "module1.func2",
30         "module1.func3",
31         "module1.func4",
32         "module1.__func5__",
33         "module1.func6"]
34
35     def test_count(self):
36         assert self.code1.object_count() == 15
37         assert self.code1.docstring_count() == 12
38
39     def test_docstrings(self):
40         objects_with_docstrings = [
41             "module1",
42             "module1.Class1",
43             "module1.Class2",
44             "module1.Class1.__init__",
45             "module1.Class1.__another_method__",
46             "module1.Class1.method1",
47             "module1.Class1.method2",
48             "module1.Class1.method3",
49             "module1.func1",
50             "module1.func2",
51             "module1.func3",
52             "module1.__func5__",
53         ]
54
55         objects_without_docstrings = [
56             "module1.Class1.method4",
57             "module1.func4",
58             "module1.func6",
59         ]
60
61         print self.code1.docstrings
62
63         for obj in objects_with_docstrings:
64             assert self.code1.docstrings.get(obj) == 1
65
66         for obj in objects_without_docstrings:
67             assert not self.code1.docstrings.get(obj)
Note: See TracBrowser for help on using the browser.