logilab-common #144526 [testlib] assertSameElements removed in Python 3.3 [validation pending]
See the bug on Gentoo here: https://bugs.gentoo.org/show_bug.cgi?id=449276 The problem is this section: if not hasattr(unittest.TestCase, 'assertItemsEqual'): # python 3.2 has deprecated assertSameElements and is missing # assertItemsEqual assertItemsEqual = unittest.TestCase.assertSameElements This is just replacing something that was removed in Python 3.2 with something removed in Python 3.3. It should use assertCountEqual (new in Python 3.2) instead of assertSameElements. | |
priority | normal |
---|---|
type | bug |
done in | 0.60.0 |
load | 0.500 |
load left | 0.000 |
closed by | #49aeb5521e29 testlib: fix for python 3.3 |
patch | testlib: fix for python 3.3 [folded]testlib: fix for python 3.3 [applied] |
Comments
-
2013/06/26 08:10, written by idella4
-
2013/06/27 05:26, written by quantheory
-
2013/06/27 06:40, written by idella4
-
2013/07/19 00:04, written by quantheory
-
2013/07/19 11:42, written by sthenault
-
2013/07/20 02:02, written by quantheory
add commentI am puzzled. This patch is missing the point. This is just replacing something that was removed in Python 3.2 with something removed in
Python 3.3. It should use assertCountEqual has not been invoked, and it still fails under py3.3.
This
@@ -1186,7 +1186,10 @@
if not hasattr(unittest.TestCase, 'assertItemsEqual'):
# python 3.2 has deprecated assertSameElements and is missing
# assertItemsEqual
- assertItemsEqual = unittest.TestCase.assertSameElements
+ if sys.version_info <= (3, 2):
+ assertItemsEqual = unittest.TestCase.assertSameElements
+ else:
+ assertItemsEqual = unittest.TestCase.assertCountEqual
import doctest
works since it substitutes assertCountEqualunder py3.3 which I gather is the whole point.
Though my system has some odd quirk,
if sys.version_info <= (3, 2):
ought arguably be
if sys.version_info != (3, 3):
but never mind, take yr pick.
I just now noticed the patch that got attached here, which of course is wrong. Actually, I personally would use this block, and not refer to assertSameElements at all:
# In Python 3.2, assertItemsEqual was deprecated and assertCountEqual was added.
if sys.version_info >= (3,2):
assertItemsEqual = unittest.TestCase.assertCountEqual
You don't want to use "!=", because that will break again as soon as 3.4 comes out.
yes quite. this block, meaning my patch?
You don't want to use "!=", because that will break again as soon as 3.4 comes out.
yep makes good sense. My system seems to be doing something odd so I had to make an adaption, which was
if sys.version_info == (3, 3):, but the oddity saw it flounder, so I'd like to see it cross checked
in another system where it might work as expected. Just to clarify, you dodn't make that attached patch, no?
My suggestion was to not use assertSameElements, because every version of Python has either assertItemsEqual or assertCountEqual. When I said "this block", I meant the code I put in the same comment. The single "if" with no "else".
I'm not sure what you mean by "the oddity saw it flounder". If one of these doesn't work, maybe that's a problem with the comparison? Does it work to compare one by one, like this?
if sys.version_info[0] >= 3 and sys.version[1] >= 2:
assertItemsEqual = unittest.TestCase.assertCountEqual
And I will confirm; I did not make the attached patch.
would you check the updated patch?
Now the patch is almost correct. Line 94 of the patch should be indented; everything else appears OK.