Source

fat_po_editor / tests / test_vcs_util.py

# -*- coding: utf-8 -*-

import os
import unittest

from fat_po_editor.vcs_util import RepoWithPofiles, BoundChangesetInfo
from . import get_testdata_path

class TestVcsUtilRepoWithPofiles(unittest.TestCase):
    def setUp(self):
        self.testdata_path = os.path.join(get_testdata_path(),
                                          'repo1')
        self.repo = RepoWithPofiles(self.testdata_path)

    def test_get_last_useful_changesets_info_simple(self):
        info = self.repo.get_last_useful_changesets_info()
        self.assertEquals(len(info), 2)
        self.assertEquals(unicode(info[0]),
                          (u"Revision no.: b45afb00139e\n"
                           u"Author: kost BebiX <k.bx@ya.ru>\n"
                           u"Affected pofiles: [pofiles/first.po]\n"))
        self.assertEquals(unicode(info[1]),
                          (u"Revision no.: df3e51d42076\n"
                           u"Author: kost BebiX <k.bx@ya.ru>\n"
                           u"Affected pofiles: [pofiles/first.po]\n"))

class TestBoundChangesetInfo(unittest.TestCase):
    def setUp(self):
        self.testdata_path = os.path.join(get_testdata_path(),
                                          'repo2')
        self.repo = RepoWithPofiles(self.testdata_path)
    
    def test_generate_podiff_simple(self):
        bound_changeset_info = (
            self.repo.get_bound_changeset_info_for_revision('7d03985ecb3c'))
        podiff = bound_changeset_info.generate_podiff('pofiles/first.po')
        self.assertEquals(
            podiff.full_represent(),
            u'+ msgid "third msgid"\n'
            u'+ msgstr "third msgstr"\n')
        
    def test_generate_podiff_added_msgplural(self):
        bound_changeset_info = (
            self.repo.get_bound_changeset_info_for_revision('578db7c04ee4'))
        podiff = bound_changeset_info.generate_podiff('pofiles/first.po')
        self.assertEquals(
            podiff.full_represent(),
            u'+ msgid "ngettext msgid"\n'
            u'+ msgid_plural "nsgettext msgid_plural"\n'
            u'+ msgstr ""\n')

    def test_generate_podiff_translated_msgplural(self):
        bound_changeset_info = (
            self.repo.get_bound_changeset_info_for_revision('6714f3f0d989'))
        podiff = bound_changeset_info.generate_podiff('pofiles/first.po')
        self.assertEquals(
            podiff.full_represent(),
            u'+ msgid "ngettext msgid"\n'
            u'+ msgid_plural "nsgettext msgid_plural"\n'
            u'+ msgstr[0] "first form"\n'
            u'+ msgstr[1] "second form"\n'
            u'+ msgstr[2] "third form"\n'
            u'- msgid "ngettext msgid"\n'
            u'- msgid_plural "nsgettext msgid_plural"\n'
            u'- msgstr ""\n')