diff options
author | Cédric Ollivier <cedric.ollivier@orange.com> | 2018-07-12 10:48:17 +0200 |
---|---|---|
committer | Cédric Ollivier <cedric.ollivier@orange.com> | 2018-07-12 13:26:45 +0200 |
commit | a3138d2df2375d36311114310fcf96a787101e46 (patch) | |
tree | 296f1587e6fb36d847bcebb9e3d14099936ac416 | |
parent | a507f38dc69019523ff02006622eb4ab84cd5ba1 (diff) |
Skip testcases by any env var0.50
It also removes CI_LOOP which is releng centric.
It can be passed as dependency if required.
Change-Id: I146bb97950cb88062451158b7cc6a16c7f9d47a2
Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
-rw-r--r-- | xtesting/ci/run_tests.py | 7 | ||||
-rw-r--r-- | xtesting/ci/testcases.yaml | 1 | ||||
-rw-r--r-- | xtesting/ci/tier_builder.py | 35 | ||||
-rw-r--r-- | xtesting/ci/tier_handler.py | 47 | ||||
-rw-r--r-- | xtesting/tests/unit/ci/test_run_tests.py | 9 | ||||
-rw-r--r-- | xtesting/tests/unit/ci/test_tier_builder.py | 9 | ||||
-rw-r--r-- | xtesting/tests/unit/ci/test_tier_handler.py | 53 |
7 files changed, 31 insertions, 130 deletions
diff --git a/xtesting/ci/run_tests.py b/xtesting/ci/run_tests.py index d77041d2..31451090 100644 --- a/xtesting/ci/run_tests.py +++ b/xtesting/ci/run_tests.py @@ -202,15 +202,12 @@ class Runner(object): tiers_to_run = [] msg = prettytable.PrettyTable( header_style='upper', padding_width=5, - field_names=['tiers', 'order', 'CI Loop', 'description', + field_names=['tiers', 'order', 'description', 'testcases']) for tier in self.tiers.get_tiers(): - ci_loop = env.get('CI_LOOP') - if (tier.get_tests() and - re.search(ci_loop, tier.get_ci_loop()) is not None): + if tier.get_tests(): tiers_to_run.append(tier) msg.add_row([tier.get_name(), tier.get_order(), - tier.get_ci_loop(), textwrap.fill(tier.description, width=40), textwrap.fill(' '.join([str(x.get_name( )) for x in tier.get_tests()]), width=40)]) diff --git a/xtesting/ci/testcases.yaml b/xtesting/ci/testcases.yaml index d9ff36c6..6ab5927f 100644 --- a/xtesting/ci/testcases.yaml +++ b/xtesting/ci/testcases.yaml @@ -3,7 +3,6 @@ tiers: - name: samples order: 1 - ci_loop: 'daily' description: '' testcases: - diff --git a/xtesting/ci/tier_builder.py b/xtesting/ci/tier_builder.py index a4169099..42909810 100644 --- a/xtesting/ci/tier_builder.py +++ b/xtesting/ci/tier_builder.py @@ -9,6 +9,7 @@ """TierBuilder class to parse testcases config file""" +import re import yaml from xtesting.ci import tier_handler @@ -43,34 +44,32 @@ class TierBuilder(object): for dic_tier in self.dic_tier_array: tier = tier_handler.Tier( name=dic_tier['name'], order=dic_tier['order'], - ci_loop=dic_tier['ci_loop'], description=dic_tier['description']) for dic_testcase in dic_tier['testcases']: - if not dic_testcase.get('dependencies'): - installer = '.*' - scenario = '.*' - else: - installer = dic_testcase['dependencies'].get( - 'installer', '.*') - scenario = dic_testcase['dependencies'].get( - 'scenario', '.*') - dep = tier_handler.Dependency(installer, scenario) - testcase = tier_handler.TestCase( name=dic_testcase['case_name'], enabled=dic_testcase.get('enabled', True), - dependency=dep, criteria=dic_testcase['criteria'], + criteria=dic_testcase['criteria'], blocking=dic_testcase['blocking'], description=dic_testcase['description'], project=dic_testcase['project_name']) - if (testcase.is_compatible(self.ci_installer, - self.ci_scenario) and - testcase.is_enabled()): - tier.add_test(testcase) + if not dic_testcase.get('dependencies'): + if testcase.is_enabled(): + tier.add_test(testcase) + else: + tier.skip_test(testcase) else: - tier.skip_test(testcase) - + for dependency in dic_testcase['dependencies']: + kenv = dependency.keys()[0] + if not re.search(dependency[kenv], env.get(kenv)): + tier.skip_test(testcase) + break + else: + if testcase.is_enabled(): + tier.add_test(testcase) + else: + tier.skip_test(testcase) self.tier_objects.append(tier) def get_tiers(self): diff --git a/xtesting/ci/tier_handler.py b/xtesting/ci/tier_handler.py index 0adc9b81..7a77e4cf 100644 --- a/xtesting/ci/tier_handler.py +++ b/xtesting/ci/tier_handler.py @@ -10,7 +10,6 @@ """Tier and TestCase classes to wrap the testcases config file""" # pylint: disable=missing-docstring -import re import textwrap import prettytable @@ -36,12 +35,11 @@ def split_text(text, max_len): class Tier(object): - def __init__(self, name, order, ci_loop, description=""): + def __init__(self, name, order, description=""): self.tests_array = [] self.skipped_tests_array = [] self.name = name self.order = order - self.ci_loop = ci_loop self.description = description def add_test(self, testcase): @@ -84,16 +82,13 @@ class Tier(object): def get_order(self): return self.order - def get_ci_loop(self): - return self.ci_loop - def __str__(self): msg = prettytable.PrettyTable( header_style='upper', padding_width=5, - field_names=['tiers', 'order', 'CI Loop', 'description', + field_names=['tiers', 'order', 'description', 'testcases']) msg.add_row( - [self.name, self.order, self.ci_loop, + [self.name, self.order, textwrap.fill(self.description, width=40), textwrap.fill(' '.join([str(x.get_name( )) for x in self.get_tests()]), width=40)]) @@ -102,27 +97,16 @@ class Tier(object): class TestCase(object): - def __init__(self, name, enabled, dependency, criteria, blocking, + def __init__(self, name, enabled, criteria, blocking, description="", project=""): # pylint: disable=too-many-arguments self.name = name self.enabled = enabled - self.dependency = dependency self.criteria = criteria self.blocking = blocking self.description = description self.project = project - def is_compatible(self, ci_installer, ci_scenario): - try: - if not re.search(self.dependency.get_installer(), ci_installer): - return False - if not re.search(self.dependency.get_scenario(), ci_scenario): - return False - return True - except TypeError: - return False - def get_name(self): return self.name @@ -141,26 +125,7 @@ class TestCase(object): def __str__(self): msg = prettytable.PrettyTable( header_style='upper', padding_width=5, - field_names=['test case', 'description', 'criteria', 'dependency']) + field_names=['test case', 'description', 'criteria']) msg.add_row([self.name, textwrap.fill(self.description, width=40), - self.criteria, self.dependency]) + self.criteria]) return msg.get_string() - - -class Dependency(object): - - def __init__(self, installer='.*', scenario='.*'): - self.installer = installer - self.scenario = scenario - - def get_installer(self): - return self.installer - - def get_scenario(self): - return self.scenario - - def __str__(self): - delimitator = "\n" if self.get_installer( - ) and self.get_scenario() else "" - return "{}{}{}".format(self.get_installer(), delimitator, - self.get_scenario()) diff --git a/xtesting/tests/unit/ci/test_run_tests.py b/xtesting/tests/unit/ci/test_run_tests.py index de2af66d..448b6f3f 100644 --- a/xtesting/tests/unit/ci/test_run_tests.py +++ b/xtesting/tests/unit/ci/test_run_tests.py @@ -153,6 +153,7 @@ class RunTestsTesting(unittest.TestCase): return_value=test_run_dict): self.runner.clean_flag = True self.runner.run_test(mock_test) + args[0].assert_called_with('test_name') args[1].assert_called_with('test_module') self.assertEqual(self.runner.overall_result, @@ -178,16 +179,8 @@ class RunTestsTesting(unittest.TestCase): def test_run_all_default(self, *mock_methods): os.environ['CI_LOOP'] = 'test_ci_loop' self.runner.run_all() - mock_methods[1].assert_not_called() self.assertTrue(mock_methods[2].called) - @mock.patch('xtesting.ci.run_tests.LOGGER.info') - @mock.patch('xtesting.ci.run_tests.Runner.summary') - def test_run_all_missing_tier(self, *mock_methods): - os.environ['CI_LOOP'] = 'loop_re_not_available' - self.runner.run_all() - self.assertTrue(mock_methods[1].called) - @mock.patch('xtesting.ci.run_tests.Runner.source_envfile', side_effect=Exception) @mock.patch('xtesting.ci.run_tests.Runner.summary') diff --git a/xtesting/tests/unit/ci/test_tier_builder.py b/xtesting/tests/unit/ci/test_tier_builder.py index 402fc664..88018472 100644 --- a/xtesting/tests/unit/ci/test_tier_builder.py +++ b/xtesting/tests/unit/ci/test_tier_builder.py @@ -19,21 +19,19 @@ from xtesting.ci import tier_builder class TierBuilderTesting(unittest.TestCase): def setUp(self): - self.dependency = { - 'installer': 'test_installer', 'scenario': 'test_scenario'} self.testcase = { - 'dependencies': self.dependency, 'enabled': True, + 'enabled': True, 'case_name': 'test_name', 'criteria': 'test_criteria', 'blocking': 'test_blocking', 'description': 'test_desc', 'project_name': 'project_name'} self.testcase_disabled = { - 'dependencies': self.dependency, 'enabled': False, + 'enabled': False, 'case_name': 'test_name_disabled', 'criteria': 'test_criteria', 'blocking': 'test_blocking', 'description': 'test_desc', 'project_name': 'project_name'} self.dic_tier = { 'name': 'test_tier', 'order': 'test_order', - 'ci_loop': 'test_ci_loop', 'description': 'test_desc', + 'description': 'test_desc', 'testcases': [self.testcase, self.testcase_disabled]} self.mock_yaml = mock.Mock() attrs = {'get.return_value': [self.dic_tier]} @@ -96,7 +94,6 @@ class TierBuilderTesting(unittest.TestCase): message = str(self.tierbuilder) self.assertTrue('test_tier' in message) self.assertTrue('test_order' in message) - self.assertTrue('test_ci_loop' in message) self.assertTrue('test_desc' in message) self.assertTrue('test_name' in message) diff --git a/xtesting/tests/unit/ci/test_tier_handler.py b/xtesting/tests/unit/ci/test_tier_handler.py index 97ba5ab3..21670dd9 100644 --- a/xtesting/tests/unit/ci/test_tier_handler.py +++ b/xtesting/tests/unit/ci/test_tier_handler.py @@ -22,19 +22,12 @@ class TierHandlerTesting(unittest.TestCase): self.test = mock.Mock() attrs = {'get_name.return_value': 'test_name'} self.test.configure_mock(**attrs) - self.mock_depend = mock.Mock() - attrs = {'get_scenario.return_value': 'test_scenario', - 'get_installer.return_value': 'test_installer'} - self.mock_depend.configure_mock(**attrs) self.tier = tier_handler.Tier( - 'test_tier', 'test_order', 'test_ci_loop', description='test_desc') + 'test_tier', 'test_order', 'test_desc') self.testcase = tier_handler.TestCase( - 'test_name', 'true', self.mock_depend, 'test_criteria', + 'test_name', 'true', 'test_criteria', True, description='test_desc', project='project_name') - self.dependency = tier_handler.Dependency( - 'test_installer', 'test_scenario') self.testcase.str = self.testcase.__str__() - self.dependency.str = self.dependency.__str__() self.tier.str = self.tier.__str__() def test_split_text(self): @@ -77,39 +70,6 @@ class TierHandlerTesting(unittest.TestCase): def test_get_order(self): self.assertEqual(self.tier.get_order(), 'test_order') - def test_get_ci_loop(self): - self.assertEqual(self.tier.get_ci_loop(), 'test_ci_loop') - - def test_testcase_is_compatible(self): - self.assertEqual( - self.testcase.is_compatible('test_installer', 'test_scenario'), - True) - - def test_testcase_is_compatible_2(self): - self.assertEqual( - self.testcase.is_compatible('missing_installer', 'test_scenario'), - False) - self.assertEqual( - self.testcase.is_compatible('test_installer', 'missing_scenario'), - False) - - @mock.patch('re.search', side_effect=TypeError) - def test_testcase_is_compatible3(self, *args): - self.assertEqual( - self.testcase.is_compatible('test_installer', 'test_scenario'), - False) - args[0].assert_called_once_with('test_installer', 'test_installer') - - def test_testcase_is_compatible_4(self): - self.assertEqual( - self.testcase.is_compatible(None, 'test_scenario'), False) - self.assertEqual( - self.testcase.is_compatible('', 'test_scenario'), False) - self.assertEqual( - self.testcase.is_compatible('test_installer', None), False) - self.assertEqual( - self.testcase.is_compatible('test_installer', ''), False) - def test_testcase_get_name(self): self.assertEqual(self.tier.get_name(), 'test_tier') @@ -128,15 +88,6 @@ class TierHandlerTesting(unittest.TestCase): def test_testcase_get_order(self): self.assertEqual(self.tier.get_order(), 'test_order') - def test_testcase_get_ci_loop(self): - self.assertEqual(self.tier.get_ci_loop(), 'test_ci_loop') - - def test_dependency_get_installer(self): - self.assertEqual(self.dependency.get_installer(), 'test_installer') - - def test_dependency_get_scenario(self): - self.assertEqual(self.dependency.get_scenario(), 'test_scenario') - if __name__ == "__main__": logging.disable(logging.CRITICAL) |