Пример #1
0
    def testQueriesWDStructures(self):
        """
        Queries using Wikibase page structures like ItemPage
        """

        q = query.HasClaim(PropertyPage(self.repo, "P99"))
        self.assertEqual(str(q), "claim[99]")

        q = query.HasClaim(PropertyPage(self.repo, "P99"),
                           ItemPage(self.repo, "Q100"))
        self.assertEqual(str(q), "claim[99:100]")

        q = query.HasClaim(99, [100, PropertyPage(self.repo, "P101")])
        self.assertEqual(str(q), "claim[99:100,101]")

        q = query.StringClaim(PropertyPage(self.repo, "P99"), "Hello")
        self.assertEqual(str(q), 'string[99:"Hello"]')

        q = query.Tree(ItemPage(self.repo, "Q92"), [1], 2)
        self.assertEqual(str(q), 'tree[92][1][2]')

        q = query.Tree(ItemPage(self.repo, "Q92"),
                       [PropertyPage(self.repo, "P101")], 2)
        self.assertEqual(str(q), 'tree[92][101][2]')

        self.assertRaises(
            TypeError, lambda: query.Tree(PropertyPage(
                self.repo, "P92"), [PropertyPage(self.repo, "P101")], 2))

        c = pywikibot.Coordinate(50, 60)
        q = query.Around(PropertyPage(self.repo, "P625"), c, 23.4)
        self.assertEqual(str(q), 'around[625,50,60,23.4]')

        begin = pywikibot.WbTime(site=self.repo, year=1999)
        end = pywikibot.WbTime(site=self.repo, year=2010, hour=1)

        # note no second comma
        q = query.Between(PropertyPage(self.repo, "P569"), begin)
        self.assertEqual(str(q), 'between[569,+00000001999-01-01T00:00:00Z]')

        q = query.Between(PropertyPage(self.repo, "P569"), end=end)
        self.assertEqual(str(q), 'between[569,,+00000002010-01-01T01:00:00Z]')

        q = query.Between(569, begin, end)
        self.assertEqual(
            str(q),
            'between[569,+00000001999-01-01T00:00:00Z,+00000002010-01-01T01:00:00Z]'
        )

        # try negative year
        begin = pywikibot.WbTime(site=self.repo, year=-44)
        q = query.Between(569, begin, end)
        self.assertEqual(
            str(q),
            'between[569,-00000000044-01-01T00:00:00Z,+00000002010-01-01T01:00:00Z]'
        )
Пример #2
0
    def test_lastrevid_del(self):
        """Test del with deprecated lastrevid."""
        item = ItemPage(self.get_repo(), 'Q60')
        item.get()
        self.assertTrue(hasattr(item, 'lastrevid'))
        self.assertTrue(hasattr(item, '_revid'))

        del item.lastrevid
        self.assertFalse(hasattr(item, 'lastrevid'))
        self.assertFalse(hasattr(item, '_revid'))
        self.assertDeprecation()
    def test_lastrevid_del(self):
        """Test del with deprecated lastrevid."""
        item = ItemPage(self.get_repo(), 'Q60')
        item.get()
        self.assertTrue(hasattr(item, 'lastrevid'))
        self.assertTrue(hasattr(item, '_revid'))

        del item.lastrevid
        self.assertFalse(hasattr(item, 'lastrevid'))
        self.assertFalse(hasattr(item, '_revid'))
        self.assertDeprecation()
Пример #4
0
    def test_lastrevid(self):
        """Test deprecated lastrevid."""
        item = ItemPage(self.get_repo(), 'Q60')
        self.assertFalse(hasattr(item, 'lastrevid'))
        item.get()
        self.assertTrue(hasattr(item, 'lastrevid'))
        self.assertIsInstance(item.lastrevid, int)
        self.assertDeprecation()
        self._reset_messages()

        item.lastrevid = 1
        self.assertTrue(hasattr(item, 'lastrevid'))
        self.assertTrue(hasattr(item, '_revid'))
        self.assertEqual(item.lastrevid, 1)
        self.assertEqual(item._revid, 1)
        self.assertDeprecation()
    def test_lastrevid(self):
        """Test deprecated lastrevid."""
        item = ItemPage(self.get_repo(), 'Q60')
        self.assertFalse(hasattr(item, 'lastrevid'))
        item.get()
        self.assertTrue(hasattr(item, 'lastrevid'))
        self.assertIsInstance(item.lastrevid, int)
        self.assertDeprecation()
        self._reset_messages()

        item.lastrevid = 1
        self.assertTrue(hasattr(item, 'lastrevid'))
        self.assertTrue(hasattr(item, '_revid'))
        self.assertEqual(item.lastrevid, 1)
        self.assertEqual(item._revid, 1)
        self.assertDeprecation()
Пример #6
0
 def add_main_subject(self,
                      itemWD: ItemPage,
                      target_id: str = None,
                      target: ItemPage = None):
     """ создать ссылку на элемент темы """
     claim_topic_subject = self.claim_instance.claim_main_subject()
     # pwb.Claim(self.WD, props.topic_subject)
     if target_id:
         wditem_subject = pwb.ItemPage(self.WD, target_id)
     elif target:
         wditem_subject = target
     else:
         return
     # target = wd_item_ids[0]
     claim_topic_subject.setTarget(wditem_subject)
     if self.test_run:
         return
     itemWD.addClaim(claim_topic_subject,
                     bot=self.as_bot,
                     summary='moved from ruwikisource')
     pwb.stdout(f'added main subject in item')
Пример #7
0
 def add_article_in_subjectitem(self, p, subject_item: ItemPage,
                                target_item: ItemPage):
     """ создать "описывается в источниках" в элементе темы """
     # s = get_item_from_listdict(other_sources, 'argument', m_item_id)
     # [i.target for i in self.wd_item.claims.get(self.main_subject, [])]
     claim_described_by = self.claim_instance.claim_described_by_source()
     rootpagename = p.rootpagename
     if p.rootpagename == 'Лентапедия' and p.title.endswith(
             '/Полная версия'):
         rootpagename = 'Лентапедия2'
     target = p.enc_meta['wditem']
     claim_described_by.setTarget(target)
     qualifier = self.claim_instance.claim_dedicated_article()
     # qualifier_target = pwb.ItemPage(self.WD, m_item_id)
     qualifier.setTarget(target_item)
     claim_described_by.addQualifier(qualifier)
     if self.test_run:
         return
     subject_item.addClaim(claim_described_by,
                           bot=self.as_bot,
                           summary='moved from ruwikisource')
     pwb.stdout(f'added item of article in subject item')
 def setUp(self):
     """Setup tests."""
     self._page = ItemPage(self.get_repo(), 'Q60')
     super(TestItemBasePageMethods, self).setUp()
 def setUp(self):
     """Setup test."""
     self._page = ItemPage(self.get_repo(), 'Q60')
     super(TestLoadRevisionsCaching, self).setUp()