summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLasse Schuirmann <lasse@schuirmann.net>2015-12-30 16:08:12 +0100
committerLasse Schuirmann <lasse@schuirmann.net>2015-12-30 16:08:12 +0100
commitd545c4625ce447f862b76f667f173f86f55d2cf2 (patch)
treecde2a1944585cc3a4f474c99c5cb58f288f58d24
parent1ba3908a8fdc10d16f264f8fca5414fe57d3c6f6 (diff)
parentad11101f5e74abd0c6d9dc2d65ecd600b854da22 (diff)
downloadbabel-d545c4625ce447f862b76f667f173f86f55d2cf2.tar.gz
Merge pull request #301 from akx/suspect-filter
Flatten NullTranslations.files into a list
-rw-r--r--babel/support.py2
-rw-r--r--tests/test_support.py27
2 files changed, 27 insertions, 2 deletions
diff --git a/babel/support.py b/babel/support.py
index 3b4869c..e803138 100644
--- a/babel/support.py
+++ b/babel/support.py
@@ -298,7 +298,7 @@ class NullTranslations(gettext.NullTranslations, object):
self._catalog = {}
self.plural = lambda n: int(n != 1)
super(NullTranslations, self).__init__(fp=fp)
- self.files = filter(None, [getattr(fp, 'name', None)])
+ self.files = list(filter(None, [getattr(fp, 'name', None)]))
self.domain = self.DEFAULT_DOMAIN
self._domains = {}
diff --git a/tests/test_support.py b/tests/test_support.py
index 4647f6b..efdddeb 100644
--- a/tests/test_support.py
+++ b/tests/test_support.py
@@ -22,7 +22,7 @@ from datetime import date, datetime, timedelta
from babel import support
from babel.messages import Catalog
from babel.messages.mofile import write_mo
-from babel._compat import BytesIO
+from babel._compat import BytesIO, PY2
@pytest.mark.usefixtures("os_environ")
@@ -328,3 +328,28 @@ def test_lazy_proxy():
u"Hello, universe!",
u"Hello, world!",
]
+
+
+def test_catalog_merge_files():
+ # Refs issues #92, #162
+ t1 = support.Translations()
+ assert t1.files == []
+ t1._catalog["foo"] = "bar"
+ if PY2:
+ # Explicitly use the pure-Python `StringIO` class, as we need to
+ # augment it with the `name` attribute, which we can't do for
+ # `babel._compat.BytesIO`, which is `cStringIO.StringIO` under
+ # `PY2`...
+ from StringIO import StringIO
+ fp = StringIO()
+ else:
+ fp = BytesIO()
+ write_mo(fp, Catalog())
+ fp.seek(0)
+ fp.name = "pro.mo"
+ t2 = support.Translations(fp)
+ assert t2.files == ["pro.mo"]
+ t2._catalog["bar"] = "quux"
+ t1.merge(t2)
+ assert t1.files == ["pro.mo"]
+ assert set(t1._catalog.keys()) == set(('', 'foo', 'bar'))