Browse Source

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>
Michael Rice 1 year ago
parent
commit
6eae6ea8db

+ 0
- 21
tests/__init__.py View File

@@ -1,4 +1,3 @@
1
-#!/usr/bin/env python
2 1
 # Copyright 2017, Major Hayden <major@mhtx.net>
3 2
 #
4 3
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,27 +14,12 @@
15 14
 """This an __init__.py."""
16 15
 
17 16
 import json
18
-import os
19 17
 
20 18
 from click.testing import CliRunner
21 19
 
22
-from monitorstack import utils
23 20
 from monitorstack.cli import cli
24 21
 
25 22
 
26
-def read_config():
27
-    """Load the test config file.
28
-
29
-    :returns: dict
30
-    """
31
-    os_config_file = os.path.expanduser(
32
-        os.path.abspath(
33
-            os.path.dirname(__file__) + '/files/test-openstack.ini'
34
-        )
35
-    )
36
-    return utils.read_config(os_config_file)
37
-
38
-
39 23
 def runner(module, extra_args=None):
40 24
     """Run click CLI tests.
41 25
 
@@ -57,8 +41,3 @@ def runner(module, extra_args=None):
57 41
         return json.loads(result.output)
58 42
     except ValueError:
59 43
         return result
60
-
61
-
62
-def fake_version_info(major, minor, serial):
63
-    """Return tuple for fake python version info."""
64
-    return major, minor, serial

+ 0
- 1
tests/files/test-openstack.ini View File

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

+ 13
- 0
tests/int/__init__.py View File

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

tests/test_plugin_uptime.py → tests/int/test_plugin_uptime.py View File


+ 36
- 0
tests/unit/__init__.py View File

@@ -0,0 +1,36 @@
1
+# Copyright 2017, Major Hayden <major@mhtx.net>
2
+#
3
+# Licensed under the Apache License, Version 2.0 (the "License");
4
+# you may not use this file except in compliance with the License.
5
+# You may obtain a copy of the License at
6
+#
7
+#     http://www.apache.org/licenses/LICENSE-2.0
8
+#
9
+# Unless required by applicable law or agreed to in writing, software
10
+# distributed under the License is distributed on an "AS IS" BASIS,
11
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+# See the License for the specific language governing permissions and
13
+# limitations under the License.
14
+"""This an __init__.py."""
15
+
16
+import os
17
+
18
+from monitorstack import utils
19
+
20
+
21
+def read_config():
22
+    """Load the test config file.
23
+
24
+    :returns: dict
25
+    """
26
+    os_config_file = os.path.expanduser(
27
+        os.path.abspath(
28
+            os.path.dirname(__file__) + '/files/test-openstack.ini'
29
+        )
30
+    )
31
+    return utils.read_config(os_config_file)
32
+
33
+
34
+def fake_version_info(major, minor, serial):
35
+    """Return tuple for fake python version info."""
36
+    return major, minor, serial

+ 1
- 0
tests/unit/files/test-openstack.ini View File

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

tests/test_cli.py → tests/unit/test_cli.py View File


tests/test_formatters.py → tests/unit/test_formatters.py View File


tests/test_os_utils.py → tests/unit/test_os_utils.py View File

@@ -135,7 +135,7 @@ class TestOSUtilsConnection(unittest.TestCase):
135 135
         """Test the OpenStack connection interface."""
136 136
         # load the base class for these tests.
137 137
         self.osu = os_utils.OpenStack(
138
-            os_auth_args=tests.read_config()['keystone']
138
+            os_auth_args=tests.unit.read_config()['keystone']
139 139
         )
140 140
         self.assertTrue(
141 141
             isinstance(
@@ -152,7 +152,7 @@ class TestOsUtils(unittest.TestCase):
152 152
         """Setup the test."""
153 153
         # load the base class for these tests.
154 154
         self.osu = os_utils.OpenStack(
155
-            os_auth_args=tests.read_config()['keystone']
155
+            os_auth_args=tests.unit.read_config()['keystone']
156 156
         )
157 157
 
158 158
     def tearDown(self):

tests/test_plugin_kvm.py → tests/unit/test_plugin_kvm.py View File

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

tests/test_plugin_memcache.py → tests/unit/test_plugin_memcache.py View File

@@ -16,7 +16,7 @@ from monitorstack.plugins import memcache as monitorstack_memcache
16 16
 
17 17
 import pymemcache
18 18
 
19
-import tests
19
+import tests.unit
20 20
 
21 21
 
22 22
 class TestMemcache(object):

tests/test_plugin_os_block.py → tests/unit/test_plugin_os_block.py View File

@@ -15,7 +15,9 @@
15 15
 
16 16
 from monitorstack.utils.os_utils import OpenStack as Ost
17 17
 
18
-import tests  # Import the test base module
18
+import tests.unit
19
+
20
+CONF_FILE = 'tests/unit/files/test-openstack.ini'
19 21
 
20 22
 
21 23
 def get_volume_pool_stats(*args, **kwargs):
@@ -54,7 +56,7 @@ class TestOsBlock(object):
54 56
             'os_block_pools_totals',
55 57
             extra_args=[
56 58
                 '--config-file',
57
-                'tests/files/test-openstack.ini'
59
+                CONF_FILE
58 60
             ]
59 61
         )
60 62
         variables = result['variables']
@@ -74,7 +76,7 @@ class TestOsBlock(object):
74 76
             'os_block_pools_totals',
75 77
             extra_args=[
76 78
                 '--config-file',
77
-                'tests/files/test-openstack.ini'
79
+                CONF_FILE
78 80
             ]
79 81
         )
80 82
         assert result['measurement_name'] == 'os_block_pools_totals'
@@ -91,7 +93,7 @@ class TestOsBlock(object):
91 93
             'os_block_pools_usage',
92 94
             extra_args=[
93 95
                 '--config-file',
94
-                'tests/files/test-openstack.ini'
96
+                CONF_FILE
95 97
             ]
96 98
         )
97 99
         variables = result['variables']
@@ -113,7 +115,7 @@ class TestOsBlock(object):
113 115
             'os_block_pools_usage',
114 116
             extra_args=[
115 117
                 '--config-file',
116
-                'tests/files/test-openstack.ini'
118
+                CONF_FILE
117 119
             ]
118 120
         )
119 121
         assert result['measurement_name'] == 'os_block_pools_usage'

tests/test_plugin_os_vm.py → tests/unit/test_plugin_os_vm.py View File

@@ -15,7 +15,10 @@
15 15
 
16 16
 from monitorstack.utils.os_utils import OpenStack as Ost
17 17
 
18
-import tests  # Import the test base module
18
+import tests.unit  # Import the test base module
19
+
20
+
21
+CONF_FILE = 'tests/unit/files/test-openstack.ini'
19 22
 
20 23
 
21 24
 class MockProject(object):
@@ -94,7 +97,7 @@ class TestOsVm(object):
94 97
             'os_vm_quota_cores',
95 98
             extra_args=[
96 99
                 '--config-file',
97
-                'tests/files/test-openstack.ini'
100
+                CONF_FILE
98 101
             ]
99 102
         )
100 103
         assert result['measurement_name'] == 'os_vm_quota_cores'
@@ -106,7 +109,7 @@ class TestOsVm(object):
106 109
             'os_vm_quota_cores',
107 110
             extra_args=[
108 111
                 '--config-file',
109
-                'tests/files/test-openstack.ini'
112
+                CONF_FILE
110 113
             ]
111 114
         )
112 115
         assert result['measurement_name'] == 'os_vm_quota_cores'
@@ -121,7 +124,7 @@ class TestOsVm(object):
121 124
             'os_vm_quota_instance',
122 125
             extra_args=[
123 126
                 '--config-file',
124
-                'tests/files/test-openstack.ini'
127
+                CONF_FILE
125 128
             ]
126 129
         )
127 130
         assert result['measurement_name'] == 'os_vm_quota_instance'
@@ -133,7 +136,7 @@ class TestOsVm(object):
133 136
             'os_vm_quota_instance',
134 137
             extra_args=[
135 138
                 '--config-file',
136
-                'tests/files/test-openstack.ini'
139
+                CONF_FILE
137 140
             ]
138 141
         )
139 142
         assert result['measurement_name'] == 'os_vm_quota_instance'
@@ -148,7 +151,7 @@ class TestOsVm(object):
148 151
             'os_vm_quota_ram',
149 152
             extra_args=[
150 153
                 '--config-file',
151
-                'tests/files/test-openstack.ini'
154
+                CONF_FILE
152 155
             ]
153 156
         )
154 157
         assert result['measurement_name'] == 'os_vm_quota_ram'
@@ -160,7 +163,7 @@ class TestOsVm(object):
160 163
             'os_vm_quota_ram',
161 164
             extra_args=[
162 165
                 '--config-file',
163
-                'tests/files/test-openstack.ini'
166
+                CONF_FILE
164 167
             ]
165 168
         )
166 169
         assert result['measurement_name'] == 'os_vm_quota_ram'
@@ -177,7 +180,7 @@ class TestOsVm(object):
177 180
             'os_vm_used_cores',
178 181
             extra_args=[
179 182
                 '--config-file',
180
-                'tests/files/test-openstack.ini'
183
+                CONF_FILE
181 184
             ]
182 185
         )
183 186
         assert result['measurement_name'] == 'os_vm_used_cores'
@@ -190,7 +193,7 @@ class TestOsVm(object):
190 193
             'os_vm_used_cores',
191 194
             extra_args=[
192 195
                 '--config-file',
193
-                'tests/files/test-openstack.ini'
196
+                CONF_FILE
194 197
             ]
195 198
         )
196 199
         assert result['measurement_name'] == 'os_vm_used_cores'
@@ -207,7 +210,7 @@ class TestOsVm(object):
207 210
             'os_vm_used_disk',
208 211
             extra_args=[
209 212
                 '--config-file',
210
-                'tests/files/test-openstack.ini'
213
+                CONF_FILE
211 214
             ]
212 215
         )
213 216
         assert result['measurement_name'] == 'os_vm_used_disk'
@@ -220,7 +223,7 @@ class TestOsVm(object):
220 223
             'os_vm_used_disk',
221 224
             extra_args=[
222 225
                 '--config-file',
223
-                'tests/files/test-openstack.ini'
226
+                CONF_FILE
224 227
             ]
225 228
         )
226 229
         assert result['measurement_name'] == 'os_vm_used_disk'
@@ -237,7 +240,7 @@ class TestOsVm(object):
237 240
             'os_vm_used_instance',
238 241
             extra_args=[
239 242
                 '--config-file',
240
-                'tests/files/test-openstack.ini'
243
+                CONF_FILE
241 244
             ]
242 245
         )
243 246
         assert result['measurement_name'] == 'os_vm_used_instance'
@@ -250,7 +253,7 @@ class TestOsVm(object):
250 253
             'os_vm_used_instance',
251 254
             extra_args=[
252 255
                 '--config-file',
253
-                'tests/files/test-openstack.ini'
256
+                CONF_FILE
254 257
             ]
255 258
         )
256 259
         assert result['measurement_name'] == 'os_vm_used_instance'
@@ -267,7 +270,7 @@ class TestOsVm(object):
267 270
             'os_vm_used_ram',
268 271
             extra_args=[
269 272
                 '--config-file',
270
-                'tests/files/test-openstack.ini'
273
+                CONF_FILE
271 274
             ]
272 275
         )
273 276
         assert result['measurement_name'] == 'os_vm_used_ram'
@@ -281,7 +284,7 @@ class TestOsVm(object):
281 284
             'os_vm_used_ram',
282 285
             extra_args=[
283 286
                 '--config-file',
284
-                'tests/files/test-openstack.ini'
287
+                CONF_FILE
285 288
             ]
286 289
         )
287 290
         assert result['measurement_name'] == 'os_vm_used_ram'

tests/test_plugin_process.py → tests/unit/test_plugin_process.py View File

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

tests/test_utils.py → tests/unit/test_utils.py View File


+ 9
- 2
tox.ini View File

@@ -19,6 +19,9 @@ whitelist_externals =
19 19
     bash
20 20
 commands =
21 21
     /usr/bin/find . -type f -name "*.pyc" -delete
22
+
23
+[testenv:functional]
24
+commands =
22 25
     coverage run -m pytest --capture=no --strict {posargs}
23 26
     coverage report -m --omit="*/test*"
24 27
 
@@ -47,9 +50,13 @@ deps =
47 50
 commands =
48 51
     {[testenv:pep8]commands}
49 52
 
50
-[testenv:functional]
53
+[testenv:integration]
54
+commands =
55
+    coverage run -m pytest --capture=no --strict "tests/int"
56
+
57
+[testenv:unit]
51 58
 commands =
52
-    {[testenv]commands}
59
+    coverage run -m pytest --capture=no --strict "tests/unit"
53 60
 
54 61
 [testenv:pep8]
55 62
 deps =

Loading…
Cancel
Save