未验证 提交 02314957 编写于 作者: C Caio Carrara

Merge remote-tracking branch 'clebergnu/tags_key_val_prep'

Signed-off-by: NCaio Carrara <ccarrara@redhat.com>
......@@ -81,22 +81,26 @@ 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
for raw_tags in filter_by_tags:
required_tags = raw_tags.split(',')
must_not_have_tags = set([_[1:] for _ in required_tags
if _.startswith('-')])
if must_not_have_tags.intersection(test_tags):
must = set()
must_not = set()
for tag in required_tags:
if tag.startswith('-'):
must_not.add(tag[1:])
else:
must.add(tag)
if must_not.intersection(test_tags):
continue
must_have_tags = set([_ for _ in required_tags
if not _.startswith('-')])
if must_have_tags:
if not must_have_tags.issubset(test_tags):
if must:
if not must.issubset(test_tags):
continue
filtered.append((klass, info))
......
......@@ -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]
......
......@@ -133,17 +133,6 @@ class DocstringDirectives(unittest.TestCase):
":avocado: tags=SLOW,disk, invalid",
":avocado: tags=SLOW,disk , invalid"]
VALID_TAGS = {":avocado: tags=fast": set(["fast"]),
":avocado: tags=fast,network": set(["fast", "network"]),
":avocado: tags=fast,,network": set(["fast", "network"]),
":avocado: tags=slow,DISK": set(["slow", "DISK"]),
":avocado: tags=SLOW,disk,disk": set(["SLOW", "disk"]),
":avocado:\ttags=FAST": set(["FAST"]),
":avocado: tags=": set([]),
":avocado: enable\n:avocado: tags=fast": set(["fast"]),
":avocado: tags=fast,slow\n:avocado: enable": set(["fast", "slow"])
}
def test_longline(self):
docstring = ("This is a very long docstring in a single line. "
"Since we have nothing useful to put in here let's just "
......@@ -173,11 +162,67 @@ 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))
def test_get_tags(self):
for raw, tags in self.VALID_TAGS.items():
self.assertEqual(safeloader.get_docstring_directives_tags(raw), tags)
self.assertEqual({}, safeloader.get_docstring_directives_tags(tag))
def test_tag_single(self):
raw = ":avocado: tags=fast"
exp = {"fast": None}
self.assertEqual(safeloader.get_docstring_directives_tags(raw), exp)
def test_tag_double(self):
raw = ":avocado: tags=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 = {"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 = {"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 = {"SLOW": None, "disk": None}
self.assertEqual(safeloader.get_docstring_directives_tags(raw), exp)
def test_tag_tab_separator(self):
raw = ":avocado:\ttags=FAST"
exp = {"FAST": None}
self.assertEqual(safeloader.get_docstring_directives_tags(raw), exp)
def test_tag_empty(self):
raw = ":avocado: tags="
exp = {}
self.assertEqual(safeloader.get_docstring_directives_tags(raw), exp)
def test_tag_newline_before(self):
raw = ":avocado: enable\n:avocado: tags=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 = {"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):
"""
......@@ -214,7 +259,18 @@ class FindClassAndMethods(UnlimitedDiff):
'test_enabled',
'test_disabled',
'test_get_tags_empty',
'test_get_tags',
'test_tag_single',
'test_tag_double',
'test_tag_double_with_empty',
'test_tag_lowercase_uppercase',
'test_tag_duplicate',
'test_tag_tab_separator',
'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',
......@@ -238,7 +294,18 @@ class FindClassAndMethods(UnlimitedDiff):
'test_enabled',
'test_disabled',
'test_get_tags_empty',
'test_get_tags',
'test_tag_single',
'test_tag_double',
'test_tag_double_with_empty',
'test_tag_lowercase_uppercase',
'test_tag_duplicate',
'test_tag_tab_separator',
'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',
......@@ -299,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.
先完成此消息的编辑!
想要评论请 注册