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:
parent
befba5c111
commit
b46734734b
@ -132,7 +132,14 @@ def path_to_regex(path):
|
|||||||
|
|
||||||
|
|
||||||
def get_regex_from_whitelist_file(file_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):
|
def construct_regex(blacklist_file, whitelist_file, regex, print_exclude):
|
||||||
|
@ -144,6 +144,18 @@ class TestConstructRegex(base.TestCase):
|
|||||||
result,
|
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_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):
|
def test_blacklist_regex_without_comments(self):
|
||||||
blacklist_file = six.StringIO()
|
blacklist_file = six.StringIO()
|
||||||
for i in range(4):
|
for i in range(4):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user