diff options
| author | Johannes Erdfelt <johannes.erdfelt@rackspace.com> | 2013-01-22 19:30:40 +0000 |
|---|---|---|
| committer | Johannes Erdfelt <johannes.erdfelt@rackspace.com> | 2013-01-22 19:41:57 +0000 |
| commit | 5aec4bf8858afa139e9abc7d75faeaf506232672 (patch) | |
| tree | 412965873213d435bad9ac838ac15fb49342c59d | |
| parent | 343ba7ac288a350c0b20f0bb31a27df756259da6 (diff) | |
Make compare_result show the difference in lists
If two lists had differed because one had an extra element, both lists
would be included in the exception message. If the lists were large (for
example the list of extensions) it could be very difficult trying to
figure out what is different between the two lists.
This change will show the items that only exist in the expected and/or
result and not the other list.
Change-Id: I6102faea037b4f5e31361adc9db81e79592b7008
| -rw-r--r-- | nova/tests/integrated/test_api_samples.py | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/nova/tests/integrated/test_api_samples.py b/nova/tests/integrated/test_api_samples.py index 949f14177..f101da243 100644 --- a/nova/tests/integrated/test_api_samples.py +++ b/nova/tests/integrated/test_api_samples.py @@ -171,23 +171,32 @@ class ApiSampleTestBase(integrated_helpers._IntegratedTestBase): if not isinstance(result, list): raise NoMatch( _('Result: %(result)s is not a list.') % locals()) - if len(expected) != len(result): - raise NoMatch( - _('Length mismatch: %(result)s\n%(expected)s.') - % locals()) + + expected = expected[:] + extra = [] for res_obj in result: - for ex_obj in expected: + for i, ex_obj in enumerate(expected): try: - res = self._compare_result(subs, ex_obj, res_obj) + matched_value = self._compare_result(subs, ex_obj, + res_obj) + del expected[i] break except NoMatch: pass else: - raise NoMatch( - _('Result: %(res_obj)s not in %(expected)s.') - % locals()) - matched_value = res or matched_value + extra.append(res_obj) + + error = [] + if expected: + error.append(_('Extra items in expected:')) + error.extend([repr(o) for o in expected]) + + if extra: + error.append(_('Extra items in result:')) + error.extend([repr(o) for o in extra]) + if error: + raise NoMatch('\n'.join(error)) elif isinstance(expected, basestring) and '%' in expected: # NOTE(vish): escape stuff for regex for char in '[]<>?': |
