# of appearance. Changing the order has an impact on the overall integration
# process, which may cause wedges in the gate later.
pbr!=2.1.0,>=2.0.0 # Apache-2.0
+stevedore>=1.20.0 # Apache-2.0
PyYAML>=3.12 # MIT
enum34>=1.0.4;python_version=='2.7' or python_version=='2.6' or python_version=='3.3' # BSD
requests>=2.14.2 # Apache-2.0
[entry_points]
console_scripts =
run_tests = xtesting.ci.run_tests:main
+xtesting.testcase =
+ bashfeature = xtesting.core.feature:BashFeature
+ robotframework = xtesting.core.robotframework:RobotFramework
+ unit = xtesting.core.unit:Suite
+ first = xtesting.samples.first:Test
+ second = xtesting.samples.second:Test
[build_sphinx]
all_files = 1
[tox]
envlist = docs,pep8,pylint,yamllint,bashate,py35,py27,perm,cover
+skipsdist = True
[testenv]
usedevelop = True
import argparse
import errno
-import importlib
import logging
import logging.config
import os
import pkg_resources
import prettytable
import six
+from stevedore import driver
import yaml
from xtesting.ci import tier_builder
if run_dict:
try:
LOGGER.info("Loading test case '%s'...", test.get_name())
- module = importlib.import_module(run_dict['module'])
- cls = getattr(module, run_dict['class'])
test_dict = Runner.get_dict_by_test(test.get_name())
- test_case = cls(**test_dict)
+ test_case = driver.DriverManager(
+ namespace='xtesting.testcase',
+ name=run_dict['name'],
+ invoke_on_load=True,
+ invoke_kwds=test_dict).driver
self.executed_test_cases[test.get_name()] = test_case
test_case.check_requirements()
if test_case.is_skipped:
clean_flag: false
description: ''
run:
- module: 'xtesting.samples.first'
- class: 'Test'
+ name: 'first'
-
case_name: second
clean_flag: false
description: ''
run:
- module: 'xtesting.samples.second'
- class: 'Test'
+ name: 'second'
-
case_name: third
clean_flag: false
description: ''
run:
- module: 'xtesting.core.feature'
- class: 'BashFeature'
+ name: 'bashfeature'
args:
cmd: 'echo -n Hello World; exit 0'
clean_flag: false
description: ''
run:
- module: 'xtesting.core.unit'
- class: 'Suite'
+ name: 'unit'
args:
name: 'xtesting.samples.fourth'
helpers to run any python method or any bash command.
"""
+import abc
import logging
import subprocess
import time
+import six
from xtesting.core import testcase
__author__ = ("Serena Feng <feng.xiaowei@zte.com.cn>, "
"Cedric Ollivier <cedric.ollivier@orange.com>")
+@six.add_metaclass(abc.ABCMeta)
class Feature(testcase.TestCase):
"""Base model for single feature."""
__logger = logging.getLogger(__name__)
+ @abc.abstractmethod
def execute(self, **kwargs):
"""Execute the Python method.
Args:
kwargs: Arbitrary keyword arguments.
-
- Returns:
- -1.
"""
- # pylint: disable=unused-argument,no-self-use
- return -1
def run(self, **kwargs):
"""Run the feature.
"""Define the parent class of all Xtesting TestCases."""
+import abc
from datetime import datetime
import json
import logging
import requests
import prettytable
+import six
from xtesting.utils import decorators
from xtesting.utils import env
__author__ = "Cedric Ollivier <cedric.ollivier@orange.com>"
-class TestCase(object): # pylint: disable=too-many-instance-attributes
+@six.add_metaclass(abc.ABCMeta)
+class TestCase(object):
+ # pylint: disable=too-many-instance-attributes
"""Base model for single test case."""
EX_OK = os.EX_OK
"""
self.is_skipped = False
+ @abc.abstractmethod
def run(self, **kwargs):
"""Run the test case.
Args:
kwargs: Arbitrary keyword arguments.
-
- Returns:
- TestCase.EX_RUN_ERROR.
"""
- # pylint: disable=unused-argument
- self.__logger.error("Run must be implemented")
- return TestCase.EX_RUN_ERROR
@decorators.can_dump_request_to_file
def push_to_db(self):
class FakeModule(TestCase):
def run(self, **kwargs):
+ self.start_time = 0
+ self.stop_time = 1
+ self.criteria = 100
+ self.result = 100
return TestCase.EX_OK
msg = "Cannot import the class for the test case."
self.assertTrue(msg in str(context.exception))
- @mock.patch('importlib.import_module', name="module",
- return_value=mock.Mock(test_class=mock.Mock(
- side_effect=FakeModule)))
+ @mock.patch('stevedore.driver.DriverManager',
+ return_value=mock.Mock(driver=FakeModule()))
@mock.patch('xtesting.ci.run_tests.Runner.get_dict_by_test')
def test_run_tests_default(self, *args):
mock_test = mock.Mock()
'is_enabled.return_value': True,
'needs_clean.return_value': True}
mock_test.configure_mock(**kwargs)
- test_run_dict = {'module': 'test_module',
- 'class': 'test_class'}
+ test_run_dict = {'name': 'test_module'}
with mock.patch('xtesting.ci.run_tests.Runner.get_run_dict',
return_value=test_run_dict):
self.runner.clean_flag = True
- self.runner.run_test(mock_test)
+ self.assertEqual(self.runner.run_test(mock_test), TestCase.EX_OK)
args[0].assert_called_with('test_name')
- args[1].assert_called_with('test_module')
+ args[1].assert_called_with(
+ invoke_kwds=mock.ANY, invoke_on_load=True, name='test_module',
+ namespace='xtesting.testcase')
self.assertEqual(self.runner.overall_result,
run_tests.Result.EX_OK)
'is_enabled.return_value': False,
'needs_clean.return_value': True}
mock_test.configure_mock(**kwargs)
- test_run_dict = {'module': 'test_module',
- 'class': 'test_class'}
+ test_run_dict = {'name': 'test_name'}
with mock.patch('xtesting.ci.run_tests.Runner.get_run_dict',
return_value=test_run_dict):
self.runner.clean_flag = True
from xtesting.core import testcase
+class FakeTestCase(feature.Feature):
+
+ def execute(self, **kwargs):
+ pass
+
+
+class AbstractFeatureTesting(unittest.TestCase):
+
+ def test_run_unimplemented(self):
+ with self.assertRaises(TypeError):
+ feature.Feature(case_name="feature", project_name="xtesting")
+
+
class FeatureTestingBase(unittest.TestCase):
_case_name = "foo"
# what will break these unit tests.
logging.disable(logging.CRITICAL)
with mock.patch('six.moves.builtins.open'):
- self.feature = feature.Feature(
+ self.feature = FakeTestCase(
project_name=self._project_name, case_name=self._case_name)
def test_run_exc(self):
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
+# pylint: disable=missing-docstring
+
"""Define the class required to fully cover testcase."""
from datetime import datetime
__author__ = "Cedric Ollivier <cedric.ollivier@orange.com>"
-class TestCaseTesting(unittest.TestCase):
- """The class testing TestCase."""
+class FakeTestCase(testcase.TestCase):
+ # pylint: disable=too-many-instance-attributes
+
+ def run(self, **kwargs):
+ return testcase.TestCase.EX_OK
+
+
+class AbstractTestCaseTesting(unittest.TestCase):
+
+ def test_run_unimplemented(self):
+ with self.assertRaises(TypeError):
+ testcase.TestCase(case_name="base", project_name="xtesting")
- # pylint: disable=missing-docstring,too-many-public-methods
+
+class TestCaseTesting(unittest.TestCase):
+ # pylint: disable=too-many-instance-attributes,too-many-public-methods
_case_name = "base"
_project_name = "xtesting"
_headers = {'Content-Type': 'application/json'}
def setUp(self):
- self.test = testcase.TestCase(case_name=self._case_name,
- project_name=self._project_name)
+ self.test = FakeTestCase(
+ case_name=self._case_name, project_name=self._project_name)
self.test.start_time = 1
self.test.stop_time = 2
self.test.result = 100
os.environ['NODE_NAME'] = "node_name"
os.environ['BUILD_TAG'] = "foo-daily-master-bar"
- def test_run_unimplemented(self):
- self.assertEqual(self.test.run(),
- testcase.TestCase.EX_RUN_ERROR)
+ def test_run_fake(self):
+ self.assertEqual(self.test.run(), testcase.TestCase.EX_OK)
def _test_pushdb_missing_attribute(self):
self.assertEqual(self.test.push_to_db(),
def test_str_project_name_ko(self):
self.test.project_name = None
- self.assertIn("<xtesting.core.testcase.TestCase object at",
- str(self.test))
+ self.assertIn("FakeTestCase object at", str(self.test))
def test_str_case_name_ko(self):
self.test.case_name = None
- self.assertIn("<xtesting.core.testcase.TestCase object at",
- str(self.test))
+ self.assertIn("FakeTestCase object at", str(self.test))
def test_str_pass(self):
duration = '01:01'
URL = 'file://{}'.format(FILE)
+class FakeTestCase(testcase.TestCase):
+ # pylint: disable=missing-docstring
+
+ def run(self, **kwargs):
+ return testcase.TestCase.EX_OK
+
+
class DecoratorsTesting(unittest.TestCase):
# pylint: disable=missing-docstring
return json.dumps(data, sort_keys=True)
def _get_testcase(self):
- test = testcase.TestCase(
+ test = FakeTestCase(
project_name=self._project_name, case_name=self._case_name)
test.start_time = self._start_time
test.stop_time = self._stop_time
test.details = {}
return test
+ def test_run_fake(self):
+ test = self._get_testcase()
+ self.assertEqual(test.run(), testcase.TestCase.EX_OK)
+
@mock.patch('requests.post')
def test_http_shema(self, *args):
os.environ['TEST_DB_URL'] = 'http://127.0.0.1'