Xqt has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1008442?usp=email )
Change subject: [cov] Update coverage ......................................................................
[cov] Update coverage
- split sjvu_test; few tests may run without installed library - ignore some lines from coverage
Change-Id: Ic7b09b757ff7c58fd4bc73ee696bf46b743db8bd --- M tests/__init__.py M tests/api_tests.py M tests/cache_tests.py M tests/date_tests.py M tests/djvu_tests.py 5 files changed, 66 insertions(+), 45 deletions(-)
Approvals: jenkins-bot: Verified Xqt: Looks good to me, approved
diff --git a/tests/__init__.py b/tests/__init__.py index d8078a6..b9d2308 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -302,7 +302,7 @@ if not super()._load_cache(): return False
- if 'lgpassword' in self._uniquedescriptionstr(): + if 'lgpassword' in self._uniquedescriptionstr(): # pragma: no cover self._data = None return False
diff --git a/tests/api_tests.py b/tests/api_tests.py index e07fed7..0c7f503 100755 --- a/tests/api_tests.py +++ b/tests/api_tests.py @@ -564,7 +564,7 @@ for count, pagedata in enumerate(gen, start=1): self.assertIsInstance(pagedata, dict) if 'missing' in pagedata: - self.assertNotIn('pageid', pagedata) + self.assertNotIn('pageid', pagedata) # pragma: no cover else: self.assertIn('pageid', pagedata) self.assertLength(links, count) @@ -587,7 +587,7 @@ for count, pagedata in enumerate(gen, start=1): self.assertIsInstance(pagedata, dict) if 'missing' in pagedata: - self.assertNotIn('pageid', pagedata) + self.assertNotIn('pageid', pagedata) # pragma: no cover else: self.assertIn('pageid', pagedata) self.assertLength(links, count) diff --git a/tests/cache_tests.py b/tests/cache_tests.py index 2d7ea8b..837c51e 100755 --- a/tests/cache_tests.py +++ b/tests/cache_tests.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 """API Request cache tests.""" # -# (C) Pywikibot team, 2012-2023 +# (C) Pywikibot team, 2012-2024 # # Distributed under the terms of the MIT license. # @@ -28,7 +28,7 @@ self.assertIsInstance(entry.site._loginstatus, int) self.assertNotIsInstance(entry.site._username, list) if entry.site._loginstatus >= LoginStatus.AS_USER: - self.assertIsNotNone(entry.site._username) + self.assertIsNotNone(entry.site._username) # pragma: no cover self.assertIsInstance(entry._params, dict) self.assertIsNotNone(entry._params) # TODO: more tests on entry._params, and possibly fixes needed diff --git a/tests/date_tests.py b/tests/date_tests.py index 5437c5c..b3dfa7e 100755 --- a/tests/date_tests.py +++ b/tests/date_tests.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 """Tests for the date module.""" # -# (C) Pywikibot team, 2012-2022 +# (C) Pywikibot team, 2012-2024 # # Distributed under the terms of the MIT license. # @@ -30,7 +30,7 @@ step = 10 try: predicate, start, stop = date.formatLimits[formatname] - except KeyError: + except KeyError: # pragma: no cover return
for code, convert in date.formats[formatname].items(): diff --git a/tests/djvu_tests.py b/tests/djvu_tests.py index 2031c10..1888b8d 100755 --- a/tests/djvu_tests.py +++ b/tests/djvu_tests.py @@ -1,8 +1,8 @@ #!/usr/bin/env python3 -"""Unit tests for djvu.py.""" +"""Unit tests for tools.djvu.py."""
# -# (C) Pywikibot team, 2015-2023 +# (C) Pywikibot team, 2015-2024 # # Distributed under the terms of the MIT license. # @@ -20,6 +20,7 @@
join_djvu_data_path = create_path_func(join_data_path, 'djvu') +file_djvu = join_djvu_data_path('myfilé.djvu') # test non-ASCII name
class TestDjVuFile(TestCase): @@ -28,63 +29,52 @@
net = False
- file_djvu_not_existing = join_djvu_data_path('not_existing.djvu') - file_djvu = join_djvu_data_path('myfilé.djvu') # test non-ASCII name file_djvu_wo_text = join_djvu_data_path('myfile_wo_text.djvu') test_txt = 'A file with non-ASCII characters, \nlike é or ç'
- def test_repr_method(self): - """Test __repr__() method.""" - djvu = DjVuFile(self.file_djvu) - expected = f"pywikibot.tools.djvu.DjVuFile('{self.file_djvu}')" - self.assertEqual(repr(djvu), expected) - - def test_str_method(self): - """Test __str__() method.""" - djvu = DjVuFile(self.file_djvu) - expected = f"DjVuFile('{self.file_djvu}')" - self.assertEqual(str(djvu), expected) - - def test_file_existence(self): - """Test file existence checks.""" - djvu = DjVuFile(self.file_djvu) - self.assertEqual(os.path.abspath(self.file_djvu), djvu.file) - with self.assertRaises(IOError): - DjVuFile(self.file_djvu_not_existing) + @classmethod + def setUpClass(cls): + """Skip if djvulibre library not installed.""" + super().setUpClass() + with skipping(OSError, msg='djvulibre library not installed.'): + dp = subprocess.Popen(['djvudump'], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + dp.communicate()
def test_number_of_images(self): """Test page number generator.""" - djvu = DjVuFile(self.file_djvu) + djvu = DjVuFile(file_djvu) self.assertEqual(djvu.number_of_images(), 4)
def test_page_info(self): """Test page info retrieval.""" - djvu = DjVuFile(self.file_djvu) + djvu = DjVuFile(file_djvu) self.assertEqual(djvu.page_info(1), ('{myfile.djvu}', ('1092x221', 600)))
def test_get_most_common_info(self): """Test that most common (size, dpi) are returned.""" - djvu = DjVuFile(self.file_djvu) + djvu = DjVuFile(file_djvu) self.assertEqual(djvu.get_most_common_info(), ('1092x221', 600))
def test_has_text(self): """Test if djvu file contains text.""" - djvu = DjVuFile(self.file_djvu) + djvu = DjVuFile(file_djvu) self.assertTrue(djvu.has_text()) djvu = DjVuFile(self.file_djvu_wo_text) self.assertFalse(djvu.has_text())
def test_get_existing_page_number(self): """Test text is returned for existing page number.""" - djvu = DjVuFile(self.file_djvu) + djvu = DjVuFile(file_djvu) self.assertTrue(djvu.has_text()) txt = djvu.get_page(1) self.assertEqual(txt, self.test_txt)
def test_get_not_existing_page_number(self): """Test error is raised if djvu page number is out of range.""" - djvu = DjVuFile(self.file_djvu) + djvu = DjVuFile(file_djvu) self.assertTrue(djvu.has_text()) with self.assertRaises(ValueError): djvu.get_page(100) @@ -98,32 +88,51 @@
def test_whiten_not_existing_page_number(self): """Test djvu page cannot be whitend if page number is out of range.""" - djvu = DjVuFile(self.file_djvu) + djvu = DjVuFile(file_djvu) with self.assertRaises(ValueError): djvu.whiten_page(100)
def test_delete_not_existing_page_number(self): """Test djvu page cannot be deleted if page number is out of range.""" - djvu = DjVuFile(self.file_djvu) + djvu = DjVuFile(file_djvu) with self.assertRaises(ValueError): djvu.delete_page(100)
def test_clear_cache(self): """Test if djvu file contains text.""" - djvu = DjVuFile(self.file_djvu) + djvu = DjVuFile(file_djvu) self.assertTrue(djvu.has_text()) djvu._has_text = False self.assertFalse(djvu.has_text()) self.assertTrue(djvu.has_text(force=True))
-def setUpModule(): - """Skip if djvulibre library not installed.""" - with skipping(OSError, msg='djvulibre library not installed.'): - dp = subprocess.Popen(['djvudump'], - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - dp.communicate() +class TestDjVuFileWithoutLib(TestCase): + + """Test DjVuFile class without library installed.""" + + net = False + + file_djvu_not_existing = join_djvu_data_path('not_existing.djvu') + + def test_file_existence(self): + """Test file existence checks.""" + djvu = DjVuFile(file_djvu) + self.assertEqual(os.path.abspath(file_djvu), djvu.file) + with self.assertRaises(IOError): + DjVuFile(self.file_djvu_not_existing) + + def test_str_method(self): + """Test __str__() method.""" + djvu = DjVuFile(file_djvu) + expected = f"DjVuFile('{file_djvu}')" + self.assertEqual(str(djvu), expected) + + def test_repr_method(self): + """Test __repr__() method.""" + djvu = DjVuFile(file_djvu) + expected = f"pywikibot.tools.djvu.DjVuFile('{file_djvu}')" + self.assertEqual(repr(djvu), expected)
if __name__ == '__main__':
pywikibot-commits@lists.wikimedia.org