Fix parameters of assertEqual are misplaced

Many assertEqual sentences don't follow assertEqual(expected, actual),
These misplaces have 2 impacts:
1, giving confusing messages when some tests failed.
2, mislead other developers, new test modules may follow these wrong pattern.

This patch fix all of them.

Change-Id: I33b5b59fda524d88386072d2058c4770a948db6f
Closes-Bug: #1604213
This commit is contained in:
yanheven 2016-07-23 19:54:15 +08:00
parent 16f40a6392
commit 69cf173ea7
2 changed files with 16 additions and 16 deletions

View File

@ -33,13 +33,13 @@ class TranslationFixtureTest(test_base.BaseTestCase):
def test_lazy(self):
msg = self.trans_fixture.lazy('this is a lazy message')
self.assertIsInstance(msg, _message.Message)
self.assertEqual(msg.msgid, 'this is a lazy message')
self.assertEqual('this is a lazy message', msg.msgid)
def test_immediate(self):
msg = self.trans_fixture.immediate('this is a lazy message')
self.assertNotIsInstance(msg, _message.Message)
self.assertIsInstance(msg, six.text_type)
self.assertEqual(msg, u'this is a lazy message')
self.assertEqual(u'this is a lazy message', msg)
class ToggleLazyFixtureText(test_base.BaseTestCase):

View File

@ -85,8 +85,8 @@ class MessageTestCase(test_base.BaseTestCase):
result = _message.Message(msgid) % params
expected = msgid % params
self.assertEqual(result, expected)
self.assertEqual(result.translate(), expected)
self.assertEqual(expected, result)
self.assertEqual(expected, result.translate())
def test_multiple_mod_with_named_parameter(self):
msgid = ("%(description)s\nCommand: %(cmd)s\n"
@ -145,8 +145,8 @@ class MessageTestCase(test_base.BaseTestCase):
result = _message.Message(msgid) % params
expected = msgid % params
self.assertEqual(result, expected)
self.assertEqual(result.translate(), expected)
self.assertEqual(expected, result)
self.assertEqual(expected, result.translate())
def test_mod_with_dict_parameter(self):
msgid = "Test that we can inject a dictionary %s"
@ -204,12 +204,12 @@ class MessageTestCase(test_base.BaseTestCase):
for message, result in zip(messages, results):
self.assertEqual(type(result), _message.Message)
self.assertEqual(result.translate(), message)
self.assertEqual(message, result.translate())
# simulate writing out as string
result_str = '%s' % result.translate()
self.assertEqual(result_str, message)
self.assertEqual(result, message)
self.assertEqual(message, result)
def test_mod_copies_parameters(self):
msgid = "Found object: %(current_value)s"
@ -220,7 +220,7 @@ class MessageTestCase(test_base.BaseTestCase):
changing_dict['current_value'] = 2
# Even if the param changes when the message is
# translated it should use the original param
self.assertEqual(result.translate(), 'Found object: 1')
self.assertEqual('Found object: 1', result.translate())
def test_mod_deep_copies_parameters(self):
msgid = "Found list: %(current_list)s"
@ -232,26 +232,26 @@ class MessageTestCase(test_base.BaseTestCase):
changing_list.append(4)
# Even though the list changed the message
# translation should use the original list
self.assertEqual(result.translate(), "Found list: [1, 2, 3]")
self.assertEqual("Found list: [1, 2, 3]", result.translate())
def test_mod_deep_copies_param_nodeep_param(self):
msgid = "Value: %s"
params = utils.NoDeepCopyObject(5)
# Apply the params
result = _message.Message(msgid) % params
self.assertEqual(result.translate(), "Value: 5")
self.assertEqual("Value: 5", result.translate())
def test_mod_deep_copies_param_nodeep_dict(self):
msgid = "Values: %(val1)s %(val2)s"
params = {'val1': 1, 'val2': utils.NoDeepCopyObject(2)}
# Apply the params
result = _message.Message(msgid) % params
self.assertEqual(result.translate(), "Values: 1 2")
self.assertEqual("Values: 1 2", result.translate())
# Apply again to make sure other path works as well
params = {'val1': 3, 'val2': utils.NoDeepCopyObject(4)}
result = _message.Message(msgid) % params
self.assertEqual(result.translate(), "Values: 3 4")
self.assertEqual("Values: 3 4", result.translate())
def test_mod_returns_a_copy(self):
msgid = "Some msgid string: %(test1)s %(test2)s"
@ -287,11 +287,11 @@ class MessageTestCase(test_base.BaseTestCase):
result = _message.Message(msgid) % params
expected = msgid % params
self.assertEqual(result, expected)
self.assertEqual(result.translate(), expected)
self.assertEqual(expected, result)
self.assertEqual(expected, result.translate())
# Make sure unused params still there
self.assertEqual(result.params.keys(), params.keys())
self.assertEqual(params.keys(), result.params.keys())
def test_add_disabled(self):
msgid = "A message"