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
parent
a1eee9682c
commit
ee76eb136a
|
@ -111,9 +111,9 @@ class ISBN(object):
|
||||||
else:
|
else:
|
||||||
return self.__isbn13
|
return self.__isbn13
|
||||||
def __unicode__(self):
|
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):
|
def __str__(self):
|
||||||
return self.to_string(type='13',hyphenate=False)
|
return self.to_string(type=self.type,hyphenate=False)
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
""" both equal if both valid checksums and ISBN 13 equal """
|
""" both equal if both valid checksums and ISBN 13 equal """
|
||||||
if isinstance(other, ISBN):
|
if isinstance(other, ISBN):
|
||||||
|
|
|
@ -347,7 +347,7 @@ class ISBNTest(TestCase):
|
||||||
self.assertEqual(isbn.ISBN(python_10).to_string(10,True), '0-672-32978-6')
|
self.assertEqual(isbn.ISBN(python_10).to_string(10,True), '0-672-32978-6')
|
||||||
|
|
||||||
# check casting to string -- ISBN 13
|
# 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
|
# test __eq__ and __ne__ and validate
|
||||||
self.assertTrue(isbn.ISBN(milosz_10) == isbn.ISBN(milosz_13))
|
self.assertTrue(isbn.ISBN(milosz_10) == isbn.ISBN(milosz_13))
|
||||||
|
@ -360,7 +360,8 @@ class ISBNTest(TestCase):
|
||||||
|
|
||||||
# curious about set membership
|
# curious about set membership
|
||||||
self.assertEqual(len(set([isbn.ISBN(milosz_10), isbn.ISBN(milosz_13)])),2)
|
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():
|
def suite():
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue