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') self.assertEqual(hyphenateIsbnNumbers('ISBN 0975229801'), 'ISBN 0975229801') # Invalid ISBN - no changes # convertIsbn10toIsbn13 self.assertEqual(convertIsbn10toIsbn13('ISBN 0-9752298-0-X'), 'ISBN 978-0-9752298-0-4') self.assertEqual(convertIsbn10toIsbn13('ISBN 0-9752298-0-1'), 'ISBN 0-9752298-0-1') # Invalid ISBN - no changes # Errors isbn = ISBN10('9492098059') self.assertRaisesRegex(IsbnExc, 'ISBN 9492098059: group number unknown.', isbn.format) isbn = ISBN10('9095012042') self.assertRaisesRegex(IsbnExc, 'ISBN 9095012042: publisher number unknown.', isbn.format)
def test_isbn10(self): """Test ISBN10.""" # Test general features isbn = ISBN10('097522980x') isbn.format() self.assertEqual(isbn.code, '0-9752298-0-X') self.assertEqual(isbn.digits(), ['0', '9', '7', '5', '2', '2', '9', '8', '0', 'X']) # Converting to ISBN13 isbn13 = isbn.toISBN13() self.assertEqual(isbn13.code, '978-0-9752298-0-4') # Errors self.assertRaises(IsbnExc, ISBN10, '0975229LOL') # Invalid characters self.assertRaises(IsbnExc, ISBN10, '0975229801') # Invalid checksum self.assertRaises(IsbnExc, ISBN10, '09752298') # Invalid length self.assertRaises(IsbnExc, ISBN10, '09752X9801') # X in the middle