Make the listbuilder the default strategy

The listbuilder is able to support very long white list.

construct_regex is considered as deprecated function,
but external project like tempest still using it at the moment.
os-testr internally does not uses it anymore.

Change-Id: I0748605207eaad3065e18b84eecc9ddc4e47404e
This commit is contained in:
Attila Fazekas 2016-09-06 09:35:29 +02:00
parent a3b403bd4e
commit ea7fb00122
3 changed files with 23 additions and 9 deletions

View File

@ -122,7 +122,7 @@ def call_testr(regex, subunit, pretty, list_tests, slowest, parallel, concur,
test_file.write('\n'.join(list_of_tests) + '\n')
test_file.close()
cmd.extend(('--load-list', test_file_name))
else:
elif regex:
cmd.append(regex)
env = copy.deepcopy(os.environ)
@ -269,20 +269,14 @@ def main():
else:
regex = opts.regex
if opts.regex and opts.blacklist_file:
# NOTE(afazekas): Now just the minority of the cases is handled
# by the testlist_builder, it can be changed in the future.
if opts.blacklist_file or opts.whitelist_file:
list_of_tests = tlb.construct_list(opts.blacklist_file,
opts.whitelist_file,
regex,
opts.print_exclude)
exit(_call_testr_with_list(opts, list_of_tests, others))
else:
exclude_regex = rb.construct_regex(opts.blacklist_file,
opts.whitelist_file,
regex,
opts.print_exclude)
exit(_select_and_call_runner(opts, exclude_regex, others))
exit(_select_and_call_runner(opts, regex, others))
if __name__ == '__main__':
main()

View File

@ -68,6 +68,7 @@ def get_regex_from_whitelist_file(file_path):
def construct_regex(blacklist_file, whitelist_file, regex, print_exclude):
"""Deprecated, please use testlist_builder.construct_list instead."""
if not blacklist_file:
exclude_regex = ''
else:

View File

@ -77,3 +77,22 @@ class TestConstructList(base.TestCase):
False)
self.assertEqual(set(result),
set(('fake_test1[tg]', 'fake_test2[tg]')))
def test_whitelist_blacklist_re(self):
white_list = 'fake_test1|fake_test2'
test_lists = ['fake_test1[tg]', 'fake_test2[spam]',
'fake_test3[tg,foo]', 'fake_test4[spam]']
black_list = [(re.compile('spam'), 'spam not liked', [])]
white_getter = 'os_testr.regex_builder.get_regex_from_whitelist_file'
with mock.patch('os_testr.regex_builder._get_test_list',
return_value=test_lists):
with mock.patch(white_getter,
return_value=white_list):
with mock.patch('os_testr.testlist_builder.black_reader',
return_value=black_list):
result = list_builder.construct_list('black_file',
'white_file',
'foo',
False)
self.assertEqual(set(result),
set(('fake_test1[tg]', 'fake_test3[tg,foo]')))