| 1 |
import os |
|---|
| 2 |
import shutil |
|---|
| 3 |
import tempfile |
|---|
| 4 |
|
|---|
| 5 |
import _path_cheesecake |
|---|
| 6 |
from _helper_cheesecake import DATA_PATH, Glutton, create_empty_file |
|---|
| 7 |
from cheesecake.cheesecake_index import IndexPyLint |
|---|
| 8 |
from cheesecake import logger |
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
class TestIndexPyLint(object): |
|---|
| 12 |
def test_import_self(self): |
|---|
| 13 |
files_list = ['import_self.py'] |
|---|
| 14 |
package_dir = DATA_PATH |
|---|
| 15 |
|
|---|
| 16 |
index = IndexPyLint() |
|---|
| 17 |
index.cheesecake = Glutton() |
|---|
| 18 |
|
|---|
| 19 |
index.compute(files_list, package_dir) |
|---|
| 20 |
|
|---|
| 21 |
# Check that package got maximum score, what means importing self |
|---|
| 22 |
# is not decreasing the score. |
|---|
| 23 |
print index.value |
|---|
| 24 |
assert index.value == index.max_value |
|---|
| 25 |
|
|---|
| 26 |
def test_long_file_list(self): |
|---|
| 27 |
"Test if pylint index works for long files lists." |
|---|
| 28 |
_package_dir = tempfile.mkdtemp() |
|---|
| 29 |
_files_list = map(lambda x: 'long_module_with_a_number_%d.py' % x, xrange(4000)) |
|---|
| 30 |
|
|---|
| 31 |
for filename in _files_list: |
|---|
| 32 |
create_empty_file(os.path.join(_package_dir, filename)) |
|---|
| 33 |
|
|---|
| 34 |
logger.setconsumer('console', logger.STDOUT) |
|---|
| 35 |
console_log = logger.MultipleProducer('cheesecake console') |
|---|
| 36 |
|
|---|
| 37 |
class CheesecakeMockup(object): |
|---|
| 38 |
package_dir = _package_dir |
|---|
| 39 |
files_list = _files_list |
|---|
| 40 |
log = console_log |
|---|
| 41 |
|
|---|
| 42 |
index = IndexPyLint() |
|---|
| 43 |
cheesecake = CheesecakeMockup() |
|---|
| 44 |
|
|---|
| 45 |
index.compute_with(cheesecake) |
|---|
| 46 |
assert index.details != "encountered an error during pylint execution" |
|---|
| 47 |
|
|---|
| 48 |
# Clean up. |
|---|
| 49 |
shutil.rmtree(_package_dir) |
|---|