-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bad757d
commit c28d34b
Showing
2 changed files
with
136 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,95 @@ | ||
from pathlib import Path | ||
|
||
from doitpy.coverage import PythonPackage | ||
from doitpy.config import Config | ||
from doitpy.coverage import PythonPackage, Coverage | ||
|
||
TEST_PATH = Path(__file__).parent | ||
|
||
SAMPLE = TEST_PATH / 'sample' # path to sample project | ||
|
||
class TestPythonPackage(object): | ||
def test_init_tests_in_package(self): | ||
pkg = PythonPackage(TEST_PATH / 'sample') | ||
assert pkg.test_base == str(TEST_PATH / 'sample/tests') | ||
pkg = PythonPackage(SAMPLE) | ||
assert pkg.test_base == str(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 str(SAMPLE / 'flake_ok.py') in pkg.src | ||
assert str(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 str(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', | ||
pkg = PythonPackage(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') | ||
pkg = PythonPackage(SAMPLE) | ||
all_modules = list(pkg.all_modules()) | ||
assert len(all_modules) == 3 | ||
assert str(TEST_PATH / 'sample/flake_fail.py') in all_modules | ||
assert str(SAMPLE / 'flake_fail.py') in all_modules | ||
|
||
|
||
|
||
class TestCoverage(object): | ||
def test_init_pkg_as_string(self): | ||
cov = Coverage([SAMPLE]) | ||
assert len(cov.pkgs) == 1 | ||
assert cov.pkgs[0].src_base == str(SAMPLE) | ||
|
||
def test_init_pkg_instance(self): | ||
cov = Coverage([PythonPackage(SAMPLE)]) | ||
assert len(cov.pkgs) == 1 | ||
assert cov.pkgs[0].src_base == str(SAMPLE) | ||
|
||
def test_cover_all(self): | ||
pkg = PythonPackage(SAMPLE) | ||
cov = Coverage([pkg]) | ||
task = list(cov.all('my_cov'))[0] | ||
assert task['verbosity'] == 2 | ||
assert task['basename'] == 'my_cov' | ||
assert task['actions'] == [ | ||
'coverage run --branch `which py.test`', | ||
'coverage report --show-missing {}'.format(' '.join(pkg.all_modules())) | ||
] | ||
|
||
def test_cover_all_parallel(self): | ||
pkg = PythonPackage(SAMPLE) | ||
cov = Coverage([pkg], config=Config(parallel=True, branch=False, | ||
omit=['abc'])) | ||
task = list(cov.all('my_cov'))[0] | ||
assert task['verbosity'] == 2 | ||
assert task['basename'] == 'my_cov' | ||
assert task['actions'] == [ | ||
'coverage run --parallel-mode `which py.test`', | ||
'coverage combine', | ||
'coverage report --show-missing --omit abc {}'.format( | ||
' '.join(pkg.all_modules())) | ||
] | ||
|
||
|
||
def test_cover_src(self): | ||
pkg = PythonPackage(SAMPLE) | ||
cov = Coverage([pkg]) | ||
task = list(cov.src('my_cov'))[0] | ||
assert task['verbosity'] == 2 | ||
assert task['basename'] == 'my_cov' | ||
assert task['actions'] == [ | ||
'coverage run --branch `which py.test`', | ||
'coverage report --show-missing {}'.format(' '.join(pkg.src)) | ||
] | ||
|
||
|
||
def test_cover_module(self): | ||
pkg = PythonPackage(SAMPLE) | ||
cov = Coverage([pkg]) | ||
tasks = list(cov.by_module('my_cov')) | ||
assert len(tasks) == 1 | ||
task = tasks[0] | ||
assert task['verbosity'] == 2 | ||
assert task['basename'] == 'my_cov' | ||
src = pkg.src_base + '/flake_ok.py' | ||
test = pkg.src_base + '/tests/test_flake_ok.py' | ||
assert task['actions'] == [ | ||
'coverage run --branch `which py.test` {}'.format(test), | ||
'coverage report --show-missing {}'.format(' '.join([src, test])) | ||
] |