提交 b0a67c1e 编写于 作者: C Cleber Rosa

Tags: replace internal representation from set to dict

This basically allows us to use the same set interface for checking if
a tag is in a set (the dict keys), and at the same time, allows us to
have room for the values given to key:val tags.

For "flat" tags, that is, ones that do not contain any value, the
dictionary will just contain None, and for the key:val tags, the
dictionary will contain a set of the values.  The set is useful
because duplicate values add no value, and a common use case
is to have a base value at the class level, and have it extended
in the
Signed-off-by: NCleber Rosa <crosa@redhat.com>
上级 fb3e572f
......@@ -81,7 +81,7 @@ def filter_test_tags(test_suite, filter_by_tags, include_empty=False):
"""
filtered = []
for klass, info in test_suite:
test_tags = info.get('tags', set([]))
test_tags = info.get('tags', {})
if not test_tags and include_empty:
filtered.append((klass, info))
continue
......
......@@ -167,15 +167,24 @@ def get_docstring_directives_tags(docstring):
Returns the test categories based on a `:avocado: tags=category`
docstring
:rtype: set
:rtype: dict
"""
tags = []
result = {}
for item in get_docstring_directives(docstring):
if item.startswith('tags='):
_, comma_tags = item.split('tags=', 1)
tags.extend([tag for tag in comma_tags.split(',') if tag])
return set(tags)
for tag in comma_tags.split(','):
if not tag:
continue
if ':' in tag:
key, val = tag.split(':', 1)
if key in result:
result[key].add(val)
else:
result[key] = set([val])
else:
result[tag] = None
return result
def find_class_and_methods(path, method_pattern=None, base_class=None):
......
......@@ -93,6 +93,13 @@ class SafeTest(Test):
def test_safe(self):
pass
class SafeX86Test(Test):
'''
:avocado: tags=safe,arch:x86_64
'''
def test_safe_x86(self):
pass
if __name__ == "__main__":
main()
"""
......@@ -437,7 +444,7 @@ class TagFilter(unittest.TestCase):
loader.DiscoverMode.ALL)
def test_no_tag_filter(self):
self.assertEqual(len(self.test_suite), 5)
self.assertEqual(len(self.test_suite), 6)
self.assertEqual(self.test_suite[0][0], 'FastTest')
self.assertEqual(self.test_suite[0][1]['methodName'], 'test_fast')
self.assertEqual(self.test_suite[1][0], 'FastTest')
......@@ -486,7 +493,7 @@ class TagFilter(unittest.TestCase):
def test_filter_not_fast_not_slow(self):
filtered = loader.filter_test_tags(self.test_suite,
['-fast,-slow'])
self.assertEqual(len(filtered), 1)
self.assertEqual(len(filtered), 2)
self.assertEqual(filtered[0][0], 'SafeTest')
self.assertEqual(filtered[0][1]['methodName'], 'test_safe')
......@@ -502,13 +509,15 @@ class TagFilter(unittest.TestCase):
self.assertEqual(len(filtered), 0)
def test_load_tags(self):
tags_map = {'FastTest.test_fast': set(['fast', 'net']),
'FastTest.test_fast_other': set(['fast', 'net']),
'SlowTest.test_slow': set(['slow', 'disk']),
'SlowUnsafeTest.test_slow_unsafe': set(['slow',
'disk',
'unsafe']),
'SafeTest.test_safe': set(['safe'])}
tags_map = {'FastTest.test_fast': {'fast': None, 'net': None},
'FastTest.test_fast_other': {'fast': None, 'net': None},
'SlowTest.test_slow': {'slow': None, 'disk': None},
'SlowUnsafeTest.test_slow_unsafe': {'slow': None,
'disk': None,
'unsafe': None},
'SafeTest.test_safe': {'safe': None},
'SafeX86Test.test_safe_x86': {'safe': None,
'arch': set(['x86_64'])}}
for _, info in self.test_suite:
name = info['name'].split(':', 1)[1]
......
......@@ -162,51 +162,66 @@ class DocstringDirectives(unittest.TestCase):
def test_get_tags_empty(self):
for tag in self.NO_TAGS:
self.assertEqual(set([]), safeloader.get_docstring_directives_tags(tag))
self.assertEqual({}, safeloader.get_docstring_directives_tags(tag))
def test_tag_single(self):
raw = ":avocado: tags=fast"
exp = set(["fast"])
exp = {"fast": None}
self.assertEqual(safeloader.get_docstring_directives_tags(raw), exp)
def test_tag_double(self):
raw = ":avocado: tags=fast,network"
exp = set(["fast", "network"])
exp = {"fast": None, "network": None}
self.assertEqual(safeloader.get_docstring_directives_tags(raw), exp)
def test_tag_double_with_empty(self):
raw = ":avocado: tags=fast,,network"
exp = set(["fast", "network"])
exp = {"fast": None, "network": None}
self.assertEqual(safeloader.get_docstring_directives_tags(raw), exp)
def test_tag_lowercase_uppercase(self):
raw = ":avocado: tags=slow,DISK"
exp = set(["slow", "DISK"])
exp = {"slow": None, "DISK": None}
self.assertEqual(safeloader.get_docstring_directives_tags(raw), exp)
def test_tag_duplicate(self):
raw = ":avocado: tags=SLOW,disk,disk"
exp = set(["SLOW", "disk"])
exp = {"SLOW": None, "disk": None}
self.assertEqual(safeloader.get_docstring_directives_tags(raw), exp)
def test_tag_tab_separator(self):
raw = ":avocado:\ttags=FAST"
exp = set(["FAST"])
exp = {"FAST": None}
self.assertEqual(safeloader.get_docstring_directives_tags(raw), exp)
def test_tag_empty(self):
raw = ":avocado: tags="
exp = set([])
exp = {}
self.assertEqual(safeloader.get_docstring_directives_tags(raw), exp)
def test_tag_newline_before(self):
raw = ":avocado: enable\n:avocado: tags=fast"
exp = set(["fast"])
exp = {"fast": None}
self.assertEqual(safeloader.get_docstring_directives_tags(raw), exp)
def test_tag_newline_after(self):
raw = ":avocado: tags=fast,slow\n:avocado: enable"
exp = set(["fast", "slow"])
exp = {"fast": None, "slow": None}
self.assertEqual(safeloader.get_docstring_directives_tags(raw), exp)
def test_tag_keyval_single(self):
raw = ":avocado: tags=fast,arch:x86_64"
exp = {"fast": None, "arch": set(["x86_64"])}
self.assertEqual(safeloader.get_docstring_directives_tags(raw), exp)
def test_tag_keyval_double(self):
raw = ":avocado: tags=fast,arch:x86_64,arch:ppc64"
exp = {"fast": None, "arch": set(["x86_64", "ppc64"])}
self.assertEqual(safeloader.get_docstring_directives_tags(raw), exp)
def test_tag_keyval_duplicate(self):
raw = ":avocado: tags=fast,arch:x86_64,arch:ppc64,arch:x86_64"
exp = {"fast": None, "arch": set(["x86_64", "ppc64"])}
self.assertEqual(safeloader.get_docstring_directives_tags(raw), exp)
def test_directives_regex(self):
......@@ -253,6 +268,9 @@ class FindClassAndMethods(UnlimitedDiff):
'test_tag_empty',
'test_tag_newline_before',
'test_tag_newline_after',
'test_tag_keyval_single',
'test_tag_keyval_double',
'test_tag_keyval_duplicate',
'test_directives_regex'],
'FindClassAndMethods': ['test_self',
'test_with_pattern',
......@@ -285,6 +303,9 @@ class FindClassAndMethods(UnlimitedDiff):
'test_tag_empty',
'test_tag_newline_before',
'test_tag_newline_after',
'test_tag_keyval_single',
'test_tag_keyval_double',
'test_tag_keyval_duplicate',
'test_directives_regex'],
'FindClassAndMethods': ['test_self',
'test_with_pattern',
......@@ -345,10 +366,10 @@ class FindClassAndMethods(UnlimitedDiff):
sys.path.append(os.path.dirname(avocado_recursive_discovery_test1.path))
tests = safeloader.find_avocado_tests(avocado_recursive_discovery_test2.path)[0]
expected = {'ThirdChild': [('test_third_child', set([])),
('test_second_child', set([])),
('test_first_child', set([])),
('test_basic', set([]))]}
expected = {'ThirdChild': [('test_third_child', {}),
('test_second_child', {}),
('test_first_child', {}),
('test_basic', {})]}
self.assertEqual(expected, tests)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册