Bug 1623339 - [mozlint] Add a test for pathutils.expand_exclusions, r=linter-reviewers,sylvestre

Differential Revision: https://phabricator.services.mozilla.com/D67334
This commit is contained in:
Andrew Halberstadt
2020-03-18 17:02:27 +00:00
parent 92e2bc5b6b
commit 29ec66bfed
2 changed files with 28 additions and 5 deletions

View File

@@ -287,6 +287,7 @@ def expand_exclusions(paths, config, root):
continue continue
yield path yield path
continue
ignore = [e[len(path):].lstrip('/') for e in exclude ignore = [e[len(path):].lstrip('/') for e in exclude
if mozpath.commonprefix((path, e)) == path] if mozpath.commonprefix((path, e)) == path]

View File

@@ -22,7 +22,7 @@ def assert_paths(a, b):
assert set(map(normalize, a)) == set(map(normalize, b)) assert set(map(normalize, a)) == set(map(normalize, b))
TEST_CASES = ( @pytest.mark.parametrize('test', (
{ {
'paths': ['a.js', 'subdir1/subdir3/d.js'], 'paths': ['a.js', 'subdir1/subdir3/d.js'],
'include': ['.'], 'include': ['.'],
@@ -71,10 +71,7 @@ TEST_CASES = (
'exclude': [], 'exclude': [],
'expected': [], 'expected': [],
} }
) ))
@pytest.mark.parametrize('test', TEST_CASES)
def test_filterpaths(test): def test_filterpaths(test):
expected = test.pop('expected') expected = test.pop('expected')
expected_exclude = test.pop('expected_exclude', []) expected_exclude = test.pop('expected_exclude', [])
@@ -84,6 +81,31 @@ def test_filterpaths(test):
assert_paths(exclude, expected_exclude) assert_paths(exclude, expected_exclude)
@pytest.mark.parametrize('test', (
{
'paths': ['subdir1/b.js'],
'config': {
'exclude': ['subdir1'],
'extensions': 'js',
},
'expected': [],
},
{
'paths': ['subdir1/subdir3'],
'config': {
'exclude': ['subdir1'],
'extensions': 'js',
},
'expected': [],
},
))
def test_expand_exclusions(test):
expected = test.pop('expected', [])
paths = list(pathutils.expand_exclusions(test['paths'], test['config'], root))
assert_paths(paths, expected)
@pytest.mark.parametrize('paths,expected', [ @pytest.mark.parametrize('paths,expected', [
(['subdir1/*'], ['subdir1']), (['subdir1/*'], ['subdir1']),
(['subdir2/*'], ['subdir2']), (['subdir2/*'], ['subdir2']),