From d577844b7bc9d7fd25d11affe3e17609a843d9b2 Mon Sep 17 00:00:00 2001 From: Davanum Srinivas Date: Tue, 29 Sep 2015 21:44:50 -0400 Subject: [PATCH] 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 --- os_testr/os_testr.py | 7 +++++-- os_testr/tests/test_os_testr.py | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/os_testr/os_testr.py b/os_testr/os_testr.py index 0e5176d..db02446 100755 --- a/os_testr/os_testr.py +++ b/os_testr/os_testr.py @@ -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: diff --git a/os_testr/tests/test_os_testr.py b/os_testr/tests/test_os_testr.py index 85d23ff..65fb0a9 100644 --- a/os_testr/tests/test_os_testr.py +++ b/os_testr/tests/test_os_testr.py @@ -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)