Merge "Use regex to check if test belong to test set"

This commit is contained in:
Jenkins 2015-01-14 13:36:13 +00:00 committed by Gerrit Code Review
commit 43da5cee06
2 changed files with 36 additions and 1 deletions

View File

@ -14,6 +14,7 @@
import logging
import os
import re
from nose import plugins
@ -68,10 +69,18 @@ class DiscoveryPlugin(plugins.Plugin):
)
LOG.info('%s discovered.', module.__name__)
@classmethod
def test_belongs_to_testset(cls, test_id, test_set_id):
"""Checks by name if test belongs to given test set."""
test_set_pattern = re.compile(
r'(\b|_){0}(\b|_)'.format(test_set_id)
)
return bool(test_set_pattern.search(test_id))
def addSuccess(self, test):
test_id = test.id()
for test_set_id in self.test_sets.keys():
if test_set_id in test_id:
if self.test_belongs_to_testset(test_id, test_set_id):
data = dict()
(data['title'], data['description'],

View File

@ -131,3 +131,29 @@ class TestNoseDiscovery(base.BaseUnitTest):
needed_test.deployment_tags,
expected['test']['deployment_tags']
)
def test_if_test_belongs_to_test_set(self):
test_set_id = 'ha'
pass_checks = (
'test_ha_sth',
'test-ha-ha',
'test.ha.sahara',
'test.ha.sth',
)
fail_checks = (
'test_sahara',
'test.nonha.sth',
'test.nonha.sahara',
)
for test_id in pass_checks:
self.assertTrue(
nose_discovery.DiscoveryPlugin.test_belongs_to_testset(
test_id, test_set_id)
)
for test_id in fail_checks:
self.assertFalse(
nose_discovery.DiscoveryPlugin.test_belongs_to_testset(
test_id, test_set_id)
)