]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
change Locale comparison: Locales are now considered equal if all of their attributes...
authorFelix Schwarz <felix.schwarz@oss.schwarz.eu>
Thu, 9 Aug 2012 07:36:36 +0000 (07:36 +0000)
committerFelix Schwarz <felix.schwarz@oss.schwarz.eu>
Thu, 9 Aug 2012 07:36:36 +0000 (07:36 +0000)
ChangeLog
babel/core.py
babel/messages/tests/pofile.py
babel/tests/core.py

index f6637851f8166283a60ea9aa02a9dccf33fb3ce9..299dd921875bfb9bd53a039a731839d440a8ba8b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -47,6 +47,8 @@ http://svn.edgewall.org/repos/babel/tags/1.0.0/
  * 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
index 083f05805d54e83ab1206055cafc666ed65525be..c9608f7150b32ded4a52fe608d74a33c56519d36 100644 (file)
@@ -214,7 +214,13 @@ class Locale(object):
         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)
index bb3f54872ea44220de2915df666eceb08a1d2a5a..7e5904f1fde52b9f520cceb00e0d6d3585b0cb48 100644 (file)
@@ -16,6 +16,7 @@ import doctest
 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
@@ -27,7 +28,7 @@ class ReadPoTestCase(unittest.TestCase):
         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"
index 1e7588208a182a7d21c4c3db8fadae8137e1dfb4..03083787117eca4ea49d829c3c06d352dd302a72 100644 (file)
@@ -31,6 +31,14 @@ class LocaleTest(unittest.TestCase):
                          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):