Commit 4458b7e5 authored by Julien Muchembled's avatar Julien Muchembled

tests: Mock objects can't be passed to assert(Not)Equal

This fixes tests on Python 2.7

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2693 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 398056ce
......@@ -89,6 +89,18 @@ class NeoTestBase(unittest.TestCase):
sys.stdout.write('\n')
sys.stdout.flush()
def failUnlessEqual(self, first, second, msg=None):
assert not (isinstance(first, Mock) or isinstance(second, Mock)), \
"Mock objects can't be compared with '==' or '!='"
return super(NeoTestBase, self).failUnlessEqual(first, second, msg=msg)
assertEqual = assertEquals = failUnlessEqual
def failIfEqual(self, first, second, msg=None):
assert not (isinstance(first, Mock) or isinstance(second, Mock)), \
"Mock objects can't be compared with '==' or '!='"
return super(NeoTestBase, self).failIfEqual(first, second, msg=msg)
assertNotEqual = assertNotEquals = failIfEqual
class NeoUnitTestBase(NeoTestBase):
""" Base class for neo tests, implements common checks """
......
......@@ -359,8 +359,7 @@ class ClientApplicationTests(NeoUnitTestBase):
tid = self.makeTID()
txn = Mock()
# first, tid is supplied
self.assertNotEquals(getattr(app, 'tid', None), tid)
self.assertNotEquals(getattr(app, 'txn', None), txn)
self.assertTrue(app._txn_container.get(txn) is None)
packet = Packets.AnswerBeginTransaction(tid=tid)
packet.setId(0)
app.master_conn = Mock({
......
......@@ -145,9 +145,9 @@ class ConnectionTests(NeoUnitTestBase):
# init with connector
registerConnectorHandler(DoNothingConnector)
connector = getConnectorHandler("DoNothingConnector")()
self.assertNotEqual(connector, None)
self.assertFalse(connector is None)
bc = self._makeConnection()
self.assertNotEqual(bc.connector, None)
self.assertFalse(bc.connector is None)
self._checkRegistered(1)
def test_01_BaseConnection2(self):
......@@ -659,12 +659,12 @@ class ConnectionTests(NeoUnitTestBase):
self.assertFalse(bc.isServer())
self._checkMakeClientConnection(1)
# check call to handler
self.assertNotEqual(bc.getHandler(), None)
self.assertFalse(bc.getHandler() is None)
self._checkConnectionStarted(1)
self._checkConnectionCompleted(1)
self._checkConnectionFailed(0)
# check call to event manager
self.assertNotEqual(bc.getEventManager(), None)
self.assertFalse(bc.getEventManager() is None)
self._checkReaderAdded(1)
self._checkWriterAdded(0)
......@@ -683,12 +683,12 @@ class ConnectionTests(NeoUnitTestBase):
self.assertFalse(bc.isServer())
self._checkMakeClientConnection(1)
# check call to handler
self.assertNotEqual(bc.getHandler(), None)
self.assertFalse(bc.getHandler() is None)
self._checkConnectionStarted(1)
self._checkConnectionCompleted(0)
self._checkConnectionFailed(0)
# check call to event manager
self.assertNotEqual(bc.getEventManager(), None)
self.assertFalse(bc.getEventManager() is None)
self._checkReaderAdded(1)
self._checkWriterAdded(1)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment