Changed the behavior of __str__ and __unicode__ of ISBN to spit back a representation matching the type of the ISBN -- and not automatically push to ISBN 13 format

pull/1/head
Raymond Yee 2011-11-18 10:21:29 -08:00
parent a1eee9682c
commit ee76eb136a
2 changed files with 5 additions and 4 deletions

View File

@ -111,9 +111,9 @@ class ISBN(object):
else:
return self.__isbn13
def __unicode__(self):
return unicode(self.to_string(type='13',hyphenate=False))
return unicode(self.to_string(type=self.type,hyphenate=False))
def __str__(self):
return self.to_string(type='13',hyphenate=False)
return self.to_string(type=self.type,hyphenate=False)
def __eq__(self, other):
""" both equal if both valid checksums and ISBN 13 equal """
if isinstance(other, ISBN):

View File

@ -347,7 +347,7 @@ class ISBNTest(TestCase):
self.assertEqual(isbn.ISBN(python_10).to_string(10,True), '0-672-32978-6')
# check casting to string -- ISBN 13
self.assertEqual(str(isbn.ISBN(python_10)), '9780672329784')
self.assertEqual(str(isbn.ISBN(python_10)), '0672329786')
# test __eq__ and __ne__ and validate
self.assertTrue(isbn.ISBN(milosz_10) == isbn.ISBN(milosz_13))
@ -360,7 +360,8 @@ class ISBNTest(TestCase):
# curious about set membership
self.assertEqual(len(set([isbn.ISBN(milosz_10), isbn.ISBN(milosz_13)])),2)
self.assertEqual(len(set([str(isbn.ISBN(milosz_10)), str(isbn.ISBN(milosz_13))])),1)
self.assertEqual(len(set([str(isbn.ISBN(milosz_10)), str(isbn.ISBN(milosz_13))])),2)
self.assertEqual(len(set([isbn.ISBN(milosz_10).to_string(), isbn.ISBN(milosz_13).to_string()])),1)
def suite():