jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/341143 )
Change subject: Fix ItemClaimFilterPageGenerator ......................................................................
Fix ItemClaimFilterPageGenerator
If negate argument is provided, the if clause is always false and kills the generator.
Change-Id: I2de6036ab3fc4295990472531b5b68f618ce7644 --- M pywikibot/pagegenerators.py M tests/pagegenerators_tests.py 2 files changed, 11 insertions(+), 4 deletions(-)
Approvals: jenkins-bot: Verified Xqt: Looks good to me, approved
diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py index 29ddced..06fa7de 100644 --- a/pywikibot/pagegenerators.py +++ b/pywikibot/pagegenerators.py @@ -1537,7 +1537,7 @@ @type negate: bool """ for page in generator: - if cls.__filter_match(page, prop, claim, qualifiers) and not negate: + if cls.__filter_match(page, prop, claim, qualifiers) is not negate: yield page
diff --git a/tests/pagegenerators_tests.py b/tests/pagegenerators_tests.py index 133caf8..dbcad04 100755 --- a/tests/pagegenerators_tests.py +++ b/tests/pagegenerators_tests.py @@ -666,7 +666,7 @@
"""Test item claim filter page generator generator."""
- def _simple_claim_test(self, prop, claim, qualifiers, valid): + def _simple_claim_test(self, prop, claim, qualifiers, valid, negate=False): """ Test given claim on sample (India) page.
@@ -678,10 +678,12 @@ @param valid: true if the page should be yielded by the generator, false otherwise @type valid: bool + @param negate: true to swap the filters' behavior + @type negate: bool """ item = pywikibot.ItemPage(self.get_repo(), 'Q668') - gen = pagegenerators.ItemClaimFilterPageGenerator([item], prop, - claim, qualifiers) + gen = pagegenerators.ItemClaimFilterPageGenerator([item], prop, claim, + qualifiers, negate) pages = set(gen) self.assertEqual(len(pages), 1 if valid else 0)
@@ -732,6 +734,11 @@ self._simple_claim_test('P625', '21,77', None, True) self._simple_claim_test('P625', '21,78.05,0.01', None, False)
+ def test_negative_filter(self): + """Test negative ItemClaimFilterPageGenerator.""" + self._simple_claim_test('P463', 'Q37470', None, False, True) + self._simple_claim_test('P463', 'Q37471', None, True, True) +
class TestFactoryGenerator(DefaultSiteTestCase):
pywikibot-commits@lists.wikimedia.org