From bed4ffff6950115f6ca8a5f87bab289d0ef84774 Mon Sep 17 00:00:00 2001 From: "Phyks (Lucas Verney)" Date: Sun, 24 Jan 2016 18:21:52 +0100 Subject: [PATCH] Fix ISBN validation and complete unittests --- libbmc/isbn.py | 6 +++++- libbmc/tools.py | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/libbmc/isbn.py b/libbmc/isbn.py index a6f3faa..5c5904a 100644 --- a/libbmc/isbn.py +++ b/libbmc/isbn.py @@ -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): diff --git a/libbmc/tools.py b/libbmc/tools.py index 3e6e9ed..b278700 100644 --- a/libbmc/tools.py +++ b/libbmc/tools.py @@ -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: