From 4f5747c8bf3695694400a109e56a83469604a069 Mon Sep 17 00:00:00 2001 From: Emma Foley Date: Wed, 29 Nov 2017 23:01:33 +0000 Subject: [PATCH] Move tests: unit/apiserver/ * Fix pylint errors * Add TODOs Some errors are ignored locally, as they were a symptom of other problems. These issues have been flagged with a TODO, and should be fixed later. JIRA: YARDSTICK-837 Signed-off-by: Emma Foley Change-Id: I30d3f61e5ea479758f9a2f39cf415da18e49b9d6 --- {tests => yardstick/tests}/unit/apiserver/__init__.py | 17 ++++++++++++++--- .../tests}/unit/apiserver/resources/__init__.py | 0 .../tests}/unit/apiserver/resources/test_env_action.py | 3 +-- .../tests}/unit/apiserver/utils/test_influx.py | 8 +++----- 4 files changed, 18 insertions(+), 10 deletions(-) rename {tests => yardstick/tests}/unit/apiserver/__init__.py (65%) rename {tests => yardstick/tests}/unit/apiserver/resources/__init__.py (100%) rename {tests => yardstick/tests}/unit/apiserver/resources/test_env_action.py (92%) rename {tests => yardstick/tests}/unit/apiserver/utils/test_influx.py (91%) diff --git a/tests/unit/apiserver/__init__.py b/yardstick/tests/unit/apiserver/__init__.py similarity index 65% rename from tests/unit/apiserver/__init__.py rename to yardstick/tests/unit/apiserver/__init__.py index 5e1ed2ea1..44d163429 100644 --- a/tests/unit/apiserver/__init__.py +++ b/yardstick/tests/unit/apiserver/__init__.py @@ -1,3 +1,12 @@ +############################################################################## +# Copyright (c) 2017 +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +"""Tests for yardstick/api/server.py""" from __future__ import absolute_import import mock @@ -12,14 +21,16 @@ from yardstick.common import constants as consts class APITestCase(unittest.TestCase): - + """Tests for the YardStick API server""" def setUp(self): self.db_fd, self.db_path = tempfile.mkstemp() consts.SQLITE = 'sqlite:///{}'.format(self.db_path) - # server calls gethostbyname which takes 4 seconds, and we should mock it anyway + # server calls gethostbyname which takes 4 seconds, and we should mock + # it anyway self.socket_mock = mock.patch.dict("sys.modules", {"socket": mock.MagicMock( - **{"gethostbyname.return_value": "127.0.0.1", "gethostname.return_value": "localhost"})}) + **{"gethostbyname.return_value": "127.0.0.1", + "gethostname.return_value": "localhost"})}) self.socket_mock.start() try: from api import server diff --git a/tests/unit/apiserver/resources/__init__.py b/yardstick/tests/unit/apiserver/resources/__init__.py similarity index 100% rename from tests/unit/apiserver/resources/__init__.py rename to yardstick/tests/unit/apiserver/resources/__init__.py diff --git a/tests/unit/apiserver/resources/test_env_action.py b/yardstick/tests/unit/apiserver/resources/test_env_action.py similarity index 92% rename from tests/unit/apiserver/resources/test_env_action.py rename to yardstick/tests/unit/apiserver/resources/test_env_action.py index 5417ad953..b7bfe294d 100644 --- a/tests/unit/apiserver/resources/test_env_action.py +++ b/yardstick/tests/unit/apiserver/resources/test_env_action.py @@ -6,12 +6,11 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -from __future__ import absolute_import import time import unittest -from tests.unit.apiserver import APITestCase +from yardstick.tests.unit.apiserver import APITestCase class EnvTestCase(APITestCase): diff --git a/tests/unit/apiserver/utils/test_influx.py b/yardstick/tests/unit/apiserver/utils/test_influx.py similarity index 91% rename from tests/unit/apiserver/utils/test_influx.py rename to yardstick/tests/unit/apiserver/utils/test_influx.py index aff0cab5c..883608bb2 100644 --- a/tests/unit/apiserver/utils/test_influx.py +++ b/yardstick/tests/unit/apiserver/utils/test_influx.py @@ -6,13 +6,11 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -from __future__ import absolute_import import unittest import mock from api.utils import influx - -import six.moves.configparser as ConfigParser +from six.moves import configparser as ConfigParser class GetDataDbClientTestCase(unittest.TestCase): @@ -25,7 +23,7 @@ class GetDataDbClientTestCase(unittest.TestCase): mock_parser.NoOptionError = ConfigParser.NoOptionError try: influx.get_data_db_client() - except Exception as e: + except Exception as e: # pylint: disable=broad-except self.assertIsInstance(e, RuntimeError) @@ -50,7 +48,7 @@ class QueryTestCase(unittest.TestCase): try: sql = 'select * form tasklist' influx.query(sql) - except Exception as e: + except Exception as e: # pylint: disable=broad-except self.assertIsInstance(e, RuntimeError) -- 2.16.6