提交 00293a40 编写于 作者: C Cleber Rosa

Tags: refactor the parsing of the tags given on command line

Let's make the parsing of those tags a utility function so that its
behavior can be tested in detail.

Also, instead of parsing it for every test in a test suite, let's
parse those only once, and using during the filter process.
Signed-off-by: NCleber Rosa <crosa@redhat.com>
上级 14275a59
......@@ -63,6 +63,33 @@ class MissingTest(object):
"""
def parse_filter_by_tags(filter_by_tags):
"""
Parses the various filter by tags in "command line" format
The filtering of tests usually happens my means of "--filter-by-tags"
command line options, and many can be given. This parses the contents
of those into a list of must/must_not pairs, which can be used directly
for comparisons when filtering.
:param filter_by_tags: params in the format given to "-t/--filter-by-tags"
:type filter_by_tags: list of str
:returns: list of tuples with (set, set)
"""
result = []
for raw_tags in filter_by_tags:
required_tags = raw_tags.split(',')
must = set()
must_not = set()
for tag in required_tags:
if tag.startswith('-'):
must_not.add(tag[1:])
else:
must.add(tag)
result.append((must, must_not))
return result
def filter_test_tags(test_suite, filter_by_tags, include_empty=False):
"""
Filter the existing (unfiltered) test suite based on tags
......@@ -80,6 +107,8 @@ def filter_test_tags(test_suite, filter_by_tags, include_empty=False):
:type include_empty: bool
"""
filtered = []
must_must_nots = parse_filter_by_tags(filter_by_tags)
for klass, info in test_suite:
test_tags = info.get('tags', {})
if not test_tags:
......@@ -87,16 +116,7 @@ def filter_test_tags(test_suite, filter_by_tags, include_empty=False):
filtered.append((klass, info))
continue
for raw_tags in filter_by_tags:
required_tags = raw_tags.split(',')
must = set()
must_not = set()
for tag in required_tags:
if tag.startswith('-'):
must_not.add(tag[1:])
else:
must.add(tag)
for must, must_not in must_must_nots:
if must_not.intersection(test_tags):
continue
......
......@@ -595,5 +595,22 @@ class TagFilter2(unittest.TestCase):
loader.filter_test_tags(test_suite, [], True))
class ParseFilterByTags(unittest.TestCase):
def test_must(self):
self.assertEqual(loader.parse_filter_by_tags(['foo,bar,baz']),
[(set(['foo', 'bar', 'baz']), set([]))])
def test_must_must_not(self):
self.assertEqual(loader.parse_filter_by_tags(['foo,-bar,baz']),
[(set(['foo', 'baz']), set(['bar']))])
def test_musts_must_nots(self):
self.assertEqual(loader.parse_filter_by_tags(['foo,bar,baz',
'-FOO,-BAR,-BAZ']),
[(set(['foo', 'bar', 'baz']), set([])),
(set([]), set(['FOO', 'BAR', 'BAZ']))])
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册