Skip to content

Commit dc173c1

Browse files
Merge pull request #1244 from allmightyspiff/master
Fixes unittests to work in pytest==5.4.1
2 parents 922d486 + cd8ce76 commit dc173c1

File tree

4 files changed

+21
-58
lines changed

4 files changed

+21
-58
lines changed

SoftLayer/CLI/call_api.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,9 @@ def _validate_parameters(ctx, param, value): # pylint: disable=unused-argument
115115
@click.option('--output-python / --no-output-python',
116116
help="Show python example code instead of executing the call")
117117
@click.option('--json-filter', callback=_validate_filter,
118-
help="A JSON string to be passed in as the object filter to the API call."
119-
"Remember to use double quotes (\") for variable names. Can NOT be used with --filter.")
118+
help="A JSON string to be passed in as the object filter to the API call. "
119+
"Remember to use double quotes (\") for variable names. Can NOT be used with --filter. "
120+
"Dont use whitespace outside of strings, or the slcli might have trouble parsing it.")
120121
@environment.pass_env
121122
def cli(env, service, method, parameters, _id, _filters, mask, limit, offset,
122123
output_python=False, json_filter=None):
@@ -137,7 +138,7 @@ def cli(env, service, method, parameters, _id, _filters, mask, limit, offset,
137138
slcli call-api Account getVirtualGuests \\
138139
-f 'virtualGuests.datacenter.name IN dal05,sng01'
139140
slcli call-api Account getVirtualGuests \\
140-
--json-filter '{"virtualGuests":{"hostname": {"operation": "^= test"}}}' --limit=10
141+
--json-filter '{"virtualGuests":{"hostname":{"operation":"^= test"}}}' --limit=10
141142
slcli -v call-api SoftLayer_User_Customer addBulkPortalPermission --id=1234567 \\
142143
'[{"keyName": "NETWORK_MESSAGE_DELIVERY_MANAGE"}]'
143144
"""

SoftLayer/CLI/deprecated.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

SoftLayer/testing/__init__.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
# pylint: disable=invalid-name
99
import logging
1010
import os.path
11+
import unittest
1112

1213
from click import testing
1314
import mock
14-
import testtools
1515

1616
import SoftLayer
1717
from SoftLayer.CLI import core
@@ -68,16 +68,15 @@ def _record_call(self, call):
6868
'offset']:
6969
details.append('%s=%r' % (prop, getattr(call, prop)))
7070

71-
logging.info('%s::%s called; %s',
72-
call.service, call.method, '; '.join(details))
71+
logging.info('%s::%s called; %s', call.service, call.method, '; '.join(details))
7372

7473

7574
def _mock_key(service, method):
7675
"""Key to address a mock object in MockableTransport."""
7776
return '%s::%s' % (service, method)
7877

7978

80-
class TestCase(testtools.TestCase):
79+
class TestCase(unittest.TestCase):
8180
"""Testcase class with PEP-8 compatible method names."""
8281

8382
@classmethod
@@ -100,7 +99,7 @@ def tear_down(self):
10099
"""Aliased from tearDown."""
101100

102101
def setUp(self): # NOQA
103-
testtools.TestCase.setUp(self)
102+
unittest.TestCase.setUp(self)
104103

105104
self.mocks.clear()
106105

@@ -114,7 +113,7 @@ def setUp(self): # NOQA
114113
self.set_up()
115114

116115
def tearDown(self): # NOQA
117-
testtools.TestCase.tearDown(self)
116+
super(TestCase, self).tearDown()
118117
self.tear_down()
119118
self.mocks.clear()
120119

@@ -141,8 +140,7 @@ def assert_called_with(self, service, method, **props):
141140
if self.calls(service, method, **props):
142141
return
143142

144-
raise AssertionError('%s::%s was not called with given properties: %s'
145-
% (service, method, props))
143+
raise AssertionError('%s::%s was not called with given properties: %s' % (service, method, props))
146144

147145
def assert_no_fail(self, result):
148146
"""Fail when a failing click result has an error"""
@@ -170,6 +168,17 @@ def run_command(self, args=None, env=None, fixtures=True, fmt='json', stdin=None
170168
runner = testing.CliRunner()
171169
return runner.invoke(core.cli, args=args, input=stdin, obj=env or self.env)
172170

171+
def assertRaises(self, exception, function_callable, *args, **kwds): # pylint: disable=arguments-differ
172+
"""Converts testtools.assertRaises to unittest.assertRaises calls.
173+
174+
testtools==2.4.0 require unittest2, which breaks pytest>=5.4.1 on skipTest.
175+
But switching to just using unittest breaks assertRaises because the format is slightly different.
176+
This basically just reformats the call so I don't have to re-write a bunch of tests.
177+
"""
178+
with super(TestCase, self).assertRaises(exception) as cm:
179+
function_callable(*args, **kwds)
180+
return cm.exception
181+
173182

174183
def call_has_props(call, props):
175184
"""Check if a call has matching properties of a given props dictionary."""

tests/CLI/deprecated_tests.py

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)