def testTwoThreadsWithCommentedOutThread(self): """Test recognizing two threads and ignoring a commented out thread. Talk:For-pywikibot-archivebot must have: {{User:MiszaBot/config |archive = Talk:Main_Page/archive |algo = old(30d) }} <!-- normal comments --> == A == foo bar <!-- == Z == foo bar bar --> == B == foo bar bar bar """ page = pywikibot.Page(self.get_site(), 'Talk:For-pywikibot-archivebot') archiver = archivebot.PageArchiver(page=page, tpl='User:MiszaBot/config', salt='', force=False) page = archivebot.DiscussionPage(page, archiver) page.load_page() self.assertEqual([x.title for x in page.threads], ['A', 'B'])
def test_archivebot(self, code=None): """Test archivebot for one site.""" site = self.get_site(code) page = pywikibot.Page(site, 'user talk:mpaa') talk = archivebot.DiscussionPage(page, None) self.assertIsInstance(talk.archives, dict) self.assertIsInstance(talk.archived_threads, int) self.assertTrue(talk.archiver is None) self.assertIsInstance(talk.header, basestring) self.assertIsInstance(talk.timestripper, TimeStripper) self.assertIsInstance(talk.threads, list) self.assertGreaterEqual( len(talk.threads), THREADS_WITH_UPDATED_FORMAT[code], u'%d Threads found on %s,\n%d or more expected' % (len(talk.threads), talk, THREADS_WITH_UPDATED_FORMAT[code])) for thread in talk.threads: self.assertIsInstance(thread, archivebot.DiscussionThread) self.assertIsInstance(thread.title, basestring) self.assertIsInstance(thread.now, datetime) self.assertEqual(thread.now, talk.now) self.assertIsInstance(thread.ts, TimeStripper) self.assertEqual(thread.ts, talk.timestripper) self.assertIsInstance(thread.code, basestring) self.assertEqual(thread.code, talk.timestripper.site.code) self.assertIsInstance(thread.content, basestring) try: self.assertIsInstance(thread.timestamp, datetime) except AssertionError: if thread.code not in self.expected_failures: pywikibot.output('code %s: %s' % (thread.code, thread.content)) raise
def load_page(self, title: str): """Load the given page.""" page = pywikibot.Page(self.site, title) tmpl = pywikibot.Page(self.site, 'User:MiszaBot/config') archiver = archivebot.PageArchiver(page=page, template=tmpl, salt='') page = archivebot.DiscussionPage(page, archiver) page.load_page() self.page = page
def test_archivebot(self, code=None): """Test archivebot for one site.""" site = self.get_site(code) if code != 'de': # bug T69663 page = pywikibot.Page(site, 'user talk:xqt') else: page = pywikibot.Page(site, 'user talk:ladsgroup') talk = archivebot.DiscussionPage(page, None) self.assertIsInstance(talk.archives, dict) self.assertIsInstance(talk.archived_threads, int) self.assertTrue(talk.archiver is None) self.assertIsInstance(talk.header, basestring) self.assertIsInstance(talk.timestripper, TimeStripper) self.assertIsInstance(talk.threads, list) self.assertGreaterEqual( len(talk.threads), THREADS[code], '{} Threads found on {},\n{} or more expected'.format( len(talk.threads), talk, THREADS[code])) for thread in talk.threads: self.assertIsInstance(thread, archivebot.DiscussionThread) self.assertIsInstance(thread.title, basestring) self.assertIsInstance(thread.now, datetime) self.assertEqual(thread.now, talk.now) self.assertIsInstance(thread.ts, TimeStripper) self.assertEqual(thread.ts, talk.timestripper) self.assertIsInstance(thread.code, basestring) self.assertEqual(thread.code, talk.timestripper.site.code) self.assertIsInstance(thread.content, basestring) try: self.assertIsInstance(thread.timestamp, datetime) except AssertionError: if thread.code not in self.expected_failures: pywikibot.output('code {}: {}'.format( thread.code, thread.content)) raise