fix the default value for types_or

This commit is contained in:
Anthony Sottile 2020-11-25 18:21:37 -08:00
parent b5baf5c807
commit 89ab609732
4 changed files with 28 additions and 3 deletions

View file

@ -61,7 +61,7 @@ MANIFEST_HOOK_DICT = cfgv.Map(
cfgv.Optional('files', check_string_regex, ''), cfgv.Optional('files', check_string_regex, ''),
cfgv.Optional('exclude', check_string_regex, '^$'), cfgv.Optional('exclude', check_string_regex, '^$'),
cfgv.Optional('types', cfgv.check_array(check_type_tag), ['file']), cfgv.Optional('types', cfgv.check_array(check_type_tag), ['file']),
cfgv.Optional('types_or', cfgv.check_array(check_type_tag), ['file']), cfgv.Optional('types_or', cfgv.check_array(check_type_tag), []),
cfgv.Optional('exclude_types', cfgv.check_array(check_type_tag), []), cfgv.Optional('exclude_types', cfgv.check_array(check_type_tag), []),
cfgv.Optional( cfgv.Optional(

View file

@ -92,7 +92,11 @@ class Classifier:
ret = [] ret = []
for filename in names: for filename in names:
tags = self._types_for_file(filename) tags = self._types_for_file(filename)
if tags >= types and tags & types_or and not tags & exclude_types: if (
tags >= types and
(not types_or or tags & types_or) and
not tags & exclude_types
):
ret.append(filename) ret.append(filename)
return ret return ret

View file

@ -964,6 +964,27 @@ def test_classifier_does_not_normalize_backslashes_non_windows(tmpdir):
assert classifier.filenames == [r'a/b\c'] assert classifier.filenames == [r'a/b\c']
def test_classifier_empty_types_or(tmpdir):
tmpdir.join('bar').ensure()
tmpdir.join('foo').mksymlinkto('bar')
with tmpdir.as_cwd():
classifier = Classifier(('foo', 'bar'))
for_symlink = classifier.by_types(
classifier.filenames,
types=['symlink'],
types_or=[],
exclude_types=[],
)
for_file = classifier.by_types(
classifier.filenames,
types=['file'],
types_or=[],
exclude_types=[],
)
assert for_symlink == ['foo']
assert for_file == ['bar']
@pytest.fixture @pytest.fixture
def some_filenames(): def some_filenames():
return ( return (

View file

@ -901,7 +901,7 @@ def test_manifest_hooks(tempdir_factory, store):
'post-commit', 'manual', 'post-checkout', 'push', 'post-commit', 'manual', 'post-checkout', 'push',
), ),
types=['file'], types=['file'],
types_or=['file'], types_or=[],
verbose=False, verbose=False,
) )