def test_not_skipped(self): """Exercise skip_page() with a page we should accept.""" bot = AddTextBot() page = _mock_page() self.assertFalse(bot.skip_page(page)) self.assertEqual([], pywikibot.bot.ui.pop_output())
def test_skip_missing_talk(self): """Exercise skip_page() with a talk page that doesn't exist.""" bot = AddTextBot() page = _mock_page(exists=False, talk=True) self.assertFalse(bot.skip_page(page)) self.assertEqual(["mock_page doesn't exist, creating it!"], pywikibot.bot.ui.pop_output())
def test_skip_missing_standard(self): """Exercise skip_page() with a non-talk page that doesn't exist.""" bot = AddTextBot() page = _mock_page(exists=False) self.assertTrue(bot.skip_page(page)) self.assertEqual(['Page mock_page does not exist on mock_site.'], pywikibot.bot.ui.pop_output())
def test_skip_if_redirect(self): """Exercise skip_page() with a page that is a redirect.""" bot = AddTextBot() page = _mock_page(redirect=True) self.assertTrue(bot.skip_page(page)) self.assertEqual([ 'Page mock_page on mock_site is skipped because it is a redirect' ], pywikibot.bot.ui.pop_output())
def test_setup_with_text(self): """Exercise bot with a -text argument.""" bot = AddTextBot(text='hello\\nworld') # setup unescapes any newlines self.assertEqual('hello\\nworld', bot.opt.text) bot.setup() self.assertEqual('hello\nworld', bot.opt.text)
def test_skip_missing_standard_with_create(self): """Exercise skip_page() with -create option for a non-talk page.""" bot = AddTextBot(create=True) for exists in (True, False): with self.subTest(exists=exists): page = _mock_page(exists=exists) self.assertFalse(bot.skip_page(page)) self.assertIsEmpty(pywikibot.bot.ui.pop_output())
def test_setup_with_textfile(self, mock_file): """Exercise both with a -textfile argument.""" bot = AddTextBot(textfile='/path/to/my/file.txt') # setup reads the file content self.assertEqual('', bot.opt.text) bot.setup() self.assertEqual('file data', bot.opt.text) mock_file.assert_called_with('/path/to/my/file.txt', 'rb', ANY)
def test_skip_if_url_match(self): """Exercise skip_page() with a '-excepturl' argument.""" bot = AddTextBot(regex_skip_url='.*\\.com') page = _mock_page(url='wikipedia.org') self.assertFalse(bot.skip_page(page)) self.assertEqual([], pywikibot.bot.ui.pop_output()) page = _mock_page(url='wikipedia.com') self.assertTrue(bot.skip_page(page)) self.assertEqual([ "Skipping mock_page because -excepturl matches ['wikipedia.com']." ], pywikibot.bot.ui.pop_output())