aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCédric Ollivier <cedric.ollivier@orange.com>2017-06-30 05:04:20 +0200
committerCédric Ollivier <cedric.ollivier@orange.com>2017-06-30 05:12:39 +0200
commit5093eefb73d0f01d383fe55fdf7fdbd63f8888f2 (patch)
tree42599a4431a16809bb32e7fde98796366224ed21
parentfbc676b2bcf63382a39c5b54d47c608a20a8cfea (diff)
Define ODL console_script
main() is excluded from coverage as it usually parses argv. It also renames ODLTests main() to run_suites() not to exclude this method. Change-Id: I3109a65166b21d93e3e376912a32d364931a7ba5 Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
-rw-r--r--.coveragerc1
-rw-r--r--[-rwxr-xr-x]functest/opnfv_tests/sdn/odl/odl.py27
-rw-r--r--functest/tests/unit/odl/test_odl.py48
-rw-r--r--setup.cfg1
4 files changed, 41 insertions, 36 deletions
diff --git a/.coveragerc b/.coveragerc
index fe258c6c6..613ea33df 100644
--- a/.coveragerc
+++ b/.coveragerc
@@ -1,3 +1,4 @@
[report]
exclude_lines =
if __name__ == .__main__.:
+ def main
diff --git a/functest/opnfv_tests/sdn/odl/odl.py b/functest/opnfv_tests/sdn/odl/odl.py
index fb5dcbc6e..67bf66e34 100755..100644
--- a/functest/opnfv_tests/sdn/odl/odl.py
+++ b/functest/opnfv_tests/sdn/odl/odl.py
@@ -117,7 +117,7 @@ class ODLTests(testcase.TestCase):
self.details['description'] = result.suite.name
self.details['tests'] = visitor.get_data()
- def main(self, suites=None, **kwargs):
+ def run_suites(self, suites=None, **kwargs):
"""Run the test suites
It has been designed to be called in any context.
@@ -246,7 +246,7 @@ class ODLTests(testcase.TestCase):
self.__logger.exception("Cannot run ODL testcases.")
return self.EX_RUN_ERROR
- return self.main(suites, **kwargs)
+ return self.run_suites(suites, **kwargs)
class ODLParser(object): # pylint: disable=too-few-public-methods
@@ -301,16 +301,19 @@ class ODLParser(object): # pylint: disable=too-few-public-methods
return vars(self.parser.parse_args(argv))
-if __name__ == '__main__':
+def main():
+ """Entry point"""
logging.basicConfig()
- ODL = ODLTests()
- PARSER = ODLParser()
- ARGS = PARSER.parse_args(sys.argv[1:])
+ odl = ODLTests()
+ parser = ODLParser()
+ args = parser.parse_args(sys.argv[1:])
try:
- RESULT = ODL.main(ODLTests.default_suites, **ARGS)
- if RESULT != testcase.TestCase.EX_OK:
- sys.exit(RESULT)
- if ARGS['pushtodb']:
- sys.exit(ODL.push_to_db())
+ result = odl.run_suites(ODLTests.default_suites, **args)
+ if result != testcase.TestCase.EX_OK:
+ return result
+ if args['pushtodb']:
+ return odl.push_to_db()
+ else:
+ return result
except Exception: # pylint: disable=broad-except
- sys.exit(testcase.TestCase.EX_RUN_ERROR)
+ return testcase.TestCase.EX_RUN_ERROR
diff --git a/functest/tests/unit/odl/test_odl.py b/functest/tests/unit/odl/test_odl.py
index 60adf211d..070a8d2ec 100644
--- a/functest/tests/unit/odl/test_odl.py
+++ b/functest/tests/unit/odl/test_odl.py
@@ -202,10 +202,10 @@ class ODLRobotTesting(ODLTesting):
class ODLMainTesting(ODLTesting):
- """The class testing ODLTests.main()."""
+ """The class testing ODLTests.run_suites()."""
# pylint: disable=missing-docstring
- def _get_main_kwargs(self, key=None):
+ def _get_run_suites_kwargs(self, key=None):
kwargs = {'odlusername': self._odl_username,
'odlpassword': self._odl_password,
'neutronip': self._neutron_ip,
@@ -220,9 +220,9 @@ class ODLMainTesting(ODLTesting):
del kwargs[key]
return kwargs
- def _test_main(self, status, *args):
- kwargs = self._get_main_kwargs()
- self.assertEqual(self.test.main(**kwargs), status)
+ def _test_run_suites(self, status, *args):
+ kwargs = self._get_run_suites_kwargs()
+ self.assertEqual(self.test.run_suites(**kwargs), status)
if len(args) > 0:
args[0].assert_called_once_with(
odl.ODLTests.res_dir)
@@ -249,8 +249,8 @@ class ODLMainTesting(ODLTesting):
os.path.join(odl.ODLTests.res_dir, 'stdout.txt'))
def _test_no_keyword(self, key):
- kwargs = self._get_main_kwargs(key)
- self.assertEqual(self.test.main(**kwargs),
+ kwargs = self._get_run_suites_kwargs(key)
+ self.assertEqual(self.test.run_suites(**kwargs),
testcase.TestCase.EX_RUN_ERROR)
def test_no_odlusername(self):
@@ -286,7 +286,7 @@ class ODLMainTesting(ODLTesting):
def test_set_vars_ko(self):
with mock.patch.object(self.test, 'set_robotframework_vars',
return_value=False) as mock_object:
- self._test_main(testcase.TestCase.EX_RUN_ERROR)
+ self._test_run_suites(testcase.TestCase.EX_RUN_ERROR)
mock_object.assert_called_once_with(
self._odl_username, self._odl_password)
@@ -295,15 +295,15 @@ class ODLMainTesting(ODLTesting):
with mock.patch.object(self.test, 'set_robotframework_vars',
return_value=True), \
self.assertRaises(Exception):
- self._test_main(testcase.TestCase.EX_RUN_ERROR,
- mock_method)
+ self._test_run_suites(testcase.TestCase.EX_RUN_ERROR,
+ mock_method)
@mock.patch('os.makedirs', side_effect=OSError)
def test_makedirs_oserror(self, mock_method):
with mock.patch.object(self.test, 'set_robotframework_vars',
return_value=True):
- self._test_main(testcase.TestCase.EX_RUN_ERROR,
- mock_method)
+ self._test_run_suites(testcase.TestCase.EX_RUN_ERROR,
+ mock_method)
@mock.patch('robot.run', side_effect=RobotError)
@mock.patch('os.makedirs')
@@ -311,7 +311,7 @@ class ODLMainTesting(ODLTesting):
with mock.patch.object(self.test, 'set_robotframework_vars',
return_value=True), \
self.assertRaises(RobotError):
- self._test_main(testcase.TestCase.EX_RUN_ERROR, *args)
+ self._test_run_suites(testcase.TestCase.EX_RUN_ERROR, *args)
@mock.patch('robot.run')
@mock.patch('os.makedirs')
@@ -320,7 +320,7 @@ class ODLMainTesting(ODLTesting):
return_value=True), \
mock.patch.object(self.test, 'parse_results',
side_effect=RobotError):
- self._test_main(testcase.TestCase.EX_RUN_ERROR, *args)
+ self._test_run_suites(testcase.TestCase.EX_RUN_ERROR, *args)
@mock.patch('robot.run')
@mock.patch('os.makedirs')
@@ -328,7 +328,7 @@ class ODLMainTesting(ODLTesting):
with mock.patch.object(self.test, 'set_robotframework_vars',
return_value=True), \
mock.patch.object(self.test, 'parse_results'):
- self._test_main(testcase.TestCase.EX_OK, *args)
+ self._test_run_suites(testcase.TestCase.EX_OK, *args)
@mock.patch('robot.run')
@mock.patch('os.makedirs', side_effect=OSError(errno.EEXIST, ''))
@@ -336,7 +336,7 @@ class ODLMainTesting(ODLTesting):
with mock.patch.object(self.test, 'set_robotframework_vars',
return_value=True), \
mock.patch.object(self.test, 'parse_results'):
- self._test_main(testcase.TestCase.EX_OK, *args)
+ self._test_run_suites(testcase.TestCase.EX_OK, *args)
@mock.patch('robot.run', return_value=1)
@mock.patch('os.makedirs')
@@ -344,7 +344,7 @@ class ODLMainTesting(ODLTesting):
with mock.patch.object(self.test, 'set_robotframework_vars',
return_value=True), \
mock.patch.object(self.test, 'parse_results'):
- self._test_main(testcase.TestCase.EX_OK, *args)
+ self._test_run_suites(testcase.TestCase.EX_OK, *args)
class ODLRunTesting(ODLTesting):
@@ -371,11 +371,11 @@ class ODLRunTesting(ODLTesting):
return_value="http://{}:9696".format(
ODLTesting._neutron_ip)):
if exception:
- self.test.main = mock.Mock(side_effect=exception)
+ self.test.run_suites = mock.Mock(side_effect=exception)
else:
- self.test.main = mock.Mock(return_value=status)
+ self.test.run_suites = mock.Mock(return_value=status)
self.assertEqual(self.test.run(), status)
- self.test.main.assert_called_once_with(
+ self.test.run_suites.assert_called_once_with(
odl.ODLTests.default_suites,
neutronip=self._neutron_ip,
odlip=odlip, odlpassword=self._odl_password,
@@ -394,9 +394,9 @@ class ODLRunTesting(ODLTesting):
with mock.patch('functest.utils.openstack_utils.get_endpoint',
return_value="http://{}:9696".format(
ODLTesting._neutron_ip)):
- self.test.main = mock.Mock(return_value=status)
+ self.test.run_suites = mock.Mock(return_value=status)
self.assertEqual(self.test.run(suites=suites), status)
- self.test.main.assert_called_once_with(
+ self.test.run_suites.assert_called_once_with(
suites,
neutronip=self._neutron_ip,
odlip=odlip, odlpassword=self._odl_password,
@@ -424,13 +424,13 @@ class ODLRunTesting(ODLTesting):
def test_no_os_tenant_name(self):
self._test_no_env_var("OS_TENANT_NAME")
- def test_main_false(self):
+ def test_run_suites_false(self):
os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip
self._test_run(testcase.TestCase.EX_RUN_ERROR,
odlip=self._sdn_controller_ip,
odlwebport=self._odl_webport)
- def test_main_exc(self):
+ def test_run_suites_exc(self):
with self.assertRaises(Exception):
os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip
self._test_run(status=testcase.TestCase.EX_RUN_ERROR,
diff --git a/setup.cfg b/setup.cfg
index ba137687d..12da1b63a 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -13,3 +13,4 @@ scripts =
[entry_points]
console_scripts =
functest = functest.cli.cli_base:cli
+ functest_odl = functest.opnfv_tests.sdn.odl.odl:main