diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-05 16:20:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-05 16:20:58 +0000 |
commit | 5bb0bb4be543fd5eca41673696a62ed80d493591 (patch) | |
tree | ad2c464f140e86c7f178a6276d7ea4a93e3e6c92 /tests/test_util_matching.py | |
parent | Adding upstream version 7.2.6. (diff) | |
download | sphinx-5bb0bb4be543fd5eca41673696a62ed80d493591.tar.xz sphinx-5bb0bb4be543fd5eca41673696a62ed80d493591.zip |
Adding upstream version 7.3.7.upstream/7.3.7
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_util_matching.py')
-rw-r--r-- | tests/test_util_matching.py | 174 |
1 files changed, 0 insertions, 174 deletions
diff --git a/tests/test_util_matching.py b/tests/test_util_matching.py deleted file mode 100644 index 7d865ba..0000000 --- a/tests/test_util_matching.py +++ /dev/null @@ -1,174 +0,0 @@ -"""Tests sphinx.util.matching functions.""" -from sphinx.util.matching import Matcher, compile_matchers, get_matching_files - - -def test_compile_matchers(): - # exact matching - pat = compile_matchers(['hello.py']).pop() - assert pat('hello.py') - assert not pat('hello-py') - assert not pat('subdir/hello.py') - - # wild card (*) - pat = compile_matchers(['hello.*']).pop() - assert pat('hello.py') - assert pat('hello.rst') - - pat = compile_matchers(['*.py']).pop() - assert pat('hello.py') - assert pat('world.py') - assert not pat('subdir/hello.py') - - # wild card (**) - pat = compile_matchers(['hello.**']).pop() - assert pat('hello.py') - assert pat('hello.rst') - assert pat('hello.py/world.py') - - pat = compile_matchers(['**.py']).pop() - assert pat('hello.py') - assert pat('world.py') - assert pat('subdir/hello.py') - - pat = compile_matchers(['**/hello.py']).pop() - assert not pat('hello.py') - assert pat('subdir/hello.py') - assert pat('subdir/subdir/hello.py') - - # wild card (?) - pat = compile_matchers(['hello.?']).pop() - assert pat('hello.c') - assert not pat('hello.py') - - # pattern ([...]) - pat = compile_matchers(['hello[12\\].py']).pop() - assert pat('hello1.py') - assert pat('hello2.py') - assert pat('hello\\.py') - assert not pat('hello3.py') - - pat = compile_matchers(['hello[^12].py']).pop() # "^" is not negative identifier - assert pat('hello1.py') - assert pat('hello2.py') - assert pat('hello^.py') - assert not pat('hello3.py') - - # negative pattern ([!...]) - pat = compile_matchers(['hello[!12].py']).pop() - assert not pat('hello1.py') - assert not pat('hello2.py') - assert not pat('hello/.py') # negative pattern does not match to "/" - assert pat('hello3.py') - - # non patterns - pat = compile_matchers(['hello[.py']).pop() - assert pat('hello[.py') - assert not pat('hello.py') - - pat = compile_matchers(['hello[].py']).pop() - assert pat('hello[].py') - assert not pat('hello.py') - - pat = compile_matchers(['hello[!].py']).pop() - assert pat('hello[!].py') - assert not pat('hello.py') - - -def test_Matcher(): - matcher = Matcher(['hello.py', '**/world.py']) - assert matcher('hello.py') - 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", exclude_patterns=["**.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", exclude_patterns=["**.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", exclude_patterns=["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", include_patterns=["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", include_patterns=["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", include_patterns=["halibut/**"]) - assert sorted(files) == [] - - -def test_get_matching_files_all_include_prefix(rootdir): - files = get_matching_files(rootdir / "test-root", include_patterns=["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", include_patterns=["img.???"]) - assert sorted(files) == [ - 'img.gif', 'img.pdf', 'img.png', - ] |