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