Example #1
0
 def test_previous_msgctxt_2(self):
     """
     Test previous msgctxt single line.
     """
     po = polib.pofile('tests/test_previous_msgid.po')
     expected = "Some message context"
     self.assertEqual(po[1].previous_msgctxt, expected)
Example #2
0
 def test_previous_msgctxt_1(self):
     """
     Test previous msgctxt multiline.
     """
     po = polib.pofile('tests/test_previous_msgid.po')
     expected = "\nSome message context"
     self.assertEqual(po[0].previous_msgctxt, expected)
Example #3
0
 def test_insert1(self):
     pofile = polib.pofile('tests/test_pofile_helpers.po')
     entry = polib.POEntry(msgid="Foo",
                           msgstr="Bar",
                           msgctxt="Some context")
     pofile.insert(0, entry)
     self.assertEqual(pofile[0], entry)
Example #4
0
 def test_previous_msgid_1(self):
     """
     Test previous msgid multiline.
     """
     po = polib.pofile('tests/test_previous_msgid.po')
     expected = "\nPartition table entries are not in disk order\n"
     self.assertEqual(po[0].previous_msgid, expected)
Example #5
0
 def test_previous_msgid_2(self):
     """
     Test previous msgid single line.
     """
     po = polib.pofile('tests/test_previous_msgid.po')
     expected = "Partition table entries are not in disk order2\n"
     self.assertEqual(po[1].previous_msgid, expected)
Example #6
0
 def test_ordered_metadata(self):
     pofile = polib.pofile('tests/test_fuzzy_header.po')
     f = open('tests/test_fuzzy_header.po')
     lines = f.readlines()[2:]
     f.close()
     mdata = [
         # ('Project-Id-Version', u('PACKAGE VERSION')),
         # ('Report-Msgid-Bugs-To', u('')),
         # ('POT-Creation-Date', u('2010-02-08 16:57+0100')),
         # ('PO-Revision-Date', u('YEAR-MO-DA HO:MI+ZONE')),
         # ('Last-Translator', u('FULL NAME <EMAIL@ADDRESS>')),
         # ('Language-Team', u('LANGUAGE <*****@*****.**>')),
         # ('MIME-Version', u('1.0')),
         # ('Content-Type', u('text/plain; charset=UTF-8')),
         # ('Content-Transfer-Encoding', u('8bit')),
         # ('X-Poedit-SearchPath-1', u('Foo')),
         # ('X-Poedit-SearchPath-2', u('Bar')),
         # ('X-Poedit-SearchPath-10', u('Baz')),
         ('Project-Id-Version', 'PACKAGE VERSION'),
         ('Report-Msgid-Bugs-To', ''),
         ('POT-Creation-Date', '2010-02-08 16:57+0100'),
         ('PO-Revision-Date', 'YEAR-MO-DA HO:MI+ZONE'),
         ('Last-Translator', 'FULL NAME <EMAIL@ADDRESS>'),
         ('Language-Team', 'LANGUAGE <*****@*****.**>'),
         ('MIME-Version', '1.0'),
         ('Content-Type', 'text/plain; charset=UTF-8'),
         ('Content-Transfer-Encoding', '8bit'),
         ('X-Poedit-SearchPath-1', 'Foo'),
         ('X-Poedit-SearchPath-2', 'Bar'),
         ('X-Poedit-SearchPath-10', 'Baz'),
     ]
     self.assertEqual(pofile.ordered_metadata(), mdata)
Example #7
0
 def test_save_as_mofile(self):
     """
     Test for the POFile.save_as_mofile() method.
     """
     import distutils.spawn
     msgfmt = distutils.spawn.find_executable('msgfmt')
     if msgfmt is None:
         try:
             return unittest.skip('msgfmt is not installed')
         except AttributeError:
             return
     reffiles = ['tests/test_utf8.po', 'tests/test_iso-8859-15.po']
     encodings = ['utf-8', 'iso-8859-15']
     for reffile, encoding in zip(reffiles, encodings):
         fd, tmpfile1 = tempfile.mkstemp()
         os.close(fd)
         fd, tmpfile2 = tempfile.mkstemp()
         os.close(fd)
         po = polib.pofile(reffile,
                           autodetect_encoding=False,
                           encoding=encoding)
         po.save_as_mofile(tmpfile1)
         subprocess.call([msgfmt, '--no-hash', '-o', tmpfile2, reffile])
         try:
             f = open(tmpfile1, 'rb')
             s1 = f.read()
             f.close()
             f = open(tmpfile2, 'rb')
             s2 = f.read()
             f.close()
             self.assertEqual(s1, s2)
         finally:
             os.remove(tmpfile1)
             os.remove(tmpfile2)
Example #8
0
 def test_metadata_as_entry(self):
     pofile = polib.pofile('tests/test_fuzzy_header.po')
     f = open('tests/test_fuzzy_header.po')
     lines = f.readlines()[2:]
     f.close()
     self.assertEqual(pofile.metadata_as_entry().__unicode__(),
                      "".join(lines))
Example #9
0
 def test_append1(self):
     pofile = polib.pofile('tests/test_pofile_helpers.po')
     entry = polib.POEntry(msgid="Foo",
                           msgstr="Bar",
                           msgctxt="Some context")
     pofile.append(entry)
     self.assertTrue(entry in pofile)
Example #10
0
 def test_order_comparison_of_plural_po_entries(self):
     po = polib.pofile('tests/test_plural_entries.po')
     self.assertTrue(po[0] == po[0])
     self.assertFalse(po[0] < po[0])
     self.assertFalse(po[0] > po[0])
     self.assertTrue(po[0] < po[1])
     self.assertTrue(po[1] > po[0])
Example #11
0
 def test_find5(self):
     pofile = polib.pofile('tests/test_msgctxt.po')
     entry1 = pofile.find('some string')
     entry2 = pofile.find('some string', msgctxt='Some message context')
     # self.assertEqual(entry1.msgstr, u('une cha\u00eene sans contexte'))
     self.assertEqual(entry1.msgstr, 'une cha\u00eene sans contexte')
     # self.assertEqual(entry2.msgstr, u('une cha\u00eene avec contexte'))
     self.assertEqual(entry2.msgstr, 'une cha\u00eene avec contexte')
Example #12
0
 def test_find4(self):
     pofile = polib.pofile('tests/test_utf8.po')
     entry1 = pofile.find('test context', msgctxt='@context1')
     entry2 = pofile.find('test context', msgctxt='@context2')
     # self.assertEqual(entry1.msgstr, u('test context 1'))
     self.assertEqual(entry1.msgstr, 'test context 1')
     # self.assertEqual(entry2.msgstr, u('test context 2'))
     self.assertEqual(entry2.msgstr, 'test context 2')
Example #13
0
 def test_pofile_and_mofile4(self):
     """
     Test that check_for_duplicates is passed to the instance.
     """
     po = polib.pofile('tests/test_iso-8859-15.po',
                       check_for_duplicates=True,
                       autodetect_encoding=False,
                       encoding='iso-8859-15')
     self.assertTrue(po.check_for_duplicates == True)
Example #14
0
 def test_str(self):
     pofile = polib.pofile('tests/test_iso-8859-15.po')
     # if polib.PY3:
     f = codecs.open('tests/test_iso-8859-15.po', encoding='iso-8859-15')
     # else:
     #     f = open('tests/test_iso-8859-15.po')
     expected = f.read()
     f.close()
     self.assertEqual(str(pofile), expected)
Example #15
0
    def test_trailing_comment(self):
        pofile = polib.pofile('tests/test_trailing_comment.po')
        expected = r'''#
msgid ""
msgstr "Content-Type: text/plain; charset=UTF-8\n"

msgid "foo"
msgstr "oof"
'''
        self.assertEqual(str(pofile), expected)
Example #16
0
    def test_pofile_with_subclass(self):
        """
        Test that the pofile function correctly returns an instance of the
        passed in class
        """
        class CustomPOFile(polib.POFile):
            pass

        pofile = polib.pofile('tests/test_indented.po', klass=CustomPOFile)
        self.assertEqual(pofile.__class__, CustomPOFile)
Example #17
0
    def test_unescaped_double_quote3(self):
        """
        Test that polib reports an error when unescaped double quote is found at the beginning of the string.
        """
        data = r'''
msgid "Some msgid with \"double\" quotes"
msgid ""Some msgstr with double\" quotes"
'''
        try:
            po = polib.pofile(data)
            self.fail("Unescaped quote not detected")
        except IOError:
            exc = sys.exc_info()[1]
            msg = 'Syntax error in po file (line 3): unescaped double quote found'
            self.assertEqual(str(exc), msg)
Example #18
0
    def test_pofile_and_mofile1(self):
        """
        Test bad usage of pofile/mofile.
        """
        data = '''# test for pofile/mofile with string buffer
msgid ""
msgstr ""
"Project-Id-Version: django\n"

msgid "foo"
msgstr "bar"
'''
        po = polib.pofile(data)
        self.assertTrue(isinstance(po, polib.POFile))
        self.assertEqual(po.encoding, 'utf-8')
        # self.assertEqual(po[0].msgstr, u("bar"))
        self.assertEqual(po[0].msgstr, "bar")
Example #19
0
    def test_wrapping(self):
        pofile = polib.pofile('tests/test_wrap.po', wrapwidth=50)
        expected = r'''# test wrapping
msgid ""
msgstr ""

msgid "This line will not be wrapped"
msgstr ""

msgid ""
"Some line that contain special characters \" and"
" that \t is very, very, very long...: %s \n"
msgstr ""

msgid ""
"Some line that contain special characters "
"\"foobar\" and that contains whitespace at the "
"end          "
msgstr ""
'''
        self.assertEqual(str(pofile), expected)
Example #20
0
 def test_pofile_and_mofile8(self):
     """
     Test that weird occurrences are correctly parsed.
     """
     po = polib.pofile('tests/test_weird_occurrences.po')
     self.assertEqual(len(po), 47)
Example #21
0
 def test_pofile_and_mofile9(self):
     """
     Test that obsolete previous msgid are ignored
     """
     po = polib.pofile('tests/test_obsolete_previousmsgid.po')
     self.assertTrue(isinstance(po, polib.POFile))
Example #22
0
 def test_pofile_and_mofile6(self):
     """
     Test that encoding is default_encoding when detect_encoding is False.
     """
     po = polib.pofile('tests/test_noencoding.po')
     self.assertTrue(po.encoding == 'utf-8')
Example #23
0
 def test_pofile_and_mofile7(self):
     """
     Test that encoding is ok when encoding is explicitly given.
     """
     po = polib.pofile('tests/test_iso-8859-15.po', encoding='iso-8859-15')
     self.assertTrue(po.encoding == 'iso-8859-15')
Example #24
0
 def test_pofile_and_mofile5(self):
     """
     Test that detect_encoding works as expected.
     """
     po = polib.pofile('tests/test_iso-8859-15.po')
     self.assertTrue(po.encoding == 'ISO_8859-15')
Example #25
0
 def test_word_garbage(self):
     po = polib.pofile('tests/test_word_garbage.po')
     e = po.find("Whatever", by='msgid')
     self.assertTrue(isinstance(e, polib.POEntry))
Example #26
0
 def test_comment_starting_with_two_hashes(self):
     po = polib.pofile('tests/test_utf8.po')
     e = po.find("Some comment starting with two '#'", by='tcomment')
     self.assertTrue(isinstance(e, polib.POEntry))
Example #27
0
 def test_unusual_metadata_location(self):
     po = polib.pofile('tests/test_unusual_metadata_location.po')
     self.assertNotEqual(po.metadata, {})
     self.assertEqual(po.metadata['Content-Type'],
                      'text/plain; charset=UTF-8')
Example #28
0
 def test_obsolete_entries(self):
     po = polib.pofile('tests/test_pofile_helpers.po')
     self.assertEqual(len(po.obsolete_entries()), 4)
Example #29
0
 def test_fuzzy_entries(self):
     po = polib.pofile('tests/test_pofile_helpers.po')
     self.assertEqual(len(po.fuzzy_entries()), 2)
Example #30
0
 def test_untranslated_entries(self):
     po = polib.pofile('tests/test_pofile_helpers.po')
     self.assertEqual(len(po.untranslated_entries()), 4)