summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark McLoughlin <markmc@redhat.com>2013-08-07 06:43:55 +0100
committerMark McLoughlin <markmc@redhat.com>2013-08-07 06:43:55 +0100
commitcb2623f46e29d0a8911221d2fd77163369d07283 (patch)
tree150e85c6cad3f9db130b4ed1eb6ddcd800614d7f
parent3471e02b4ac6a7edaf41ac8df03f85d5a46da2eb (diff)
downloadoslo-messaging-cb2623f46e29d0a8911221d2fd77163369d07283.tar.gz
Use testtools.TestCase assertion methods
I typically avoided using e.g. assertIsNone() thinking we couldn't use it on 2.7, but now that we use testtools.TestCast there are a bunch of useful assertion methods we can use. Change-Id: I7696dc4744cdfd2466773326f202bc08dcfcbf0f
-rw-r--r--tests/test_exception_serialization.py4
-rw-r--r--tests/test_pool.py6
-rw-r--r--tests/test_rabbit.py11
-rw-r--r--tests/test_rpc_client.py8
-rw-r--r--tests/test_rpc_dispatcher.py4
-rw-r--r--tests/test_rpc_server.py28
-rw-r--r--tests/test_target.py4
-rw-r--r--tests/test_transport.py12
8 files changed, 38 insertions, 39 deletions
diff --git a/tests/test_exception_serialization.py b/tests/test_exception_serialization.py
index c3103a2..a1de6ee 100644
--- a/tests/test_exception_serialization.py
+++ b/tests/test_exception_serialization.py
@@ -136,7 +136,7 @@ class SerializeRemoteExceptionTestCase(test_utils.BaseTestCase):
# Note: _Remote prefix not stripped from tracebacks
tb = ex.__class__.__name__ + ': ' + self.msg
- self.assertTrue(tb in ''.join(failure['tb']))
+ self.assertIn(tb, ''.join(failure['tb']))
if self.log_failure:
self.assertTrue(len(errors) > 0, errors)
@@ -307,7 +307,7 @@ class DeserializeRemoteExceptionTestCase(test_utils.BaseTestCase):
ex = exceptions.deserialize_remote_exception(self.conf, serialized)
- self.assertTrue(isinstance(ex, self.cls))
+ self.assertIsInstance(ex, self.cls)
self.assertEqual(ex.__class__.__name__, self.remote_name)
self.assertEqual(str(ex), self.str)
self.assertEqual(ex.message, self.msg)
diff --git a/tests/test_pool.py b/tests/test_pool.py
index ec4795c..8ea2f07 100644
--- a/tests/test_pool.py
+++ b/tests/test_pool.py
@@ -89,11 +89,11 @@ class PoolTestCase(test_utils.BaseTestCase):
objs = []
for i in range(self.n_iters):
objs.append(p.get())
- self.assertTrue(isinstance(objs[i], uuid.UUID))
+ self.assertIsInstance(objs[i], uuid.UUID)
def wait_for_obj():
o = p.get()
- self.assertTrue(o in objs)
+ self.assertIn(o, objs)
waiter = self.ThreadWaitWaiter(p._cond, self.n_iters, self.stubs)
@@ -115,7 +115,7 @@ class PoolTestCase(test_utils.BaseTestCase):
p.put(o)
for o in p.iter_free():
- self.assertTrue(o in objs)
+ self.assertIn(o, objs)
objs.remove(o)
self.assertEquals(objs, [])
diff --git a/tests/test_rabbit.py b/tests/test_rabbit.py
index 5f14182..0116f21 100644
--- a/tests/test_rabbit.py
+++ b/tests/test_rabbit.py
@@ -43,8 +43,7 @@ class TestRabbitDriverLoad(test_utils.BaseTestCase):
def test_driver_load(self):
transport = messaging.get_transport(self.conf)
- self.assertTrue(isinstance(transport._driver,
- rabbit_driver.RabbitDriver))
+ self.assertIsInstance(transport._driver, rabbit_driver.RabbitDriver)
class TestSendReceive(test_utils.BaseTestCase):
@@ -110,7 +109,7 @@ class TestSendReceive(test_utils.BaseTestCase):
senders[i].start()
received = listener.poll()
- self.assertTrue(received is not None)
+ self.assertIsNotNone(received)
self.assertEqual(received.ctxt, self.ctxt)
self.assertEqual(received.message, {'foo': i})
msgs.append(received)
@@ -136,7 +135,7 @@ class TestSendReceive(test_utils.BaseTestCase):
if not self.failure:
self.assertEqual(reply, {'bar': order[i]})
else:
- self.assertTrue(isinstance(reply, ZeroDivisionError))
+ self.assertIsInstance(reply, ZeroDivisionError)
TestSendReceive.generate_scenarios()
@@ -272,7 +271,7 @@ class TestRequestWireFormat(test_utils.BaseTestCase):
connection.drain_events()
self.assertEqual(1, len(msgs))
- self.assertTrue('oslo.message' in msgs[0])
+ self.assertIn('oslo.message', msgs[0])
received = msgs[0]
received['oslo.message'] = jsonutils.loads(received['oslo.message'])
@@ -418,7 +417,7 @@ class TestReplyWireFormat(test_utils.BaseTestCase):
producer.publish(msg)
received = listener.poll()
- self.assertTrue(received is not None)
+ self.assertIsNotNone(received)
self.assertEqual(self.expected_ctxt, received.ctxt)
self.assertEqual(self.expected, received.message)
diff --git a/tests/test_rpc_client.py b/tests/test_rpc_client.py
index 9717e20..14ddf53 100644
--- a/tests/test_rpc_client.py
+++ b/tests/test_rpc_client.py
@@ -400,8 +400,8 @@ class TestVersionCap(test_utils.BaseTestCase):
try:
method({}, 'foo')
except Exception as ex:
- self.assertTrue(isinstance(ex, messaging.RPCVersionCapError), ex)
- self.assertTrue(not self.success)
+ self.assertIsInstance(ex, messaging.RPCVersionCapError, ex)
+ self.assertFalse(self.success)
else:
self.assertTrue(self.success)
@@ -504,7 +504,7 @@ class TestCheckForLock(test_utils.BaseTestCase):
transport = _FakeTransport(self.conf)
def check_for_lock(conf):
- self.assertTrue(conf is self.conf)
+ self.assertIs(conf, self.conf)
return self.locks_held
client = messaging.RPCClient(transport, messaging.Target(),
@@ -529,6 +529,6 @@ class TestCheckForLock(test_utils.BaseTestCase):
if self.warning:
self.assertEqual(len(warnings), 1)
- self.assertTrue(self.warning in warnings[0])
+ self.assertIn(self.warning, warnings[0])
else:
self.assertEqual(len(warnings), 0)
diff --git a/tests/test_rpc_dispatcher.py b/tests/test_rpc_dispatcher.py
index 49ba348..0dbce62 100644
--- a/tests/test_rpc_dispatcher.py
+++ b/tests/test_rpc_dispatcher.py
@@ -114,8 +114,8 @@ class TestDispatcher(test_utils.BaseTestCase):
dispatcher(self.ctxt, self.msg)
except Exception as ex:
self.assertFalse(self.success, ex)
- self.assertTrue(self.ex is not None, ex)
- self.assertTrue(isinstance(ex, self.ex), ex)
+ self.assertIsNotNone(self.ex, ex)
+ self.assertIsInstance(ex, self.ex, ex)
if isinstance(ex, messaging.NoSuchMethod):
self.assertEqual(ex.method, self.msg.get('method'))
elif isinstance(ex, messaging.UnsupportedVersion):
diff --git a/tests/test_rpc_server.py b/tests/test_rpc_server.py
index 3aefbcf..28731f6 100644
--- a/tests/test_rpc_server.py
+++ b/tests/test_rpc_server.py
@@ -97,13 +97,13 @@ class TestRPCServer(test_utils.BaseTestCase, ServerSetupMixin):
server = messaging.get_rpc_server(transport, target, endpoints,
serializer=serializer)
- self.assertTrue(server.conf is self.conf)
- self.assertTrue(server.transport is transport)
- self.assertTrue(server.target is target)
- self.assertTrue(isinstance(server.dispatcher, messaging.RPCDispatcher))
- self.assertTrue(server.dispatcher.endpoints is endpoints)
- self.assertTrue(server.dispatcher.serializer is serializer)
- self.assertTrue(server.executor is 'blocking')
+ self.assertIs(server.conf, self.conf)
+ self.assertIs(server.transport, transport)
+ self.assertIs(server.target, target)
+ self.assertIsInstance(server.dispatcher, messaging.RPCDispatcher)
+ self.assertIs(server.dispatcher.endpoints, endpoints)
+ self.assertIs(server.dispatcher.serializer, serializer)
+ self.assertIs(server.executor, 'blocking')
def test_no_target_server(self):
transport = messaging.get_transport(self.conf, url='fake:')
@@ -114,7 +114,7 @@ class TestRPCServer(test_utils.BaseTestCase, ServerSetupMixin):
try:
server.start()
except Exception as ex:
- self.assertTrue(isinstance(ex, messaging.ServerListenError), ex)
+ self.assertIsInstance(ex, messaging.ServerListenError, ex)
self.assertEqual(ex.target.topic, 'testtopic')
else:
self.assertTrue(False)
@@ -126,7 +126,7 @@ class TestRPCServer(test_utils.BaseTestCase, ServerSetupMixin):
try:
server.start()
except Exception as ex:
- self.assertTrue(isinstance(ex, messaging.ServerListenError), ex)
+ self.assertIsInstance(ex, messaging.ServerListenError, ex)
self.assertEqual(ex.target.server, 'testserver')
else:
self.assertTrue(False)
@@ -141,8 +141,8 @@ class TestRPCServer(test_utils.BaseTestCase, ServerSetupMixin):
try:
method({}, 'ping', arg='foo')
except Exception as ex:
- self.assertTrue(isinstance(ex, messaging.ClientSendError), ex)
- self.assertTrue(ex.target is not None)
+ self.assertIsInstance(ex, messaging.ClientSendError, ex)
+ self.assertIsNotNone(ex.target)
else:
self.assertTrue(False)
@@ -170,7 +170,7 @@ class TestRPCServer(test_utils.BaseTestCase, ServerSetupMixin):
try:
client.prepare(timeout=0).call({}, 'ping', arg='foo')
except Exception as ex:
- self.assertTrue(isinstance(ex, messaging.MessagingTimeout), ex)
+ self.assertIsInstance(ex, messaging.MessagingTimeout, ex)
else:
self.assertTrue(False)
@@ -186,7 +186,7 @@ class TestRPCServer(test_utils.BaseTestCase, ServerSetupMixin):
try:
messaging.get_rpc_server(transport, None, [], executor='foo')
except Exception as ex:
- self.assertTrue(isinstance(ex, messaging.ExecutorLoadFailure))
+ self.assertIsInstance(ex, messaging.ExecutorLoadFailure)
self.assertEqual(ex.executor, 'foo')
else:
self.assertTrue(False)
@@ -415,7 +415,7 @@ class TestMultipleServers(test_utils.BaseTestCase, ServerSetupMixin):
def check(pings, expect):
self.assertEqual(len(pings), len(expect))
for a in expect:
- self.assertTrue(a in pings)
+ self.assertIn(a, pings)
if self.expect_either:
check(endpoint1.pings + endpoint2.pings, self.expect_either)
diff --git a/tests/test_target.py b/tests/test_target.py
index b5ae240..98e25fa 100644
--- a/tests/test_target.py
+++ b/tests/test_target.py
@@ -41,7 +41,7 @@ class TargetConstructorTestCase(test_utils.BaseTestCase):
'version', 'server', 'fanout']:
if k in self.kwargs:
continue
- self.assertTrue(getattr(target, k) is None)
+ self.assertIsNone(getattr(target, k))
class TargetCallableTestCase(test_utils.BaseTestCase):
@@ -95,7 +95,7 @@ class TargetCallableTestCase(test_utils.BaseTestCase):
'version', 'server', 'fanout']:
if k in self.vals:
continue
- self.assertTrue(getattr(target, k) is None)
+ self.assertIsNone(getattr(target, k))
class TargetReprTestCase(test_utils.BaseTestCase):
diff --git a/tests/test_transport.py b/tests/test_transport.py
index 83b0dda..9240f96 100644
--- a/tests/test_transport.py
+++ b/tests/test_transport.py
@@ -109,9 +109,9 @@ class GetTransportTestCase(test_utils.BaseTestCase):
transport = messaging.get_transport(self.conf, url=self.url)
- self.assertTrue(transport is not None)
- self.assertTrue(transport.conf is self.conf)
- self.assertTrue(transport._driver is drvr)
+ self.assertIsNotNone(transport)
+ self.assertIs(transport.conf, self.conf)
+ self.assertIs(transport._driver, drvr)
class GetTransportSadPathTestCase(test_utils.BaseTestCase):
@@ -164,10 +164,10 @@ class GetTransportSadPathTestCase(test_utils.BaseTestCase):
ex_cls = self.ex.pop('cls')
ex_msg_contains = self.ex.pop('msg_contains')
- self.assertTrue(isinstance(ex, messaging.MessagingException))
- self.assertTrue(isinstance(ex, ex_cls))
+ self.assertIsInstance(ex, messaging.MessagingException)
+ self.assertIsInstance(ex, ex_cls)
self.assertTrue(hasattr(ex, 'msg'))
- self.assertTrue(ex_msg_contains in ex.msg)
+ self.assertIn(ex_msg_contains, ex.msg)
for k, v in self.ex.items():
self.assertTrue(hasattr(ex, k))