Skip to content

Commit 585acb8

Browse files
committed
Splits coverage testing from other tests
Also uses unittest2 instead of testtools. unittest2 only works for python 2 and causes the dependencies to be different between py2 and py3.
1 parent fd5b9db commit 585acb8

8 files changed

Lines changed: 44 additions & 52 deletions

File tree

SoftLayer/testing/__init__.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
# Disable pylint import error and too many methods error
88
# pylint: disable=F0401,R0904
99
import logging
10-
try:
11-
import unittest2 as unittest
12-
except ImportError:
13-
import unittest
1410
import os.path
1511

1612
import SoftLayer
@@ -19,6 +15,7 @@
1915

2016
from click import testing
2117
import mock
18+
import testtools
2219

2320
FIXTURE_PATH = os.path.abspath(os.path.join(__file__, '..', 'fixtures'))
2421

@@ -74,7 +71,7 @@ def _mock_key(service, method):
7471
return '%s::%s' % (service, method)
7572

7673

77-
class TestCase(unittest.TestCase):
74+
class TestCase(testtools.TestCase):
7875
"""Testcase class with PEP-8 compatable method names."""
7976

8077
def set_up(self):
@@ -86,6 +83,7 @@ def tear_down(self):
8683
pass
8784

8885
def setUp(self): # NOQA
86+
super(TestCase, self).setUp()
8987
self.env = environment.Environment()
9088

9189
# Create a crazy mockable, fixture client
@@ -102,6 +100,7 @@ def setUp(self): # NOQA
102100
return self.set_up()
103101

104102
def tearDown(self): # NOQA
103+
super(TestCase, self).tearDown()
105104
return self.tear_down()
106105

107106
def calls(self, service=None, method=None):
@@ -168,6 +167,3 @@ def call_has_props(call, props):
168167
return False
169168

170169
return True
171-
172-
173-
__all__ = ['unittest']

SoftLayer/tests/CLI/core_tests.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ class CoreMainTests(testing.TestCase):
6060
def test_unexpected_error(self, stdoutmock, climock):
6161
climock.side_effect = AttributeError('Attribute foo does not exist')
6262

63-
with self.assertRaises(SystemExit):
64-
core.main()
63+
self.assertRaises(SystemExit, core.main)
6564

6665
self.assertIn("Feel free to report this error as it is likely a bug",
6766
stdoutmock.getvalue())
@@ -76,8 +75,7 @@ def test_sl_error(self, stdoutmock, climock):
7675
ex = SoftLayer.SoftLayerAPIError('SoftLayer_Exception', 'Not found')
7776
climock.side_effect = ex
7877

79-
with self.assertRaises(SystemExit):
80-
core.main()
78+
self.assertRaises(SystemExit, core.main)
8179

8280
self.assertIn("SoftLayerAPIError(SoftLayer_Exception): Not found",
8381
stdoutmock.getvalue())
@@ -89,8 +87,7 @@ def test_auth_error(self, stdoutmock, climock):
8987
'Invalid API token.')
9088
climock.side_effect = ex
9189

92-
with self.assertRaises(SystemExit):
93-
core.main()
90+
self.assertRaises(SystemExit, core.main)
9491

9592
self.assertIn("Authentication Failed:", stdoutmock.getvalue())
9693
self.assertIn("use 'sl config setup'", stdoutmock.getvalue())

SoftLayer/tests/CLI/modules/dns_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,6 @@ def test_import_zone(self):
218218

219219
self.assertEqual(len(calls), len(expected_calls))
220220
for call, expected_call in zip(calls, expected_calls):
221-
self.assertDictEqual(call.args[0], expected_call)
221+
self.assertEqual(call.args[0], expected_call)
222222

223223
self.assertIn("Finished", result.output)

SoftLayer/tests/functional_tests.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,23 @@
1111
from SoftLayer import transports
1212

1313

14-
def get_creds():
15-
for key in 'SL_USERNAME SL_API_KEY'.split():
16-
if key not in os.environ:
17-
raise testing.unittest.SkipTest(
18-
'SL_USERNAME and SL_API_KEY environmental variables not set')
14+
class FunctionalTest(testing.TestCase):
15+
def _get_creds(self):
16+
for key in 'SL_USERNAME SL_API_KEY'.split():
17+
if key not in os.environ:
18+
raise self.skipTest('SL_USERNAME and SL_API_KEY environmental '
19+
'variables not set')
1920

20-
return {
21-
'endpoint': (os.environ.get('SL_API_ENDPOINT') or
22-
SoftLayer.API_PUBLIC_ENDPOINT),
23-
'username': os.environ['SL_USERNAME'],
24-
'api_key': os.environ['SL_API_KEY']
25-
}
21+
return {
22+
'endpoint': (os.environ.get('SL_API_ENDPOINT') or
23+
SoftLayer.API_PUBLIC_ENDPOINT),
24+
'username': os.environ['SL_USERNAME'],
25+
'api_key': os.environ['SL_API_KEY']
26+
}
2627

2728

28-
class UnauthedUser(testing.TestCase):
29+
class UnauthedUser(FunctionalTest):
30+
2931
def test_failed_auth(self):
3032
client = SoftLayer.Client(
3133
username='doesnotexist', api_key='issurelywrong', timeout=20)
@@ -52,9 +54,9 @@ def test_no_hostname(self):
5254
self.fail('No Exception Raised')
5355

5456

55-
class AuthedUser(testing.TestCase):
57+
class AuthedUser(FunctionalTest):
5658
def test_service_does_not_exist(self):
57-
creds = get_creds()
59+
creds = self._get_creds()
5860
client = SoftLayer.Client(
5961
username=creds['username'],
6062
api_key=creds['api_key'],
@@ -71,7 +73,7 @@ def test_service_does_not_exist(self):
7173
self.fail('No Exception Raised')
7274

7375
def test_get_users(self):
74-
creds = get_creds()
76+
creds = self._get_creds()
7577
client = SoftLayer.Client(
7678
username=creds['username'],
7779
api_key=creds['api_key'],
@@ -86,7 +88,7 @@ def test_get_users(self):
8688
self.assertTrue(found)
8789

8890
def test_result_types(self):
89-
creds = get_creds()
91+
creds = self._get_creds()
9092
client = SoftLayer.Client(
9193
username=creds['username'],
9294
api_key=creds['api_key'],

SoftLayer/tests/managers/ordering_tests.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ def test_get_package_id_by_type_fails_for_nonexistent_package_type(self):
6969
mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects')
7070
mock.return_value = []
7171

72-
with self.assertRaises(ValueError):
73-
self.ordering.get_package_id_by_type("STRAWBERRY_FLAVORED_SERVERS")
72+
self.assertRaises(ValueError,
73+
self.ordering.get_package_id_by_type,
74+
"STRAWBERRY_FLAVORED_SERVERS")
7475

7576
def test_get_order_container(self):
7677
container = self.ordering.get_order_container(1234)
@@ -119,5 +120,6 @@ def test_generate_order_template(self):
119120
'quantity': 1})
120121

121122
def test_generate_order_template_extra_quantity(self):
122-
with self.assertRaises(ValueError):
123-
self.ordering.generate_order_template(1234, [], quantity=1)
123+
self.assertRaises(ValueError,
124+
self.ordering.generate_order_template,
125+
1234, [], quantity=1)

setup.cfg

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
[nosetests]
22
verbosity=1
33
detailed-errors=1
4-
with-coverage=1
5-
cover-min-percentage=79
6-
cover-erase=true
7-
cover-package=SoftLayer
8-
cover-html=1
94

105
[wheel]
116
universal=1

tools/test-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ nose
33
mock
44
coverage
55
sphinx
6+
testtools

tox.ini

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
[tox]
2-
envlist = py26,py27,py33,py34,pypy,analysis
2+
envlist = py26,py27,py33,py34,pypy,analysis,coverage
33
[testenv]
4-
deps =
5-
unittest2
6-
-r{toxinidir}/tools/test-requirements.txt
7-
commands = {envpython} setup.py nosetests []
8-
9-
10-
[testenv:py33]
114
deps = -r{toxinidir}/tools/test-requirements.txt
12-
commands = {envpython} setup.py nosetests []
5+
commands = nosetests
136

14-
[testenv:py34]
15-
deps = -r{toxinidir}/tools/test-requirements.txt
16-
commands = {envpython} setup.py nosetests []
7+
[testenv:coverage]
8+
basepython = python2.7
9+
commands = nosetests \
10+
--with-coverage \
11+
--cover-min-percentage=79 \
12+
--cover-erase \
13+
--cover-package=SoftLayer \
14+
--cover-html
1715

1816
[testenv:analysis]
1917
basepython = python2.7
2018
deps =
19+
-r{toxinidir}/tools/test-requirements.txt
2120
hacking
2221
pylint
2322
commands =

0 commit comments

Comments
 (0)