| 1 |
import _path_cheesecake |
|---|
| 2 |
from cheesecake.codeparser import CodeParser |
|---|
| 3 |
import os |
|---|
| 4 |
datadir = os.path.abspath(os.path.join(os.path.dirname(__file__), "data")) |
|---|
| 5 |
|
|---|
| 6 |
class TestCodeParser: |
|---|
| 7 |
def setUp(self): |
|---|
| 8 |
self.code1 = CodeParser(os.path.join(datadir, "module1.py")) |
|---|
| 9 |
|
|---|
| 10 |
def test_modules(self): |
|---|
| 11 |
assert self.code1.modules == ["module1"] |
|---|
| 12 |
|
|---|
| 13 |
def test_classes(self): |
|---|
| 14 |
assert self.code1.classes == ["module1.Class1", "module1.Class2"] |
|---|
| 15 |
|
|---|
| 16 |
def test_methods(self): |
|---|
| 17 |
assert self.code1.methods== ["module1.Class1.__init__", |
|---|
| 18 |
"module1.Class1.__another_method__", |
|---|
| 19 |
"module1.Class1.method1", |
|---|
| 20 |
"module1.Class1.method2", |
|---|
| 21 |
"module1.Class1.method3", |
|---|
| 22 |
"module1.Class1.method4"] |
|---|
| 23 |
|
|---|
| 24 |
def test_functions(self): |
|---|
| 25 |
assert self.code1.functions == [ |
|---|
| 26 |
"module1.func1", |
|---|
| 27 |
"module1.func2", |
|---|
| 28 |
"module1.func3", |
|---|
| 29 |
"module1.func4", |
|---|
| 30 |
"module1.__func5__"] |
|---|
| 31 |
|
|---|
| 32 |
def test_count(self): |
|---|
| 33 |
assert self.code1.object_count() == 14 |
|---|
| 34 |
assert self.code1.docstring_count() == 12 |
|---|
| 35 |
|
|---|
| 36 |
def test_docstrings(self): |
|---|
| 37 |
print self.code1.docstrings |
|---|
| 38 |
assert self.code1.docstrings.get("module1") == 1 |
|---|
| 39 |
for object in ["module1.Class1", "module1.Class2"]: |
|---|
| 40 |
assert self.code1.docstrings.get(object) == 1 |
|---|
| 41 |
for object in ["module1.Class1.__init__", "module1.Class1.__another_method__",\ |
|---|
| 42 |
"module1.Class1.method1", "module1.Class1.method2", "module1.Class1.method3"]: |
|---|
| 43 |
assert self.code1.docstrings.get(object) == 1 |
|---|
| 44 |
assert not self.code1.docstrings.get("module1.Class1.method4") |
|---|
| 45 |
for object in ["module1.func1", "module1.func2", "module1.func3", "module1.__func5__"]: |
|---|
| 46 |
assert self.code1.docstrings.get(object) == 1 |
|---|
| 47 |
assert not self.code1.docstrings.get("module1.func4") |
|---|