Better blacklist - tested with Nova

So in Nova, i wanted to add a text file with a list of
test ids like so:

nova.tests.unit.api.ec2.test_api.ApiEc2TestCase
nova.tests.unit.api.ec2.test_apirequest.APIRequestTestCase
nova.tests.unit.api.ec2.test_cinder_cloud.CinderCloudTestCase
nova.tests.unit.api.ec2.test_cloud.CloudTestCase
functional

to skip those specific test cases and any functional tests and
the current code would not work, so digging through the
regexp(s) on stack overflow and found this:
http://stackoverflow.com/questions/406230/regular-expression-to-match-line-that-doesnt-contain-a-word

Works like a charm!

Change-Id: I0e947c599ab19276f35150749d559487d9790028
This commit is contained in:
Davanum Srinivas 2015-09-29 21:44:50 -04:00
parent 368a2553cd
commit d577844b7b
2 changed files with 15 additions and 12 deletions

View File

@ -152,9 +152,12 @@ def construct_regex(blacklist_file, whitelist_file, regex, print_exclude):
if line_regex:
if print_exclude:
print_skips(line_regex, comment)
exclude_regex = '|'.join([line_regex, exclude_regex])
if exclude_regex:
exclude_regex = '|'.join([line_regex, exclude_regex])
else:
exclude_regex = line_regex
if exclude_regex:
exclude_regex = "(?!.*" + exclude_regex + ")"
exclude_regex = "^((?!" + exclude_regex + ").)*$"
if regex:
exclude_regex += regex
if whitelist_file:

View File

@ -142,7 +142,7 @@ class TestConstructRegex(base.TestCase):
result = os_testr.construct_regex('fake_path', None, None, False)
self.assertEqual(
result,
"(?!.*fake_regex_3|fake_regex_2|fake_regex_1|fake_regex_0|)")
"^((?!fake_regex_3|fake_regex_2|fake_regex_1|fake_regex_0).)*$")
def test_blacklist_regex_without_comments(self):
blacklist_file = six.StringIO()
@ -154,7 +154,7 @@ class TestConstructRegex(base.TestCase):
result = os_testr.construct_regex('fake_path', None, None, False)
self.assertEqual(
result,
"(?!.*fake_regex_3|fake_regex_2|fake_regex_1|fake_regex_0|)")
"^((?!fake_regex_3|fake_regex_2|fake_regex_1|fake_regex_0).)*$")
def test_blacklist_regex_with_comments_and_regex(self):
blacklist_file = six.StringIO()
@ -166,8 +166,8 @@ class TestConstructRegex(base.TestCase):
result = os_testr.construct_regex('fake_path', None,
'fake_regex', False)
expected_regex = ("(?!.*fake_regex_3|fake_regex_2|fake_regex_1|"
"fake_regex_0|)fake_regex")
expected_regex = ("^((?!fake_regex_3|fake_regex_2|fake_regex_1|"
"fake_regex_0).)*$fake_regex")
self.assertEqual(result, expected_regex)
def test_blacklist_regex_without_comments_and_regex(self):
@ -180,8 +180,8 @@ class TestConstructRegex(base.TestCase):
result = os_testr.construct_regex('fake_path', None,
'fake_regex', False)
expected_regex = ("(?!.*fake_regex_3|fake_regex_2|fake_regex_1|"
"fake_regex_0|)fake_regex")
expected_regex = ("^((?!fake_regex_3|fake_regex_2|fake_regex_1|"
"fake_regex_0).)*$fake_regex")
self.assertEqual(result, expected_regex)
@mock.patch.object(os_testr, 'print_skips')
@ -195,8 +195,8 @@ class TestConstructRegex(base.TestCase):
result = os_testr.construct_regex('fake_path', None,
None, True)
expected_regex = ("(?!.*fake_regex_3|fake_regex_2|fake_regex_1|"
"fake_regex_0|)")
expected_regex = ("^((?!fake_regex_3|fake_regex_2|fake_regex_1|"
"fake_regex_0).)*$")
self.assertEqual(result, expected_regex)
calls = print_mock.mock_calls
self.assertEqual(len(calls), 4)
@ -217,8 +217,8 @@ class TestConstructRegex(base.TestCase):
result = os_testr.construct_regex('fake_path', None,
None, True)
expected_regex = ("(?!.*fake_regex_3|fake_regex_2|fake_regex_1|"
"fake_regex_0|)")
expected_regex = ("^((?!fake_regex_3|fake_regex_2|"
"fake_regex_1|fake_regex_0).)*$")
self.assertEqual(result, expected_regex)
calls = print_mock.mock_calls
self.assertEqual(len(calls), 4)