This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2014年09月21日 11:12 by simonzack, last changed 2022年04月11日 14:58 by admin.
| Messages (6) | |||
|---|---|---|---|
| msg227210 - (view) | Author: Simon Zack (simonzack) | Date: 2014年09月21日 11:12 | |
Functions added by addTypeEqualityFunc is not used for comparing list elements in assertListEqual, and only used in assertEqual. It would be nice to have assertListEqual use functions added by addTypeEqualityFunc for comparisons of list elements. I think this provides more flexibility, and we get nicely formatted error messages for nested list compares for free. |
|||
| msg227212 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2014年09月21日 11:16 | |
That sounds reasonable to me. Do you want to provide a patch? See https://docs.python.org/devguide/ for guidelines. |
|||
| msg227222 - (view) | Author: Ezio Melotti (ezio.melotti) * (Python committer) | Date: 2014年09月21日 18:29 | |
Currently assertListEqual calls assertSequenceEqual, and assertSequenceEqual doesn't use any function to compare list elements -- it just does "if item1 != item2:" (https://hg.python.org/cpython/file/default/Lib/unittest/case.py). Checking the types of the two items and compare them recursively could be done, but it's not as simple as it sounds, since using e.g. assertSequenceEqual will raise an error message that will need to be caught and integrated with the error message that it's already being constructed, possibly resulting in a long and unreadable message. Since this is a somewhat specific situation, it might be better if you just defined your own assert function for nested lists. In addition to nested lists you might have a dictionary that contains lists, or a set of tuples or any other combinations of arbitrarily nested containers, and having a generic way to handle them all will require quite a lot of work. One thing that could be done is to add more attributes to the exception raised by assertSequenceEqual (and others), so that you could do something like: try: self.assertEqual(nested_list1, nested_list2) except AssertionError as exc: index = exc.first_differing_index self.assertEqual(nested_list1[index], nested_list2[index], msg=str(exc)) Not sure how that will look light though, and it's still not a generic solution, but if you know what are you dealing with, it might be helpful. |
|||
| msg230776 - (view) | Author: Robert Collins (rbcollins) * (Python committer) | Date: 2014年11月07日 09:58 | |
https://code.google.com/p/unittest-ext/issues/detail?id=11 I think that the hamcrest inspired matchers stuff may help make this a reality too. OTOH if we had a clean patch now for the existing asserts that would be fine too. |
|||
| msg230785 - (view) | Author: Robert Collins (rbcollins) * (Python committer) | Date: 2014年11月07日 10:30 | |
See also https://code.google.com/p/unittest-ext/issues/detail?id=27 "Sorry, wrong wording of the bug. I tested this on IronPython 2.6.1 and 2.7.b1. I see the same result as you and I consider the following wrong or at least misleading: - [1, Decimal("1"), Decimal("2.00")] ? ^ --- + [2, Decimal("1.00"), Decimal("2")] ? ^ +++ I mean the +++ and --- under Decimal numbers. On the other hand I understand that these are differences in string representation of those lists..." |
|||
| msg399199 - (view) | Author: Irit Katriel (iritkatriel) * (Python committer) | Date: 2021年08月07日 19:03 | |
I've closed issue44819 as a duplicate of this. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:58:08 | admin | set | github: 66642 |
| 2021年08月07日 19:03:47 | iritkatriel | set | nosy:
+ iritkatriel messages: + msg399199 versions: + Python 3.11, - Python 3.5 |
| 2021年08月04日 17:40:20 | iritkatriel | link | issue44819 superseder |
| 2015年08月18日 14:00:24 | anton.barkovsky | set | nosy:
+ anton.barkovsky |
| 2014年11月07日 10:30:35 | rbcollins | set | messages: + msg230785 |
| 2014年11月07日 09:58:16 | rbcollins | set | messages: + msg230776 |
| 2014年11月01日 22:09:27 | ezio.melotti | set | nosy:
+ rbcollins |
| 2014年09月21日 18:29:23 | ezio.melotti | set | nosy:
+ serhiy.storchaka messages: + msg227222 |
| 2014年09月21日 16:36:19 | r.david.murray | set | nosy:
+ r.david.murray |
| 2014年09月21日 11:16:05 | pitrou | set | versions:
+ Python 3.5 nosy: + ezio.melotti, michael.foord, pitrou messages: + msg227212 stage: needs patch |
| 2014年09月21日 11:12:16 | simonzack | set | type: enhancement |
| 2014年09月21日 11:12:08 | simonzack | create | |