Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

tests for coverage.PythonPackage

  • Loading branch information...
commit b97b0ac8c6d12cbd4bfd19efe406f133670271b4 1 parent c0de990
eduardo naufel schettino schettino72 authored
3  dodo.py
View
@@ -10,8 +10,7 @@ def task_pyflakes():
def task_coverage():
- cov = Coverage([PythonPackage('doitpy', test_path='tests')],
- config={'omit':['"tests/sample_*"']})
+ cov = Coverage([PythonPackage('doitpy', test_path='tests')])
yield cov.all()
yield cov.src()
yield cov.by_module()
23 doitpy/coverage.py
View
@@ -11,20 +11,26 @@
class PythonPackage(object):
# TODO should track sub-packages
- TEST_PREFIX = 'test_'
+ config = Config(
+ test_prefix = 'test_',
+ pkg_test_dir = 'tests',
+ )
- def __init__(self, name, test_path=None):
+ def __init__(self, path, test_path=None, config=None):
"""if test_path is not given assume it is 'tests' inside source package"""
- self.name = name
- self.src_base = name if name else ''
+ self.config = self.config.make(config)
+ self.test_prefix = self.config['test_prefix']
+
+ self.src_base = path if path else ''
if test_path is None:
- self.test_base = '{}/tests'.format(self.src_base)
+ self.test_base = '{}/{}'.format(self.src_base,
+ self.config['pkg_test_dir'])
else:
self.test_base = test_path
self.src = glob.glob("{}/*.py".format(self.src_base))
self.test = glob.glob("{}/*.py".format(self.test_base))
self.test_files = glob.glob("{}/{}*.py".format(
- self.test_base, self.TEST_PREFIX))
+ self.test_base, self.test_prefix))
def all_modules(self):
for mod in self.src + self.test:
@@ -102,8 +108,9 @@ def src(self):
def by_module(self):
"""show coverage for individual modules"""
for pkg in self.pkgs:
- to_strip = len('{}/{}'.format(pkg.test_base, pkg.TEST_PREFIX))
- tests = glob.glob('{}/{}*.py'.format(pkg.test_base, pkg.TEST_PREFIX))
+ to_strip = len('{}/{}'.format(pkg.test_base, pkg.test_prefix))
+ tests = glob.glob('{}/{}*.py'.format(pkg.test_base,
+ pkg.test_prefix))
for test in tests:
source = pkg.src_base + '/' + test[to_strip:]
yield {
0  tests/sample_fail.py → tests/sample/flake_fail.py
View
File renamed without changes
0  tests/sample_ok.py → tests/sample/flake_ok.py
View
File renamed without changes
0  tests/sample/tests/test_flake_ok.py
View
No changes.
28 tests/test_coverage.py
View
@@ -0,0 +1,28 @@
+from pathlib import Path
+
+from doitpy.coverage import PythonPackage, Coverage
+
+TEST_PATH = Path(__file__).parent
+
+
+class TestPythonPackage(object):
+ def test_init_tests_in_package(self):
+ pkg = PythonPackage(TEST_PATH / 'sample')
+ assert pkg.test_base == str(TEST_PATH / 'sample/tests')
+ assert len(pkg.src) == 2
+ assert str(TEST_PATH / 'sample/flake_ok.py') in pkg.src
+ assert str(TEST_PATH / 'sample/flake_fail.py') in pkg.src
+ assert len(pkg.test) == 1
+ assert str(TEST_PATH / 'sample/tests/test_flake_ok.py') in pkg.test
+ assert pkg.test == pkg.test_files
+
+ def test_init_test_path(self):
+ pkg = PythonPackage(TEST_PATH / 'sample',
+ test_path=str(TEST_PATH/'test2'))
+ assert pkg.test_base == str(TEST_PATH / 'test2')
+
+ def test_all_modules(self):
+ pkg = PythonPackage(TEST_PATH / 'sample')
+ all_modules = list(pkg.all_modules())
+ assert len(all_modules) == 3
+ assert str(TEST_PATH / 'sample/flake_fail.py') in all_modules
19 tests/test_pyflakes.py
View
@@ -1,15 +1,15 @@
-import os
+from pathlib import Path
from doitpy import pyflakes
-TEST_PATH = os.path.dirname(__file__)
+TEST_PATH = Path(__file__).parent
class TestCheckPath(object):
def test_success(self):
- assert pyflakes.check_path('{}/sample_ok.py'.format(TEST_PATH))
+ assert pyflakes.check_path(str(TEST_PATH / 'sample/flake_ok.py'))
def test_failure(self):
- assert not pyflakes.check_path('{}/sample_fail.py'.format(TEST_PATH))
+ assert not pyflakes.check_path(str(TEST_PATH / 'sample/flake_fail.py'))
class TestPyflakes(object):
def test_init(self):
@@ -24,10 +24,11 @@ def test_call(self):
assert task_dict['file_dep'] == ['my_module.py']
def test_tasks(self):
- exclude_pattern = 'test_*'
- check_pattern = '*.py'
- exclude_path = 'sample_fail.py'
+ exclude_pattern = 'tests/*'
+ check_pattern = '**/*.py'
+ exclude_path = 'flake_fail.py'
obj = pyflakes.Pyflakes(exclude_patterns=[exclude_pattern])
- tasks = list(obj.tasks(check_pattern, TEST_PATH, [exclude_path]))
+ base_dir = TEST_PATH / 'sample'
+ tasks = list(obj.tasks(check_pattern, base_dir, [exclude_path]))
assert len(tasks) == 1
- assert tasks[0]['name'] == '{}/sample_ok.py'.format(TEST_PATH)
+ assert tasks[0]['name'] == str(base_dir / 'flake_ok.py')
Please sign in to comment.
Something went wrong with that request. Please try again.