[Pyunit-interest] Recursive assert_equals.
Brought to you by:
purcell
From: Desilets, A. <Ala...@nr...> - 2006-11-29 14:29:35
|
Is there a way to do a recursive assert_equals on a complex data = structure?=20 For example, say I want to assert that two dictionary are "equal". The = keys of the dictionary are strings, and the values are objects of type = SomeClass, which, among other things, have an attrigute called = some_attribute which is of type SomeOtherClass. I want to write: Self.assert_equal_recusrsive(expected_dict, got_dict) And have the system do the following: - Make sure that expected_dict and got_dict are both of the same type (a = dictionary in this case) - Make sure that they have the same string keys - For each string key, make sure that the associated objects are of the = same type (SomeClass), have the same attributes with same values. - In particular for the some_attribute attribute, it would make sure = that the values are also of the same type (SomeOtherClass), and that = they have the same attribute values pairs. Has this been written before? If not would it be doble (it seems to me = it should be). I know that in jUnit (Java version), this kind of recursive comparison = is supported to at least some extend. For example, if I compare two = dictionnary objects, the system will make sure that the keys are the = same and the values too. But it doesn't go recursively into the = attributes of objects AFAIK. ---- Alain D=E9silets, MASc=20 Agent de recherches/Research Officer=20 Institut de technologie de l'information du CNRC /=20 NRC Institute for Information Technology=20 ala...@nr...=20 T=E9l/Tel (613) 990-2813=20 Facsimile/t=E9l=E9copieur: (613) 952-7151=20 Conseil national de recherches Canada, M50, 1200 chemin Montr=E9al,=20 Ottawa (Ontario) K1A 0R6=20 National Research Council Canada, M50, 1200 Montreal Rd., Ottawa, ON=20 K1A 0R6=20 Gouvernement du Canada | Government of Canada=20 =20 |