Merge "Support comments in whitelist files"

This commit is contained in:
Jenkins 2016-01-05 17:24:51 +00:00 committed by Gerrit Code Review
commit 29c64b1287
2 changed files with 20 additions and 1 deletions

View File

@ -132,7 +132,14 @@ def path_to_regex(path):
def get_regex_from_whitelist_file(file_path):
return '|'.join(open(file_path).read().splitlines())
lines = []
for line in open(file_path).read().splitlines():
split_line = line.strip().split('#')
# Before the # is the regex
line_regex = split_line[0].strip()
if line_regex:
lines.append(line_regex)
return '|'.join(lines)
def construct_regex(blacklist_file, whitelist_file, regex, print_exclude):

View File

@ -144,6 +144,18 @@ class TestConstructRegex(base.TestCase):
result,
"^((?!fake_regex_3|fake_regex_2|fake_regex_1|fake_regex_0).)*$")
def test_whitelist_regex_with_comments(self):
whitelist_file = six.StringIO()
for i in range(4):
whitelist_file.write('fake_regex_%s # A Comment\n' % i)
whitelist_file.seek(0)
with mock.patch('six.moves.builtins.open',
return_value=whitelist_file):
result = os_testr.construct_regex(None, 'fake_path', None, False)
self.assertEqual(
result,
"fake_regex_0|fake_regex_1|fake_regex_2|fake_regex_3")
def test_blacklist_regex_without_comments(self):
blacklist_file = six.StringIO()
for i in range(4):