jenkins-bot has submitted this change and it was merged.
Change subject: file_tests.py: Add tests for FilePage.latest_revision_info ......................................................................
file_tests.py: Add tests for FilePage.latest_revision_info
Added also missing docstrings and added to tox.ini.
Change-Id: I1bba341a1e884630d13a7c22f17a0d68adb54215 --- M tests/file_tests.py M tox.ini 2 files changed, 35 insertions(+), 0 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/tests/file_tests.py b/tests/file_tests.py index f8a7c14..8fa1de5 100644 --- a/tests/file_tests.py +++ b/tests/file_tests.py @@ -38,6 +38,7 @@ cached = True
def testSharedOnly(self): + """Test fileIsShared() on file page with shared file only.""" title = 'File:Sepp Maier 1.JPG'
commons = self.get_site('commons') @@ -59,6 +60,7 @@ self.assertRaises(pywikibot.NoPage, itwp_file.get)
def testLocalOnly(self): + """Test fileIsShared() on file page with local file only.""" title = 'File:April Fools Day Adminship discussion (2005).png'
commons = self.get_site('commons') @@ -80,6 +82,7 @@ self.assertRaises(pywikibot.NoPage, commons_file.get)
def testOnBoth(self): + """Test fileIsShared() on file page with both local and shared file.""" title = 'File:Pulsante spam.png'
commons = self.get_site('commons') @@ -114,6 +117,37 @@ commons_file.fileUrl())
+class TestFilePage(TestCase): + + """Test FilePage.latest_revision_info. + + These tests cover exceptions for all properties and methods + in FilePage that rely on site.loadimageinfo. + + """ + + family = 'wikipedia' + code = 'test' + + cached = True + + def test_file_info_with_no_page(self): + """FilePage:latest_file_info raises NoPage for non existing pages.""" + site = self.get_site() + image = pywikibot.FilePage(site, u'File:NoPage') + self.assertFalse(image.exists()) + with self.assertRaises(pywikibot.NoPage): + image = image.latest_file_info + + def test_file_info_with_no_file(self): + """FilePage:latest_file_info raises PagerelatedError if no file is present.""" + site = self.get_site() + image = pywikibot.FilePage(site, u'File:Test with no image') + self.assertTrue(image.exists()) + with self.assertRaises(pywikibot.PageRelatedError): + image = image.latest_file_info + + if __name__ == '__main__': try: unittest.main() diff --git a/tox.ini b/tox.ini index e2e1451..57d8873 100644 --- a/tox.ini +++ b/tox.ini @@ -100,6 +100,7 @@ tests/edit_failure_tests.py \ tests/exceptions_tests.py \ tests/family_tests.py \ + tests/file_tests.py \ tests/i18n/ \ tests/l10n_tests.py \ tests/pwb/ \