summaryrefslogtreecommitdiff
path: root/tests/test_util_matching.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_util_matching.py')
-rw-r--r--tests/test_util_matching.py94
1 files changed, 93 insertions, 1 deletions
diff --git a/tests/test_util_matching.py b/tests/test_util_matching.py
index ee1d3b2cb..ecff0e2d8 100644
--- a/tests/test_util_matching.py
+++ b/tests/test_util_matching.py
@@ -1,5 +1,5 @@
"""Tests sphinx.util.matching functions."""
-from sphinx.util.matching import Matcher, compile_matchers
+from sphinx.util.matching import Matcher, compile_matchers, get_matching_files
def test_compile_matchers():
@@ -80,3 +80,95 @@ def test_Matcher():
assert not matcher('subdir/hello.py')
assert matcher('world.py')
assert matcher('subdir/world.py')
+
+
+def test_get_matching_files_all(rootdir):
+ files = get_matching_files(rootdir / "test-root")
+ assert sorted(files) == [
+ 'Makefile', '_templates/contentssb.html', '_templates/customsb.html',
+ '_templates/layout.html', 'autodoc.txt', 'autodoc_target.py', 'bom.txt', 'conf.py',
+ 'extapi.txt', 'extensions.txt', 'file_with_special_#_chars.xyz', 'footnote.txt',
+ 'images.txt', 'img.foo.png', 'img.gif', 'img.pdf', 'img.png', 'includes.txt',
+ 'index.txt', 'lists.txt', 'literal.inc', 'literal_orig.inc', 'markup.txt', 'math.txt',
+ 'objects.txt', 'otherext.foo', 'parsermod.py', 'quotes.inc', 'rimg.png',
+ 'special/api.h', 'special/code.py', 'subdir/excluded.txt', 'subdir/images.txt',
+ 'subdir/img.png', 'subdir/include.inc', 'subdir/includes.txt', 'subdir/simg.png',
+ 'svgimg.pdf', 'svgimg.svg', 'tabs.inc', 'test.inc', 'wrongenc.inc',
+ ]
+
+
+def test_get_matching_files_all_exclude_single(rootdir):
+ files = get_matching_files(rootdir / "test-root", ["**.html"])
+ assert sorted(files) == [
+ 'Makefile', 'autodoc.txt', 'autodoc_target.py', 'bom.txt', 'conf.py',
+ 'extapi.txt', 'extensions.txt', 'file_with_special_#_chars.xyz', 'footnote.txt',
+ 'images.txt', 'img.foo.png', 'img.gif', 'img.pdf', 'img.png', 'includes.txt',
+ 'index.txt', 'lists.txt', 'literal.inc', 'literal_orig.inc', 'markup.txt', 'math.txt',
+ 'objects.txt', 'otherext.foo', 'parsermod.py', 'quotes.inc', 'rimg.png',
+ 'special/api.h', 'special/code.py', 'subdir/excluded.txt', 'subdir/images.txt',
+ 'subdir/img.png', 'subdir/include.inc', 'subdir/includes.txt', 'subdir/simg.png',
+ 'svgimg.pdf', 'svgimg.svg', 'tabs.inc', 'test.inc', 'wrongenc.inc',
+ ]
+
+
+def test_get_matching_files_all_exclude_multiple(rootdir):
+ files = get_matching_files(rootdir / "test-root", ["**.html", "**.inc"])
+ assert sorted(files) == [
+ 'Makefile', 'autodoc.txt', 'autodoc_target.py', 'bom.txt', 'conf.py',
+ 'extapi.txt', 'extensions.txt', 'file_with_special_#_chars.xyz', 'footnote.txt',
+ 'images.txt', 'img.foo.png', 'img.gif', 'img.pdf', 'img.png', 'includes.txt',
+ 'index.txt', 'lists.txt', 'markup.txt', 'math.txt', 'objects.txt', 'otherext.foo',
+ 'parsermod.py', 'rimg.png', 'special/api.h', 'special/code.py', 'subdir/excluded.txt',
+ 'subdir/images.txt', 'subdir/img.png', 'subdir/includes.txt', 'subdir/simg.png',
+ 'svgimg.pdf', 'svgimg.svg',
+ ]
+
+
+def test_get_matching_files_all_exclude_nonexistent(rootdir):
+ files = get_matching_files(rootdir / "test-root", ["halibut/**"])
+ assert sorted(files) == [
+ 'Makefile', '_templates/contentssb.html', '_templates/customsb.html',
+ '_templates/layout.html', 'autodoc.txt', 'autodoc_target.py', 'bom.txt', 'conf.py',
+ 'extapi.txt', 'extensions.txt', 'file_with_special_#_chars.xyz', 'footnote.txt',
+ 'images.txt', 'img.foo.png', 'img.gif', 'img.pdf', 'img.png', 'includes.txt',
+ 'index.txt', 'lists.txt', 'literal.inc', 'literal_orig.inc', 'markup.txt', 'math.txt',
+ 'objects.txt', 'otherext.foo', 'parsermod.py', 'quotes.inc', 'rimg.png',
+ 'special/api.h', 'special/code.py', 'subdir/excluded.txt', 'subdir/images.txt',
+ 'subdir/img.png', 'subdir/include.inc', 'subdir/includes.txt', 'subdir/simg.png',
+ 'svgimg.pdf', 'svgimg.svg', 'tabs.inc', 'test.inc', 'wrongenc.inc',
+ ]
+
+
+def test_get_matching_files_all_include_single(rootdir):
+ files = get_matching_files(rootdir / "test-root", [], ["subdir/**"])
+ assert sorted(files) == [
+ 'subdir/excluded.txt', 'subdir/images.txt', 'subdir/img.png', 'subdir/include.inc',
+ 'subdir/includes.txt', 'subdir/simg.png',
+ ]
+
+
+def test_get_matching_files_all_include_multiple(rootdir):
+ files = get_matching_files(rootdir / "test-root", [], ["special/**", "subdir/**"])
+ assert sorted(files) == [
+ 'special/api.h', 'special/code.py', 'subdir/excluded.txt', 'subdir/images.txt',
+ 'subdir/img.png', 'subdir/include.inc', 'subdir/includes.txt', 'subdir/simg.png',
+ ]
+
+
+def test_get_matching_files_all_include_nonexistent(rootdir):
+ files = get_matching_files(rootdir / "test-root", [], ["halibut/**"])
+ assert sorted(files) == []
+
+
+def test_get_matching_files_all_include_prefix(rootdir):
+ files = get_matching_files(rootdir / "test-root", [], ["autodoc*"])
+ assert sorted(files) == [
+ 'autodoc.txt', 'autodoc_target.py',
+ ]
+
+
+def test_get_matching_files_all_include_question_mark(rootdir):
+ files = get_matching_files(rootdir / "test-root", [], ["img.???"])
+ assert sorted(files) == [
+ 'img.gif', 'img.pdf', 'img.png',
+ ]