jenkins-bot has submitted this change and it was merged.
Change subject: Solve usage of expectedFailure for tools_tests.py
......................................................................
Solve usage of expectedFailure for tools_tests.py
Bug: T130985
Change-Id: I60a6398f78d3f3dedea8073fa355662eef443cb9
---
M pywikibot/tools/__init__.py
M tests/tools_tests.py
2 files changed, 11 insertions(+), 4 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/tools/__init__.py b/pywikibot/tools/__init__.py
index c2c5bba..cb3e0be 100644
--- a/pywikibot/tools/__init__.py
+++ b/pywikibot/tools/__init__.py
@@ -759,6 +759,8 @@
used automatically. Any other method may be provided explicitly using the
add parameter.
+ Beware that key=id is only useful for cases where id() is not unique.
+
Note: This is not thread safe.
@param iterable: the source iterable
diff --git a/tests/tools_tests.py b/tests/tools_tests.py
index 2d0935e..d48cfb0 100644
--- a/tests/tools_tests.py
+++ b/tests/tools_tests.py
@@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
"""Test tools package alone which don't fit into other
tests."""
#
-# (C) Pywikibot team, 2015
+# (C) Pywikibot team, 2016
#
# Distributed under the terms of the MIT license.
from __future__ import absolute_import, unicode_literals
@@ -409,13 +409,18 @@
deduper = tools.filter_unique(self.decs, container=deduped, key=hash)
self._test_dedup_int(deduped, deduper, hash)
- @unittest.expectedFailure
def test_obj_id(self):
"""Test filter_unique with objects using id as key, which
fails."""
- # Two objects which may be equal do not have the same id.
+ # Two objects which may be equal do not necessary have the same id.
deduped = set()
deduper = tools.filter_unique(self.decs, container=deduped, key=id)
- self._test_dedup_int(deduped, deduper, id)
+ self.assertEqual(len(deduped), 0)
+ for _ in self.decs:
+ self.assertEqual(id(next(deduper)), deduped.pop())
+ self.assertRaises(StopIteration, next, deduper)
+ # No. of Decimal with distinct ids != no. of Decimal with distinct value.
+ deduper_ids = list(tools.filter_unique(self.decs, key=id))
+ self.assertNotEqual(len(deduper_ids), len(set(deduper_ids)))
def test_str(self):
"""Test filter_unique with str."""
--
To view, visit
https://gerrit.wikimedia.org/r/278456
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I60a6398f78d3f3dedea8073fa355662eef443cb9
Gerrit-PatchSet: 4
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>