Fix ISBN validation and complete unittests

This commit is contained in:
Lucas Verney 2016-01-24 18:21:52 +01:00
parent eb576f5fa6
commit bed4ffff69
2 changed files with 7 additions and 2 deletions

View File

@ -37,7 +37,11 @@ def is_valid(isbn):
>>> is_valid("123456789X")
True
"""
return not isbnlib.notisbn(isbn)
return (
(not isbnlib.notisbn(isbn)) and (
isbnlib.get_canonical_isbn(isbn) == isbn or
isbnlib.mask(isbnlib.get_canonical_isbn(isbn)) == isbn)
)
def extract_from_text(text):

View File

@ -82,7 +82,8 @@ def batch(iterable, size):
:params size: Size of the batches.
:returns: A new batch of the given size at each time.
# TODO: Unittest
>>> [list(i) for i in batch([1, 2, 3, 4, 5], 2)]
[[1, 2], [3, 4], [5]]
"""
it = iter(iterable)
while True: