Support comments in whitelist files

We already support comments in blacklist files. we should
do the same for whitelist files as well.

Change-Id: I5ad0c113cdb04dd1bdaa4d8bfdd1a3ab169fb0af
This commit is contained in:
Davanum Srinivas 2016-01-05 11:43:28 -05:00
parent befba5c111
commit b46734734b
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):