summaryrefslogtreecommitdiffstats
path: root/python/mozlint/test
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:14:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:14:29 +0000
commitfbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8 (patch)
tree4c1ccaf5486d4f2009f9a338a98a83e886e29c97 /python/mozlint/test
parentReleasing progress-linux version 124.0.1-1~progress7.99u1. (diff)
downloadfirefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.tar.xz
firefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.zip
Merging upstream version 125.0.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'python/mozlint/test')
-rw-r--r--python/mozlint/test/linters/invalid_ext_and_exclude_ext.yml7
-rw-r--r--python/mozlint/test/test_parser.py1
-rw-r--r--python/mozlint/test/test_pathutils.py68
3 files changed, 72 insertions, 4 deletions
diff --git a/python/mozlint/test/linters/invalid_ext_and_exclude_ext.yml b/python/mozlint/test/linters/invalid_ext_and_exclude_ext.yml
new file mode 100644
index 0000000000..a73353fb71
--- /dev/null
+++ b/python/mozlint/test/linters/invalid_ext_and_exclude_ext.yml
@@ -0,0 +1,7 @@
+---
+InvalidExtensionAndExcludedExtensions:
+ type: string
+ payload: foobar
+ description: Having both extensions and exclude_extensions is not allowed.
+ extensions: ["*.js"]
+ exclude_extensions: ["*.png"]
diff --git a/python/mozlint/test/test_parser.py b/python/mozlint/test/test_parser.py
index 2fbf26c8e5..3cb319a2e0 100644
--- a/python/mozlint/test/test_parser.py
+++ b/python/mozlint/test/test_parser.py
@@ -59,6 +59,7 @@ def test_parser_valid_multiple(parse):
"invalid_include_with_glob.yml",
"invalid_exclude.yml",
"invalid_support_files.yml",
+ "invalid_ext_and_exclude_ext.yml",
"missing_attrs.yml",
"missing_definition.yml",
"non_existing_include.yml",
diff --git a/python/mozlint/test/test_pathutils.py b/python/mozlint/test/test_pathutils.py
index 78f7883e88..5f593fdc47 100644
--- a/python/mozlint/test/test_pathutils.py
+++ b/python/mozlint/test/test_pathutils.py
@@ -59,6 +59,43 @@ def assert_paths(a, b):
"extensions": ["py"],
"expected": ["a.py", "subdir1/b.py"],
},
+ pytest.param(
+ {
+ "paths": [
+ "a.py",
+ "a.js",
+ "subdir1/b.py",
+ "subdir2/c.py",
+ "subdir1/subdir3/d.py",
+ ],
+ "include": ["."],
+ "exclude": [],
+ "exclude_extensions": ["py"],
+ "expected": ["a.js"],
+ },
+ id="Excluding .py should only return .js file.",
+ ),
+ pytest.param(
+ {
+ "paths": [
+ "a.py",
+ "a.js",
+ "subdir1/b.py",
+ "subdir2/c.py",
+ "subdir1/subdir3/d.py",
+ ],
+ "include": ["."],
+ "exclude": [],
+ "exclude_extensions": ["js"],
+ "expected": [
+ "a.py",
+ "subdir1/b.py",
+ "subdir2/c.py",
+ "subdir1/subdir3/d.py",
+ ],
+ },
+ id="Excluding .js should only return .py files.",
+ ),
{
"paths": ["a.py", "a.js", "subdir2"],
"include": ["."],
@@ -104,24 +141,47 @@ def test_filterpaths(test):
"paths": ["subdir1/b.js"],
"config": {
"exclude": ["subdir1"],
- "extensions": "js",
+ "extensions": ["js"],
},
"expected": [],
},
{
- "paths": ["subdir1/subdir3"],
+ "paths": ["subdir1"],
"config": {
"exclude": ["subdir1"],
- "extensions": "js",
+ "extensions": ["js"],
},
"expected": [],
},
+ pytest.param(
+ {
+ "paths": ["a.py", "subdir1"],
+ "config": {
+ "exclude": ["subdir1"],
+ "exclude_extensions": ["gob"],
+ },
+ "expected": ["a.py"],
+ },
+ id="Excluding both subdirs and nonsense extensions returns other files.",
+ ),
+ pytest.param(
+ {
+ "paths": ["a.py", "a.js", "subdir1"],
+ "config": {
+ "exclude": [],
+ "exclude_extensions": ["py"],
+ },
+ "expected": ["a.js", "subdir1/subdir3/d.js", "subdir1/b.js"],
+ },
+ id="Excluding .py files returns only non-.py files, also from subdirs.",
+ ),
),
)
def test_expand_exclusions(test):
expected = test.pop("expected", [])
- paths = list(pathutils.expand_exclusions(test["paths"], test["config"], root))
+ input_paths = [os.path.join(root, p) for p in test["paths"]]
+ paths = list(pathutils.expand_exclusions(input_paths, test["config"], root))
assert_paths(paths, expected)