Skip to content

Commit a8100fc

Browse files
jurko-gospodneticgaborbernat
authored andcommitted
add pytest plugin tests to improve test coverage
1 parent 1f75f70 commit a8100fc

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

tests/test_pytest_plugins.py

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
"""
2+
Test utility tests, intended to cover use-cases not used in the current
3+
project test suite, e.g. as shown by the code coverage report.
4+
5+
"""
6+
import py.path
7+
import pytest
8+
9+
from tox._pytestplugin import _filedefs_contains
10+
from tox._pytestplugin import _path_parts
11+
12+
13+
class TestInitProj:
14+
@pytest.mark.parametrize('kwargs', (
15+
{},
16+
{'src_root': None},
17+
{'src_root': ''},
18+
{'src_root': '.'}))
19+
def test_no_src_root(self, kwargs, tmpdir, initproj):
20+
initproj('black_knight-42', **kwargs)
21+
init_file = tmpdir.join('black_knight', 'black_knight', '__init__.py')
22+
assert init_file.read_binary() == b"__version__ = '42'"
23+
24+
def test_existing_src_root(self, tmpdir, initproj):
25+
initproj('spam-666', src_root='ham')
26+
assert not tmpdir.join('spam', 'spam').check(exists=1)
27+
init_file = tmpdir.join('spam', 'ham', 'spam', '__init__.py')
28+
assert init_file.read_binary() == b"__version__ = '666'"
29+
30+
def test_prebuilt_src_dir_with_no_src_root(self, tmpdir, initproj):
31+
initproj('spam-1.0', filedefs={'spam': {}})
32+
src_dir = tmpdir.join('spam', 'spam')
33+
assert src_dir.check(dir=1)
34+
assert not src_dir.join('__init__.py').check(exists=1)
35+
36+
def test_prebuilt_src_dir_with_src_root(self, tmpdir, initproj):
37+
initproj(
38+
'spam-1.0',
39+
filedefs={'incontinentia': {'spam': {'__init__.py': 'buttocks'}}},
40+
src_root='incontinentia')
41+
assert not tmpdir.join('spam', 'spam').check(exists=1)
42+
init_file = tmpdir.join('spam', 'incontinentia', 'spam', '__init__.py')
43+
assert init_file.read_binary() == b'buttocks'
44+
45+
def test_broken_py_path_local_join_workaround_on_Windows(
46+
self, tmpdir, initproj, monkeypatch):
47+
# construct an absolute folder path for our src_root folder without the
48+
# Windows drive indicator
49+
src_root = tmpdir.join('spam')
50+
src_root = _path_parts(src_root)
51+
src_root[0] = ''
52+
src_root = '/'.join(src_root)
53+
54+
# make sure tmpdir drive is the current one so the constructed src_root
55+
# folder path gets interpreted correctly on Windows
56+
monkeypatch.chdir(tmpdir)
57+
58+
# will throw an assertion error if the bug is not worked around
59+
initproj('spam-666', src_root=src_root)
60+
61+
init_file = tmpdir.join('spam', 'spam', '__init__.py')
62+
assert init_file.read_binary() == b"__version__ = '666'"
63+
64+
65+
class TestPathParts:
66+
@pytest.mark.parametrize('input, expected', (
67+
('', []),
68+
('/', ['/']),
69+
('//', ['//']),
70+
('/a', ['/', 'a']),
71+
('/a/', ['/', 'a']),
72+
('/a/b', ['/', 'a', 'b']),
73+
('a', ['a']),
74+
('a/b', ['a', 'b'])))
75+
def test_path_parts(self, input, expected):
76+
assert _path_parts(input) == expected
77+
78+
def test_on_py_path(self):
79+
cwd_parts = _path_parts(py.path.local())
80+
folder_parts = _path_parts(py.path.local('a/b/c'))
81+
assert folder_parts[len(cwd_parts):] == ['a', 'b', 'c']
82+
83+
84+
@pytest.mark.parametrize('base, filedefs, target, expected', (
85+
('/base', {}, '', False),
86+
('/base', {}, '/base', False),
87+
('/base', {'a': {'b': 'data'}}, '', True),
88+
('/base', {'a': {'b': 'data'}}, 'a', True),
89+
('/base', {'a': {'b': 'data'}}, 'a/b', True),
90+
('/base', {'a': {'b': 'data'}}, 'a/x', False),
91+
('/base', {'a': {'b': 'data'}}, 'a/b/c', False),
92+
('/base', {'a': {'b': 'data'}}, '/base', True),
93+
('/base', {'a': {'b': 'data'}}, '/base/a', True),
94+
('/base', {'a': {'b': 'data'}}, '/base/a/b', True),
95+
('/base', {'a': {'b': 'data'}}, '/base/a/x', False),
96+
('/base', {'a': {'b': 'data'}}, '/base/a/b/c', False),
97+
('/base', {'a': {'b': 'data'}}, '/a', False)))
98+
def test_filedefs_contains(base, filedefs, target, expected):
99+
assert bool(_filedefs_contains(base, filedefs, target)) == expected

0 commit comments

Comments
 (0)