* handle irregular multi-line msgstr (no "" as first line) gracefully (#171)
* parse_decimal() now returns Decimals not floats, API change (#178)
* no warnings when running setup.py without installed setuptools (#262)
+ * modified Locale.__eq__ method so Locales are only equal if all of their
+ attributes (language, territory, script, variant) are equal
Version 0.9.6
return identifier
def __eq__(self, other):
- return str(self) == str(other)
+ for key in ('language', 'territory', 'script', 'variant'):
+ if not hasattr(other, key):
+ return False
+ return (self.language == other.language) and \
+ (self.territory == other.territory) and \
+ (self.script == other.script) and \
+ (self.variant == other.variant)
def __ne__(self, other):
return not self.__eq__(other)
from StringIO import StringIO
import unittest
+from babel.core import Locale
from babel.messages.catalog import Catalog, Message
from babel.messages import pofile
from babel.util import FixedOffsetTimezone
buf = StringIO(r'''msgid "foo"
msgstr "Voh"''')
catalog = pofile.read_po(buf, locale='en_US')
- self.assertEqual('en_US', catalog.locale)
+ self.assertEqual(Locale('en', 'US'), catalog.locale)
def test_preserve_domain(self):
buf = StringIO(r'''msgid "foo"
repr(Locale('de', 'DE')))
self.assertEqual("Locale('zh', territory='CN', script='Hans')",
repr(Locale('zh', 'CN', script='Hans')))
+
+ def test_locale_comparison(self):
+ en_US = Locale('en', 'US')
+ self.assertEqual(en_US, en_US)
+ self.assertNotEqual(None, en_US)
+
+ bad_en_US = Locale('en_US')
+ self.assertNotEqual(en_US, bad_en_US)
class DefaultLocaleTest(unittest.TestCase):