コード例 #1
0
    def test_mofile_with_subclass(self):
        """
        Test that the mofile function correctly returns an instance of the
        passed in class
        """
        class CustomMOFile(polib.MOFile):
            pass

        mofile = polib.mofile('tests/test_utf8.mo', klass=CustomMOFile)
        self.assertEqual(mofile.__class__, CustomMOFile)
コード例 #2
0
    def test_no_header(self):
        mo = polib.mofile('tests/test_no_header.mo')
        expected = '''msgid ""
msgstr ""

msgid "bar"
msgstr "rab"

msgid "foo"
msgstr "oof"
'''
        self.assertEqual(mo.__unicode__(), expected)
コード例 #3
0
    def test_msgctxt(self):
        #import pdb; pdb.set_trace()
        mo = polib.mofile('tests/test_msgctxt.mo')
        expected = '''msgid ""
msgstr "Content-Type: text/plain; charset=UTF-8\u005cn"

msgctxt "Some message context"
msgid "some string"
msgstr "une cha\u00eene avec contexte"

msgctxt "Some other message context"
msgid "singular"
msgid_plural "plural"
msgstr[0] "singulier"
msgstr[1] "pluriel"

msgid "some string"
msgstr "une cha\u00eene sans contexte"
'''
        self.assertEqual(mo.__unicode__(), expected)
コード例 #4
0
 def test_save_as_pofile(self):
     """
     Test for the MOFile.save_as_pofile() method.
     """
     fd, tmpfile = tempfile.mkstemp()
     os.close(fd)
     mo = polib.mofile('tests/test_utf8.mo', wrapwidth=78)
     mo.save_as_pofile(tmpfile)
     try:
         # if polib.PY3:
         f = open(tmpfile, encoding='utf-8')
         # else:
         #     f = open(tmpfile)
         s1 = f.read()
         f.close()
         # if polib.PY3:
         f = open('tests/test_save_as_pofile.po', encoding='utf-8')
         # else:
         #     f = open('tests/test_save_as_pofile.po')
         s2 = f.read()
         f.close()
         self.assertEqual(s1, s2)
     finally:
         os.remove(tmpfile)
コード例 #5
0
 def test_invalid_version(self):
     self.assertRaises(IOError, polib.mofile,
                       'tests/test_invalid_version.mo')
     polib.mofile('tests/test_version_1.1.mo')
コード例 #6
0
 def test_pofile_and_mofile3(self):
     """
     Test  that the mofile function returns a MOFile instance.
     """
     mo = polib.mofile('tests/test_utf8.mo')
     self.assertTrue(isinstance(mo, polib.MOFile))