summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMichael Birtwell <michael.birtwell@starleaf.com>2016-10-12 16:13:50 +0100
committerMichael Birtwell <michael.birtwell@starleaf.com>2016-11-21 14:32:49 +0000
commit467bf955711e9224bb9f51a9620282d98e61f6c6 (patch)
tree8ba1d2f6e25169f52745ae38ef9ac061d44e38f0 /tests
parent15365e2cc99d0fe05b90aeb2fddec44c6ffef762 (diff)
downloadbabel-467bf955711e9224bb9f51a9620282d98e61f6c6.tar.gz
pofile parsing. Fix handling of obsolete + refactor
Fixes the handling of the unit before the obsolete unit. Previously it would mark the unit before an obsolete unit as obsolete also. Some refactoring: * the transition between finishing one unit and starting the next is clearer * separate the processing of keywords and continuation lines * combine the reset and initialisation code * Make the handling of strings consistent. * Add some nascent error handling, removed some errors in test inputs
Diffstat (limited to 'tests')
-rw-r--r--tests/messages/test_pofile.py67
1 files changed, 64 insertions, 3 deletions
diff --git a/tests/messages/test_pofile.py b/tests/messages/test_pofile.py
index d2a10dd..cdb90f5 100644
--- a/tests/messages/test_pofile.py
+++ b/tests/messages/test_pofile.py
@@ -79,7 +79,7 @@ msgstr ""''')
message.id)
def test_fuzzy_header(self):
- buf = StringIO(r'''\
+ buf = StringIO(r'''
# Translations template for AReallyReallyLongNameForAProject.
# Copyright (C) 2007 ORGANIZATION
# This file is distributed under the same license as the
@@ -93,7 +93,7 @@ msgstr ""''')
self.assertEqual(True, list(catalog)[0].fuzzy)
def test_not_fuzzy_header(self):
- buf = StringIO(r'''\
+ buf = StringIO(r'''
# Translations template for AReallyReallyLongNameForAProject.
# Copyright (C) 2007 ORGANIZATION
# This file is distributed under the same license as the
@@ -106,7 +106,7 @@ msgstr ""''')
self.assertEqual(False, list(catalog)[0].fuzzy)
def test_header_entry(self):
- buf = StringIO(r'''\
+ buf = StringIO(r'''
# SOME DESCRIPTIVE TITLE.
# Copyright (C) 2007 THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
@@ -216,6 +216,28 @@ msgstr "Bahr"
self.assertEqual(u'Bahr', message.string)
self.assertEqual(['This message is not obsolete'], message.user_comments)
+ def test_unit_before_obsolete_is_not_obsoleted(self):
+ buf = StringIO(r'''
+# This message is not obsolete
+#: main.py:1
+msgid "bar"
+msgstr "Bahr"
+
+# This is an obsolete message
+#~ msgid ""
+#~ "foo"
+#~ "fooooooo"
+#~ msgstr ""
+#~ "Voh"
+#~ "Vooooh"
+''')
+ catalog = pofile.read_po(buf)
+ self.assertEqual(1, len(catalog))
+ message = catalog[u'bar']
+ self.assertEqual(u'bar', message.id)
+ self.assertEqual(u'Bahr', message.string)
+ self.assertEqual(['This message is not obsolete'], message.user_comments)
+
def test_with_context(self):
buf = BytesIO(b'''# Some string in the menu
#: main.py:1
@@ -242,6 +264,29 @@ msgstr "Bahr"
assert out_buf.getvalue().strip() == buf.getvalue().strip(), \
out_buf.getvalue()
+ def test_obsolete_message_with_context(self):
+ buf = StringIO('''
+# This message is not obsolete
+msgid "baz"
+msgstr "Bazczch"
+
+# This is an obsolete message
+#~ msgctxt "other"
+#~ msgid "foo"
+#~ msgstr "Voh"
+
+# This message is not obsolete
+#: main.py:1
+msgid "bar"
+msgstr "Bahr"
+''')
+ catalog = pofile.read_po(buf)
+ self.assertEqual(2, len(catalog))
+ self.assertEqual(1, len(catalog.obsolete))
+ message = catalog.obsolete[u"foo"]
+ self.assertEqual(message.context, "other")
+ self.assertEqual(message.string, "Voh")
+
def test_with_context_two(self):
buf = BytesIO(b'''msgctxt "Menu"
msgid "foo"
@@ -308,6 +353,22 @@ msgstr[1] "Vohs [text]"''')
message = catalog['foo']
self.assertEqual(2, len(message.string))
+ def test_obsolete_plural_with_square_brackets(self):
+ buf = StringIO('''\
+#~ msgid "foo"
+#~ msgid_plural "foos"
+#~ msgstr[0] "Voh [text]"
+#~ msgstr[1] "Vohs [text]"
+''')
+ catalog = pofile.read_po(buf, locale='nb_NO')
+ self.assertEqual(0, len(catalog))
+ self.assertEqual(1, len(catalog.obsolete))
+ self.assertEqual(2, catalog.num_plurals)
+ message = catalog.obsolete[('foo', 'foos')]
+ self.assertEqual(2, len(message.string))
+ self.assertEqual("Voh [text]", message.string[0])
+ self.assertEqual("Vohs [text]", message.string[1])
+
class WritePoTestCase(unittest.TestCase):