Fix regex to find test names

Create a whilelist file including only the test names with
the regex expression "test_name\[" since some test names can be a
subset of others

Change-Id: I4b4e60e2c2e1bae7d6a86f9af993390ecd7ccf7b
This commit is contained in:
Ghe Rivero 2016-10-03 18:20:34 +02:00
parent 65b7d3d99a
commit c824952594
2 changed files with 31 additions and 6 deletions
refstack_client

@ -208,15 +208,18 @@ class TestListParser(object):
def create_whitelist(self, list_location):
"""This takes in a test list file, get normalized, and get whitelist
test IDs.
regexes using full qualified test names (one per line).
Ex:
'tempest.test1[id-2,gate]' -> id-2
'tempest.test2[id-3,smoke](scenario)' -> id-3
'tempest.test1[id-2,gate]' -> tempest.test1\[
'tempest.test2[id-3,smoke](scenario)' -> tempest.test2\[
'tempest.test3[compute,id-4]' -> tempest.test3\[
:param list_location: file path or URL location of list file
"""
normalized_list = open(self.get_normalized_test_list(list_location),
'r').read()
# Keep the IDs
test_ids = re.sub("[\,\]].*", "", re.sub(".*.\[", "", normalized_list))
return self._write_normalized_test_list(test_ids.split('\n'))
# Keep the names
tests_list = [re.sub("\[", "\[", test)
for test in re.findall(".*\[", normalized_list)]
return self._write_normalized_test_list(tests_list)

@ -17,6 +17,7 @@ import logging
import os
import requests
import subprocess
import tempfile
import httmock
import mock
@ -184,3 +185,24 @@ class TestTestListParser(unittest.TestCase):
subprocess.Popen = mock.Mock(return_value=process_mock)
with self.assertRaises(subprocess.CalledProcessError):
self.parser.setup_venv(logging.DEBUG)
@mock.patch.object(parser.TestListParser, "get_normalized_test_list")
def test_create_whitelist(self, mock_get_normalized):
"""Test whether a test list is properly parsed to extract test names"""
test_list = [
"tempest.test.one[id-11111111-2222-3333-4444-555555555555,gate]",
"tempest.test.two[comp,id-22222222-3333-4444-5555-666666666666]",
"tempest.test.three[id-33333333-4444-5555-6666-777777777777](gate)"
]
expected_list = "tempest.test.one\[\n"\
"tempest.test.two\[\n"\
"tempest.test.three\[\n"
tmpfile = tempfile.mktemp()
with open(tmpfile, 'w') as f:
[f.write(item + "\n") for item in test_list]
mock_get_normalized.return_value = tmpfile
result = open(self.parser.create_whitelist(tmpfile)).read()
self.assertEqual(result, expected_list)