jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/750796 )
Change subject: [isbn] Update isbn dependency ......................................................................
[isbn] Update isbn dependency
- require python-stdnum >= 1.17 - recover TestCosmeticChangesISBN test
Change-Id: I67948949edfec1829794bc1be3383bd2e9786d6d --- M requirements.txt M setup.py M tests/archive/isbn_tests.py M tests/cosmetic_changes_tests.py 4 files changed, 83 insertions(+), 77 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/requirements.txt b/requirements.txt index e74de65..ebe1371 100644 --- a/requirements.txt +++ b/requirements.txt @@ -40,7 +40,7 @@ pydot >= 1.2
# cosmetic_changes -python-stdnum >= 1.16 +python-stdnum >= 1.17
# GUI Pillow >= 8.1.1 ; python_version >= '3.6' diff --git a/setup.py b/setup.py index 840534a..c79a832 100644 --- a/setup.py +++ b/setup.py @@ -27,7 +27,7 @@ - upload this patchset to Gerrit and merge it. """ # -# (C) Pywikibot team, 2009-2021 +# (C) Pywikibot team, 2009-2022 # # Distributed under the terms of the MIT license. # @@ -62,7 +62,7 @@ extra_deps = { # Core library dependencies 'eventstreams': ['sseclient!=0.0.23,!=0.0.24,>=0.0.18'], - 'isbn': ['python-stdnum>=1.16'], + 'isbn': ['python-stdnum>=1.17'], 'Graphviz': ['pydot>=1.2'], 'Google': ['google>=1.7'], 'mwparserfromhell': ['mwparserfromhell>=0.5.0'], diff --git a/tests/archive/isbn_tests.py b/tests/archive/isbn_tests.py index b159370..8e9eda7 100644 --- a/tests/archive/isbn_tests.py +++ b/tests/archive/isbn_tests.py @@ -1,22 +1,22 @@ """Tests for isbn script.""" # -# (C) Pywikibot team, 2014-2021 +# (C) Pywikibot team, 2014-2022 # # Distributed under the terms of the MIT license. # import pywikibot from pywikibot import Bot, Claim, ItemPage -from pywikibot.cosmetic_changes import CANCEL_MATCH, CosmeticChangesToolkit from pywikibot.tools import has_module + from scripts.isbn import InvalidIsbnException as IsbnExc from scripts.isbn import convertIsbn10toIsbn13, hyphenateIsbnNumbers, main from tests.aspects import ( - DefaultDrySiteTestCase, ScriptMainTestCase, TestCase, WikibaseTestCase, unittest, ) + from tests.bot_tests import TWNBotTestCase from tests.utils import empty_sites
@@ -33,76 +33,6 @@ AnyIsbnValidationException = IsbnExc
-class TestCosmeticChangesISBN(DefaultDrySiteTestCase): - - """Test CosmeticChanges ISBN fix.""" - - ISBN_DIGITERROR_RE = 'ISBN [0-9]+ is not [0-9]+ digits long' - ISBN_INVALIDERROR_RE = 'Invalid ISBN found' - ISBN_CHECKSUMERROR_RE = 'ISBN checksum of [0-9]+ is incorrect' - ISBN_INVALIDCHECKERROR_RE = 'checksum or check digit is invalid' - ISBN_INVALIDCHARERROR_RE = 'ISBN [0-9a-zA-Z]+ contains invalid characters' - ISBN_INVALIDLENGTHERROR_RE = 'The number has an invalid length' - - def test_valid_isbn(self): - """Test ISBN.""" - cc = CosmeticChangesToolkit(self.site, namespace=0) - - text = cc.fix_ISBN(' ISBN 097522980x ') - self.assertEqual(text, ' ISBN 0-9752298-0-X ') - - text = cc.fix_ISBN(' ISBN 9780975229804 ') - self.assertEqual(text, ' ISBN 978-0-9752298-0-4 ') - - text = cc.fix_ISBN(' ISBN 9783955390631 ') - self.assertEqual(text, ' ISBN 978-3-95539-063-1 ') - - text = cc.fix_ISBN(' ISBN 9791091447034 ') - self.assertEqual(text, ' ISBN 979-10-91447-03-4 ') - - def test_invalid_isbn(self): - """Test that it'll fail when the ISBN is invalid.""" - cc = CosmeticChangesToolkit(self.site, namespace=0) - - # Invalid characters - with self.assertRaisesRegex( - AnyIsbnValidationException, - '|'.join((self.ISBN_DIGITERROR_RE, - self.ISBN_INVALIDERROR_RE, - self.ISBN_INVALIDLENGTHERROR_RE))): - cc.fix_ISBN('ISBN 0975229LOL') - # Invalid checksum - with self.assertRaisesRegex( - AnyIsbnValidationException, - '|'.join((self.ISBN_CHECKSUMERROR_RE, - self.ISBN_INVALIDERROR_RE, - self.ISBN_INVALIDLENGTHERROR_RE, - self.ISBN_INVALIDCHECKERROR_RE))): - cc.fix_ISBN('ISBN 0975229801') - # Invalid length - with self.assertRaisesRegex( - AnyIsbnValidationException, - '|'.join((self.ISBN_DIGITERROR_RE, - self.ISBN_INVALIDERROR_RE, - self.ISBN_INVALIDLENGTHERROR_RE))): - cc.fix_ISBN('ISBN 09752298') - # X in the middle - with self.assertRaisesRegex( - AnyIsbnValidationException, - '|'.join((self.ISBN_INVALIDCHARERROR_RE, - self.ISBN_INVALIDERROR_RE, - self.ISBN_INVALIDLENGTHERROR_RE))): - cc.fix_ISBN('ISBN 09752X9801') - - def test_ignore_invalid_isbn(self): - """Test fixing ISBN numbers with an invalid ISBN.""" - cc = CosmeticChangesToolkit(self.site, namespace=0, - ignore=CANCEL_MATCH) - - text = cc.fix_ISBN(' ISBN 0975229LOL ISBN 9780975229804 ') - self.assertEqual(text, ' ISBN 0975229LOL ISBN 978-0-9752298-0-4 ') - - class TestIsbn(TestCase):
"""Test ISBN-related classes and helper functions.""" diff --git a/tests/cosmetic_changes_tests.py b/tests/cosmetic_changes_tests.py index b0f8fed..34ffcb4 100644 --- a/tests/cosmetic_changes_tests.py +++ b/tests/cosmetic_changes_tests.py @@ -8,7 +8,9 @@ from contextlib import suppress
from pywikibot import Page -from pywikibot.cosmetic_changes import CosmeticChangesToolkit +from pywikibot.cosmetic_changes import CANCEL, CosmeticChangesToolkit +from pywikibot.tools import has_module + from pywikibot.site._namespace import NamespacesDict
from tests.aspects import TestCase @@ -545,6 +547,80 @@ # Once numbering fixes are enabled we can add tests.
+class TestCosmeticChangesISBN(TestCosmeticChanges): + + """Test CosmeticChanges ISBN fix.""" + + dry = True + + ISBN_DIGITERROR_RE = 'ISBN [0-9]+ is not [0-9]+ digits long' + ISBN_INVALIDERROR_RE = 'Invalid ISBN found' + ISBN_CHECKSUMERROR_RE = 'ISBN checksum of [0-9]+ is incorrect' + ISBN_INVALIDCHECKERROR_RE = 'checksum or check digit is invalid' + ISBN_INVALIDCHARERROR_RE = 'ISBN [0-9a-zA-Z]+ contains invalid characters' + ISBN_INVALIDLENGTHERROR_RE = 'The number has an invalid length' + + @classmethod + def setUpClass(cls): # noqa: N802 + """Skip tests if isbn libraries are missing.""" + if not has_module('stdnum', version='1.17'): + raise unittest.SkipTest('python-stdnum is not available.') + super().setUpClass() + + def test_valid_isbn(self): + """Test ISBN.""" + text = self.cct.fix_ISBN(' ISBN 097522980x ') + self.assertEqual(text, ' ISBN 0-9752298-0-X ') + + text = self.cct.fix_ISBN(' ISBN 9780975229804 ') + self.assertEqual(text, ' ISBN 978-0-9752298-0-4 ') + + text = self.cct.fix_ISBN(' ISBN 9783955390631 ') + self.assertEqual(text, ' ISBN 978-3-95539-063-1 ') + + text = self.cct.fix_ISBN(' ISBN 9791091447034 ') + self.assertEqual(text, ' ISBN 979-10-91447-03-4 ') + + def test_invalid_isbn(self): + """Test that it'll fail when the ISBN is invalid.""" + from stdnum.exceptions import ValidationError + # Invalid characters + with self.assertRaisesRegex( + ValidationError, + '|'.join((self.ISBN_DIGITERROR_RE, + self.ISBN_INVALIDERROR_RE, + self.ISBN_INVALIDLENGTHERROR_RE))): + self.cct.fix_ISBN('ISBN 0975229LOL') + # Invalid checksum + with self.assertRaisesRegex( + ValidationError, + '|'.join((self.ISBN_CHECKSUMERROR_RE, + self.ISBN_INVALIDERROR_RE, + self.ISBN_INVALIDLENGTHERROR_RE, + self.ISBN_INVALIDCHECKERROR_RE))): + self.cct.fix_ISBN('ISBN 0975229801') + # Invalid length + with self.assertRaisesRegex( + ValidationError, + '|'.join((self.ISBN_DIGITERROR_RE, + self.ISBN_INVALIDERROR_RE, + self.ISBN_INVALIDLENGTHERROR_RE))): + self.cct.fix_ISBN('ISBN 09752298') + # X in the middle + with self.assertRaisesRegex( + ValidationError, + '|'.join((self.ISBN_INVALIDCHARERROR_RE, + self.ISBN_INVALIDERROR_RE, + self.ISBN_INVALIDLENGTHERROR_RE))): + self.cct.fix_ISBN('ISBN 09752X9801') + + def test_ignore_invalid_isbn(self): + """Test fixing ISBN numbers with an invalid ISBN.""" + self.cct.ignore = CANCEL.MATCH + text = self.cct.fix_ISBN(' ISBN 0975229LOL ISBN 9780975229804 ') + self.assertEqual(text, ' ISBN 0975229LOL ISBN 978-0-9752298-0-4 ') + + if __name__ == '__main__': # pragma: no cover with suppress(SystemExit): unittest.main()
pywikibot-commits@lists.wikimedia.org