[Pyunit-interest] Fwd: Recursive assert_equals.
Brought to you by:
purcell
From: Ori P. <or...@us...> - 2006-12-06 00:51:06
|
Oops, corrected mailing list address. ---------- Forwarded message ---------- From: Ori Peleg <or...@us...> Date: Dec 6, 2006 2:47 AM Subject: Re: [Pyunit-interest] Recursive assert_equals. To: "Desilets, Alain" <Ala...@nr...> Cc: pyu...@li... Doesn't the equality operator do what you want? http://docs.python.org/ref/comparisons.html As long as your classes implement __eq__ or __cmp__, assertEquals should work fine. (http://docs.python.org/ref/customization.html) On 11/29/06, Desilets, Alain <Ala...@nr...> wrote: > Is there a way to do a recursive assert_equals on a complex data structur= e? > > For example, say I want to assert that two dictionary are "equal". The ke= ys of the dictionary are strings, and the values are objects of type SomeCl= ass, which, among other things, have an attrigute called some_attribute whi= ch 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 s= ame 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 dictionna= ry objects, the system will make sure that the keys are the same and the va= lues too. But it doesn't go recursively into the attributes of objects AFAI= K. > > > ---- > Alain D=E9silets, MASc > Agent de recherches/Research Officer > Institut de technologie de l'information du CNRC / > NRC Institute for Information Technology > > ala...@nr... > T=E9l/Tel (613) 990-2813 > Facsimile/t=E9l=E9copieur: (613) 952-7151 > > Conseil national de recherches Canada, M50, 1200 chemin Montr=E9al, > Ottawa (Ontario) K1A 0R6 > National Research Council Canada, M50, 1200 Montreal Rd., Ottawa, ON > K1A 0R6 > > Gouvernement du Canada | Government of Canada > > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share y= our > opinions on IT & business topics through brief surveys - and earn cash > http://www.techsay.com/default.php?page=3Djoin.php&p=3Dsourceforge&CID=3D= DEVDEV > _______________________________________________ > Pyunit-interest mailing list > Pyu...@li... > https://lists.sourceforge.net/lists/listinfo/pyunit-interest > |