Page MenuHomePhabricator

isbn tests fail with stdnum 0.6
Closed, ResolvedPublic

Description

stdnum 0.6 is packaged with Ubuntu precise

_______________ TestCosmeticChangesISBN.test_ignore_invalid_isbn _______________
self = <tests.isbn_tests.TestCosmeticChangesISBN testMethod=test_ignore_invalid_isbn>
    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 ')
tests/isbn_tests.py:75: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
pywikibot/cosmetic_changes.py:996: in fix_ISBN
    text, strict=False if self.ignore == CANCEL_MATCH else True)
pywikibot/cosmetic_changes.py:195: in _reformat_ISBNs
    text, lambda match: _format_isbn_match(match, strict=strict))
pywikibot/textlib.py:1712: in reformat_ISBNs
    text = isbnR.sub(match_func, text)
pywikibot/cosmetic_changes.py:195: in <lambda>
    text, lambda match: _format_isbn_match(match, strict=strict))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
match = <_sre.SRE_Match object at 0xa658a08>, strict = False
    def _format_isbn_match(match, strict=True):
        """Helper function to validate and format a single matched ISBN."""
        scripts_isbn = None
    
        if not stdnum_isbn:
            # For backwards compatibility, if stdnum.isbn is not available
            # attempt loading scripts.isbn as an alternative implementation.
            try:
                import scripts.isbn as scripts_isbn
            except ImportError:
                raise NotImplementedError(
                    'ISBN functionality not available.  Install stdnum package.')
    
            warn('package stdnum.isbn not found; using scripts.isbn',
                 ImportWarning)
    
        isbn = match.group('code')
        if stdnum_isbn:
            try:
                stdnum_isbn.validate(isbn)
>           except stdnum_isbn.ValidationError as e:
E           AttributeError: 'module' object has no attribute 'ValidationError'
pywikibot/cosmetic_changes.py:163: AttributeError
__________________ TestCosmeticChangesISBN.test_invalid_isbn ___________________
self = <tests.isbn_tests.TestCosmeticChangesISBN testMethod=test_invalid_isbn>
    def test_invalid_isbn(self):
        """Test that it'll fail when the ISBN is invalid."""
        cc = CosmeticChangesToolkit(self.site, namespace=0)
    
        # Invalid characters
        self.assertRaises(AnyIsbnValidationException,
>                         cc.fix_ISBN, 'ISBN 0975229LOL')
tests/isbn_tests.py:60: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
pywikibot/cosmetic_changes.py:996: in fix_ISBN
    text, strict=False if self.ignore == CANCEL_MATCH else True)
pywikibot/cosmetic_changes.py:195: in _reformat_ISBNs
    text, lambda match: _format_isbn_match(match, strict=strict))
pywikibot/textlib.py:1712: in reformat_ISBNs
    text = isbnR.sub(match_func, text)
pywikibot/cosmetic_changes.py:195: in <lambda>
    text, lambda match: _format_isbn_match(match, strict=strict))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
match = <_sre.SRE_Match object at 0xa83e4e0>, strict = True
    def _format_isbn_match(match, strict=True):
        """Helper function to validate and format a single matched ISBN."""
        scripts_isbn = None
    
        if not stdnum_isbn:
            # For backwards compatibility, if stdnum.isbn is not available
            # attempt loading scripts.isbn as an alternative implementation.
            try:
                import scripts.isbn as scripts_isbn
            except ImportError:
                raise NotImplementedError(
                    'ISBN functionality not available.  Install stdnum package.')
    
            warn('package stdnum.isbn not found; using scripts.isbn',
                 ImportWarning)
    
        isbn = match.group('code')
        if stdnum_isbn:
            try:
                stdnum_isbn.validate(isbn)
>           except stdnum_isbn.ValidationError as e:
E           AttributeError: 'module' object has no attribute 'ValidationError'
pywikibot/cosmetic_changes.py:163: AttributeError
___________________ TestCosmeticChangesISBN.test_valid_isbn ____________________
self = <tests.isbn_tests.TestCosmeticChangesISBN testMethod=test_valid_isbn>
    def test_valid_isbn(self):
        """Test ISBN."""
        cc = CosmeticChangesToolkit(self.site, namespace=0)
    
>       text = cc.fix_ISBN(' ISBN 097522980x ')
tests/isbn_tests.py:48: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
pywikibot/cosmetic_changes.py:996: in fix_ISBN
    text, strict=False if self.ignore == CANCEL_MATCH else True)
pywikibot/cosmetic_changes.py:195: in _reformat_ISBNs
    text, lambda match: _format_isbn_match(match, strict=strict))
pywikibot/textlib.py:1712: in reformat_ISBNs
    text = isbnR.sub(match_func, text)
pywikibot/cosmetic_changes.py:195: in <lambda>
    text, lambda match: _format_isbn_match(match, strict=strict))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
match = <_sre.SRE_Match object at 0xa83e6c0>, strict = True
    def _format_isbn_match(match, strict=True):
        """Helper function to validate and format a single matched ISBN."""
        scripts_isbn = None
    
        if not stdnum_isbn:
            # For backwards compatibility, if stdnum.isbn is not available
            # attempt loading scripts.isbn as an alternative implementation.
            try:
                import scripts.isbn as scripts_isbn
            except ImportError:
                raise NotImplementedError(
                    'ISBN functionality not available.  Install stdnum package.')
    
            warn('package stdnum.isbn not found; using scripts.isbn',
                 ImportWarning)
    
        isbn = match.group('code')
        if stdnum_isbn:
            try:
                stdnum_isbn.validate(isbn)
>           except stdnum_isbn.ValidationError as e:
E           AttributeError: 'module' object has no attribute 'ValidationError'
pywikibot/cosmetic_changes.py:163: AttributeError
____________________________ TestIsbn.test_general _____________________________
self = <tests.isbn_tests.TestIsbn testMethod=test_general>
    def test_general(self):
        """Test things that apply both to ISBN10 and ISBN13."""
        # getIsbn
        self.assertIsInstance(getIsbn('097522980x'), ISBN10)
        self.assertIsInstance(getIsbn('9783161484100'), ISBN13)
        self.assertRaisesRegex(IsbnExc,
                               'ISBN-13: The ISBN 097522 is not 13 digits '
                               'long. / ISBN-10: The ISBN 097522 is not 10 '
                               'digits long.', getIsbn, '097522')
    
        # hyphenateIsbnNumbers
>       self.assertEqual(hyphenateIsbnNumbers('ISBN 097522980x'),
                         'ISBN 0-9752298-0-X')
tests/isbn_tests.py:131: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
pywikibot/textlib.py:1712: in reformat_ISBNs
    text = isbnR.sub(match_func, text)
scripts/isbn.py:1396: in _hyphenateIsbnNumber
    is_valid(isbn)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
isbn = '097522980X'
    def is_valid(isbn):
        """Check whether an ISBN 10 or 13 is valid."""
        # isbnlib marks any ISBN10 with lowercase 'X' as invalid
        isbn = isbn.upper()
        try:
            stdnum.isbn
        except NameError:
            pass
        else:
            try:
                stdnum.isbn.validate(isbn)
>           except stdnum.isbn.InvalidFormat as e:
E           AttributeError: 'module' object has no attribute 'InvalidFormat'
scripts/isbn.py:1370: AttributeError
________________________ TestIsbnWikibaseBot.test_isbn _________________________
self = <tests.isbn_tests.TestIsbnWikibaseBot testMethod=test_isbn>
    def test_isbn(self):
        """Test using the bot and wikibase."""
        main('-page:' + self.test_page_qid, '-always', '-format')
>       self.assertEqual(self.setTarget_value, '0-9752298-0-X')
E       AttributeError: 'TestIsbnWikibaseBot' object has no attribute 'setTarget_value'
tests/isbn_tests.py:241: AttributeError

https://travis-ci.org/jayvdb/pywikibot-core/jobs/134670315

Event Timeline

stdnum exceptions.py was added in 0.8, and hasnt been modified since then.
And since that release, isbn.py has always contained from stdnum.exceptions import *

@jayvdb: I assume this is about Pywikibot? Please add a project. Thanks. :)

@jayvdb: I assume this is about Pywikibot? Please add a project. Thanks. :)

sorry, and thank you! I was wondering why it wasnt showing up on IRC; I was subconsciously annoyed and blaming the irc bot for being down so often ..

validate() was also added only in 0.8, but earlier versions have is_valid() which goes back to 0.2 (and before that it was called validate)

Change 292338 had a related patch set uploaded (by John Vandenberg):
Add apt packages

https://gerrit.wikimedia.org/r/292338

Xqt triaged this task as High priority.Oct 30 2016, 11:47 AM

Change 292338 abandoned by Xqt:
Add apt packages

Reason:
T136807 is closed. For T136808 we should use a better library

https://gerrit.wikimedia.org/r/292338

Dvorapa reassigned this task from jayvdb to Xqt.
Dvorapa lowered the priority of this task from High to Medium.
Dvorapa moved this task from Needs Review to Backlog on the Pywikibot board.
Dvorapa subscribed.