refactor testing directory layout

This changes the layout of the tests. Before both unit
and functional tests were in the same place. That made
it so development really needed to happen on linux because
of tests like uptime needing /proc/uptime This change
puts those kind of tests into the int testing dir
and adds a unit and integration test arg to tox.

Change-Id: I922079e4a556a171aadd801a8cc932e1e08f9b5d
Signed-off-by: Michael Rice <michael.rice@rackspace.com>
This commit is contained in:
Michael Rice 2017-05-31 00:56:41 -05:00
parent 0268ce450c
commit 6eae6ea8db
16 changed files with 89 additions and 49 deletions

View File

@ -1,4 +1,3 @@
#!/usr/bin/env python
# Copyright 2017, Major Hayden <major@mhtx.net>
#
# Licensed under the Apache License, Version 2.0 (the "License");
@ -15,27 +14,12 @@
"""This an __init__.py."""
import json
import os
from click.testing import CliRunner
from monitorstack import utils
from monitorstack.cli import cli
def read_config():
"""Load the test config file.
:returns: dict
"""
os_config_file = os.path.expanduser(
os.path.abspath(
os.path.dirname(__file__) + '/files/test-openstack.ini'
)
)
return utils.read_config(os_config_file)
def runner(module, extra_args=None):
"""Run click CLI tests.
@ -57,8 +41,3 @@ def runner(module, extra_args=None):
return json.loads(result.output)
except ValueError:
return result
def fake_version_info(major, minor, serial):
"""Return tuple for fake python version info."""
return major, minor, serial

View File

@ -1 +0,0 @@
../../etc/openstack.ini

13
tests/int/__init__.py Normal file
View File

@ -0,0 +1,13 @@
# Copyright 2017, Michael Rice <michael@michaelrice.org>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

36
tests/unit/__init__.py Normal file
View File

@ -0,0 +1,36 @@
# Copyright 2017, Major Hayden <major@mhtx.net>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""This an __init__.py."""
import os
from monitorstack import utils
def read_config():
"""Load the test config file.
:returns: dict
"""
os_config_file = os.path.expanduser(
os.path.abspath(
os.path.dirname(__file__) + '/files/test-openstack.ini'
)
)
return utils.read_config(os_config_file)
def fake_version_info(major, minor, serial):
"""Return tuple for fake python version info."""
return major, minor, serial

View File

@ -0,0 +1 @@
../../../etc/openstack.ini

View File

@ -135,7 +135,7 @@ class TestOSUtilsConnection(unittest.TestCase):
"""Test the OpenStack connection interface."""
# load the base class for these tests.
self.osu = os_utils.OpenStack(
os_auth_args=tests.read_config()['keystone']
os_auth_args=tests.unit.read_config()['keystone']
)
self.assertTrue(
isinstance(
@ -152,7 +152,7 @@ class TestOsUtils(unittest.TestCase):
"""Setup the test."""
# load the base class for these tests.
self.osu = os_utils.OpenStack(
os_auth_args=tests.read_config()['keystone']
os_auth_args=tests.unit.read_config()['keystone']
)
def tearDown(self):

View File

@ -21,7 +21,7 @@ from click.testing import CliRunner
from monitorstack.cli import cli
import tests # Import the test base module
import tests.unit # Import the test base module
def _runner(module):

View File

@ -16,7 +16,7 @@ from monitorstack.plugins import memcache as monitorstack_memcache
import pymemcache
import tests
import tests.unit
class TestMemcache(object):

View File

@ -15,7 +15,9 @@
from monitorstack.utils.os_utils import OpenStack as Ost
import tests # Import the test base module
import tests.unit
CONF_FILE = 'tests/unit/files/test-openstack.ini'
def get_volume_pool_stats(*args, **kwargs):
@ -54,7 +56,7 @@ class TestOsBlock(object):
'os_block_pools_totals',
extra_args=[
'--config-file',
'tests/files/test-openstack.ini'
CONF_FILE
]
)
variables = result['variables']
@ -74,7 +76,7 @@ class TestOsBlock(object):
'os_block_pools_totals',
extra_args=[
'--config-file',
'tests/files/test-openstack.ini'
CONF_FILE
]
)
assert result['measurement_name'] == 'os_block_pools_totals'
@ -91,7 +93,7 @@ class TestOsBlock(object):
'os_block_pools_usage',
extra_args=[
'--config-file',
'tests/files/test-openstack.ini'
CONF_FILE
]
)
variables = result['variables']
@ -113,7 +115,7 @@ class TestOsBlock(object):
'os_block_pools_usage',
extra_args=[
'--config-file',
'tests/files/test-openstack.ini'
CONF_FILE
]
)
assert result['measurement_name'] == 'os_block_pools_usage'

View File

@ -15,7 +15,10 @@
from monitorstack.utils.os_utils import OpenStack as Ost
import tests # Import the test base module
import tests.unit # Import the test base module
CONF_FILE = 'tests/unit/files/test-openstack.ini'
class MockProject(object):
@ -94,7 +97,7 @@ class TestOsVm(object):
'os_vm_quota_cores',
extra_args=[
'--config-file',
'tests/files/test-openstack.ini'
CONF_FILE
]
)
assert result['measurement_name'] == 'os_vm_quota_cores'
@ -106,7 +109,7 @@ class TestOsVm(object):
'os_vm_quota_cores',
extra_args=[
'--config-file',
'tests/files/test-openstack.ini'
CONF_FILE
]
)
assert result['measurement_name'] == 'os_vm_quota_cores'
@ -121,7 +124,7 @@ class TestOsVm(object):
'os_vm_quota_instance',
extra_args=[
'--config-file',
'tests/files/test-openstack.ini'
CONF_FILE
]
)
assert result['measurement_name'] == 'os_vm_quota_instance'
@ -133,7 +136,7 @@ class TestOsVm(object):
'os_vm_quota_instance',
extra_args=[
'--config-file',
'tests/files/test-openstack.ini'
CONF_FILE
]
)
assert result['measurement_name'] == 'os_vm_quota_instance'
@ -148,7 +151,7 @@ class TestOsVm(object):
'os_vm_quota_ram',
extra_args=[
'--config-file',
'tests/files/test-openstack.ini'
CONF_FILE
]
)
assert result['measurement_name'] == 'os_vm_quota_ram'
@ -160,7 +163,7 @@ class TestOsVm(object):
'os_vm_quota_ram',
extra_args=[
'--config-file',
'tests/files/test-openstack.ini'
CONF_FILE
]
)
assert result['measurement_name'] == 'os_vm_quota_ram'
@ -177,7 +180,7 @@ class TestOsVm(object):
'os_vm_used_cores',
extra_args=[
'--config-file',
'tests/files/test-openstack.ini'
CONF_FILE
]
)
assert result['measurement_name'] == 'os_vm_used_cores'
@ -190,7 +193,7 @@ class TestOsVm(object):
'os_vm_used_cores',
extra_args=[
'--config-file',
'tests/files/test-openstack.ini'
CONF_FILE
]
)
assert result['measurement_name'] == 'os_vm_used_cores'
@ -207,7 +210,7 @@ class TestOsVm(object):
'os_vm_used_disk',
extra_args=[
'--config-file',
'tests/files/test-openstack.ini'
CONF_FILE
]
)
assert result['measurement_name'] == 'os_vm_used_disk'
@ -220,7 +223,7 @@ class TestOsVm(object):
'os_vm_used_disk',
extra_args=[
'--config-file',
'tests/files/test-openstack.ini'
CONF_FILE
]
)
assert result['measurement_name'] == 'os_vm_used_disk'
@ -237,7 +240,7 @@ class TestOsVm(object):
'os_vm_used_instance',
extra_args=[
'--config-file',
'tests/files/test-openstack.ini'
CONF_FILE
]
)
assert result['measurement_name'] == 'os_vm_used_instance'
@ -250,7 +253,7 @@ class TestOsVm(object):
'os_vm_used_instance',
extra_args=[
'--config-file',
'tests/files/test-openstack.ini'
CONF_FILE
]
)
assert result['measurement_name'] == 'os_vm_used_instance'
@ -267,7 +270,7 @@ class TestOsVm(object):
'os_vm_used_ram',
extra_args=[
'--config-file',
'tests/files/test-openstack.ini'
CONF_FILE
]
)
assert result['measurement_name'] == 'os_vm_used_ram'
@ -281,7 +284,7 @@ class TestOsVm(object):
'os_vm_used_ram',
extra_args=[
'--config-file',
'tests/files/test-openstack.ini'
CONF_FILE
]
)
assert result['measurement_name'] == 'os_vm_used_ram'

View File

@ -17,7 +17,7 @@ import mock
from monitorstack.plugins import process
import tests # Import the test base module
import tests.unit # Import the test base module
class TestUptime(object):

11
tox.ini
View File

@ -19,6 +19,9 @@ whitelist_externals =
bash
commands =
/usr/bin/find . -type f -name "*.pyc" -delete
[testenv:functional]
commands =
coverage run -m pytest --capture=no --strict {posargs}
coverage report -m --omit="*/test*"
@ -47,9 +50,13 @@ deps =
commands =
{[testenv:pep8]commands}
[testenv:functional]
[testenv:integration]
commands =
{[testenv]commands}
coverage run -m pytest --capture=no --strict "tests/int"
[testenv:unit]
commands =
coverage run -m pytest --capture=no --strict "tests/unit"
[testenv:pep8]
deps =