Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Jun 3, 2022
1 parent 3ffb75e commit fac1162
Showing 1 changed file with 95 additions and 1 deletion.
96 changes: 95 additions & 1 deletion 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():
Expand Down Expand Up @@ -80,3 +80,97 @@ 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',
]


0 comments on commit fac1162

Please sign in to comment.