jenkins-bot merged this change.
djvu.py: Fix parsing and page deletion checks
If only one page is present, _get_page_info() was swapping the key, id
pair:
- key, id = '', 1 needs to be swapped.
Checks after page deletion need to be fixed when file is left with one
page only:
- assertion needs to consider that key = ''
- number of pages before deletion n_tot is > 2 if files have more than
one page after deletion.
Bug: T195426
Change-Id: I319ad685a878b4e241a324ea7226a4ad44d119ad
---
M pywikibot/tools/djvu.py
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/pywikibot/tools/djvu.py b/pywikibot/tools/djvu.py
index 8ad7fba..7f4e66e 100644
--- a/pywikibot/tools/djvu.py
+++ b/pywikibot/tools/djvu.py
@@ -202,7 +202,9 @@
if m:
key, id = int(m.group('n')), m.group('id')
else:
- key, id = '', 1
+ # If djvu doc has only one page,
+ # FORM:DJVU line in djvudump has no id
+ key, id = 1, ''
if 'INFO' in line:
m = self._pat_info.search(line)
@@ -332,9 +334,14 @@
# Check if page processing is as expected.
# ref page info.
- assert self.page_info(new_ref_page, force=True) == info_ref_page
- if n_tot > 1:
- assert self.number_of_images() == n_tot - 1
+ if n_tot > 2:
+ assert self.number_of_images(force=True) == n_tot - 1
+ # cahce cleared above
+ assert self.page_info(new_ref_page) == info_ref_page
+ else:
+ # If djvu has only one page, FORM:DJVU line in djvudump has no id
+ _id, (sz, dpi) = info_ref_page
+ assert self.page_info(new_ref_page, force=True) == ('', (sz, dpi))
return True
To view, visit change 434822. To unsubscribe, visit settings.