Ejemplo n.º 1
0
    def test_romanian_nicio(self):
        """Test the Romanian nicio check"""
        posource = '''
msgid "cow"
msgstr "bla nici o bla"
'''
        pofile = self.parse_text(posource)
        filter_result = self.filter(pofile,
                                    cmdlineoptions=["--language=ro",
                                                    "--test=niciun_nicio"])
        errors = first_translatable(filter_result).geterrors()
        assert len(errors) == 1
        assert 'niciun_nicio' in errors

        posource = '''
msgid "cow"
msgstr "bla nicio bla"
'''
        pofile = self.parse_text(posource)
        filter_result = self.filter(pofile,
                                    cmdlineoptions=["--language=ro",
                                                    "--test=niciun_nicio"])
        errors = first_translatable(filter_result).geterrors()
        assert len(errors) == 0
        assert 'niciun_nicio' not in errors
Ejemplo n.º 2
0
    def test_romanian_cedillas(self):
        """Test the Romanian cedillas check"""
        posource = '''
msgid "cow"
msgstr "blaŞbla"
'''
        pofile = self.parse_text(posource)
        filter_result = self.filter(pofile,
                                    cmdlineoptions=["--language=ro",
                                                    "--test=cedillas"])
        errors = first_translatable(filter_result).geterrors()
        assert len(errors) == 1
        assert 'cedillas' in errors

        posource = '''
msgid "cow"
msgstr "blaSbla"
'''
        pofile = self.parse_text(posource)
        filter_result = self.filter(pofile,
                                    cmdlineoptions=["--language=ro",
                                                    "--test=cedillas"])
        errors = first_translatable(filter_result).geterrors()
        assert len(errors) == 0
        assert 'cedillas' not in errors
Ejemplo n.º 3
0
    def test_romanian_nicio(self):
        """Test the Romanian nicio check"""
        posource = """
msgid "cow"
msgstr "bla nici o bla"
"""
        pofile = self.parse_text(posource)
        filter_result = self.filter(
            pofile, cmdlineoptions=["--language=ro", "--test=niciun_nicio"]
        )
        errors = first_translatable(filter_result).geterrors()
        assert len(errors) == 1
        assert "niciun_nicio" in errors

        posource = """
msgid "cow"
msgstr "bla nicio bla"
"""
        pofile = self.parse_text(posource)
        filter_result = self.filter(
            pofile, cmdlineoptions=["--language=ro", "--test=niciun_nicio"]
        )
        errors = first_translatable(filter_result).geterrors()
        assert len(errors) == 0
        assert "niciun_nicio" not in errors
Ejemplo n.º 4
0
 def test_msgid_comments(self):
     """Tests that msgid comments don't feature anywhere."""
     posource = 'msgid "_: Capital.  ACRONYMN. (msgid) comment 3. %d Extra sentence.\\n"\n"cow"\nmsgstr "koei"\n'
     pofile = self.parse_text(posource)
     filter_result = self.filter(pofile)
     if headerless_len(filter_result.units):
         print first_translatable(filter_result)
     assert headerless_len(filter_result.units) == 0
Ejemplo n.º 5
0
 def test_msgid_comments(self):
     """Tests that msgid comments don't feature anywhere."""
     posource = 'msgid "_: Capital.  ACRONYMN. (msgid) comment 3. %d Extra sentence.\\n"\n"cow"\nmsgstr "koei"\n'
     pofile = self.parse_text(posource)
     filter_result = self.filter(pofile)
     if headerless_len(filter_result.units):
         print first_translatable(filter_result)
     assert headerless_len(filter_result.units) == 0
Ejemplo n.º 6
0
    def test_simplegrep(self):
        """grep for a simple string."""
        xliff_text = self.xliff_text
        xliff_file = self.xliff_parse(xliff_text)
        xliff_result = self.xliff_parse(self.xliff_grep(xliff_text, "rêd"))
        assert first_translatable(xliff_result).getsource() == "rêd"
        assert first_translatable(xliff_result).gettarget() == "rooi"

        xliff_result = self.xliff_parse(self.xliff_grep(xliff_text, "unavailable string"))
        assert xliff_result.isempty()
Ejemplo n.º 7
0
    def test_simplegrep(self):
        """grep for a simple string."""
        xliff_text = self.xliff_text
        xliff_file = self.xliff_parse(xliff_text)
        xliff_result = self.xliff_parse(self.xliff_grep(xliff_text, "rêd"))
        assert first_translatable(xliff_result).getsource() == u"rêd"
        assert first_translatable(xliff_result).gettarget() == u"rooi"

        xliff_result = self.xliff_parse(self.xliff_grep(xliff_text, "unavailable string"))
        assert xliff_result.isempty()
Ejemplo n.º 8
0
    def test_simplegrep(self):
        """grep for a simple string."""
        xliff_text = self.xliff_text
        self.xliff_parse(xliff_text.encode())
        xliff_result = self.xliff_parse(self.xliff_grep(xliff_text, "rêd"))
        assert first_translatable(xliff_result).source == "rêd"
        assert first_translatable(xliff_result).target == "rooi"

        xliff_result = self.xliff_parse(
            self.xliff_grep(xliff_text, "unavailable string"))
        assert xliff_result.isempty()
Ejemplo n.º 9
0
    def test_ignore_if_already_marked(self):
        """check that we don't add another failing marker if the message is already marked as failed"""
        self.unit.target = ''
        filter_result = self.filter(self.translationstore, cmdlineoptions=["--test=untranslated"])
        errors = first_translatable(filter_result).geterrors()
        assert len(errors) == 1
        assert errors.has_key('untranslated')

        # Run a filter test on the result, to check that it doesn't mark the same error twice.
        filter_result2 = self.filter(filter_result, cmdlineoptions=["--test=untranslated"])
        errors = first_translatable(filter_result2).geterrors()
        assert len(errors) == 1
        assert errors.has_key('untranslated')
Ejemplo n.º 10
0
    def test_ignore_if_already_marked(self):
        """check that we don't add another failing marker if the message is already marked as failed"""
        self.unit.target = ''
        filter_result = self.filter(self.translationstore,
                                    cmdlineoptions=["--test=untranslated"])
        errors = first_translatable(filter_result).geterrors()
        assert len(errors) == 1
        assert errors.has_key('untranslated')

        # Run a filter test on the result, to check that it doesn't mark the same error twice.
        filter_result2 = self.filter(filter_result,
                                     cmdlineoptions=["--test=untranslated"])
        errors = first_translatable(filter_result2).geterrors()
        assert len(errors) == 1
        assert errors.has_key('untranslated')
Ejemplo n.º 11
0
 def test_simplefail(self):
     """checks that an obviously wrong string fails"""
     self.unit.target = "REST"
     filter_result = self.filter(self.translationstore)
     print(filter_result)
     print(filter_result.units)
     assert "startcaps" in first_translatable(filter_result).geterrors()
Ejemplo n.º 12
0
 def test_simplefail(self):
     """checks that an obviously wrong string fails"""
     self.unit.target = "REST"
     filter_result = self.filter(self.translationstore)
     print filter_result
     print filter_result.units
     assert first_translatable(filter_result).geterrors().has_key('startcaps')
Ejemplo n.º 13
0
    def test_isreview(self):
        """tests the extraction of items marked review"""
        filter_result = self.filter(self.translationstore, cmdlineoptions=["--test=isreview"])
        assert headerless_len(filter_result.units) == 0

        self.unit.markreviewneeded()
        filter_result = self.filter(self.translationstore, cmdlineoptions=["--test=isreview"])
        assert first_translatable(filter_result).isreview()
Ejemplo n.º 14
0
    def test_notes(self):
        """tests the optional adding of notes"""
        # let's make sure we trigger the 'long' and/or 'doubleword' test
        self.unit.target = u"asdf asdf asdf asdf asdf asdf asdf"
        filter_result = self.filter(self.translationstore)
        assert headerless_len(filter_result.units) == 1
        assert first_translatable(filter_result).geterrors()

        # now we remove the existing error. self.unit is changed since we copy
        # units - very naughty
        if isinstance(self.unit, xliff.xliffunit):
            self.unit.removenotes(origin='pofilter')
        else:
            self.unit.removenotes()
        filter_result = self.filter(self.translationstore, cmdlineoptions=["--nonotes"])
        assert headerless_len(filter_result.units) == 1
        assert len(first_translatable(filter_result).geterrors()) == 0
Ejemplo n.º 15
0
    def test_notes(self):
        """tests the optional adding of notes"""
        # let's make sure we trigger the 'long' and/or 'doubleword' test
        self.unit.target = "asdf asdf asdf asdf asdf asdf asdf"
        filter_result = self.filter(self.translationstore)
        assert headerless_len(filter_result.units) == 1
        assert first_translatable(filter_result).geterrors()

        # now we remove the existing error. self.unit is changed since we copy
        # units - very naughty
        if isinstance(self.unit, xliff.xliffunit):
            self.unit.removenotes(origin="pofilter")
        else:
            self.unit.removenotes()
        filter_result = self.filter(self.translationstore, cmdlineoptions=["--nonotes"])
        assert headerless_len(filter_result.units) == 1
        assert len(first_translatable(filter_result).geterrors()) == 0
Ejemplo n.º 16
0
 def test_preconditions(self):
     """tests that the preconditions work correctly"""
     self.unit.source = "File"
     self.unit.target = ""
     filter_result= self.filter(self.translationstore)
     # We should only get one error (untranslated), and nothing else
     assert headerless_len(filter_result.units) == 1
     unit = first_translatable(filter_result)
     assert len(unit.geterrors()) == 1
Ejemplo n.º 17
0
 def test_preconditions(self):
     """tests that the preconditions work correctly"""
     self.unit.source = "File"
     self.unit.target = ""
     filter_result = self.filter(self.translationstore)
     # We should only get one error (untranslated), and nothing else
     assert headerless_len(filter_result.units) == 1
     unit = first_translatable(filter_result)
     assert len(unit.geterrors()) == 1
Ejemplo n.º 18
0
    def test_isfuzzy(self):
        """tests the extraction of items marked fuzzy"""
        self.unit.markfuzzy()

        filter_result = self.filter(self.translationstore, cmdlineoptions=["--test=isfuzzy"])
        assert first_translatable(filter_result).geterrors().has_key('isfuzzy')

        self.unit.markfuzzy(False)
        filter_result = self.filter(self.translationstore, cmdlineoptions=["--test=isfuzzy"])
        assert headerless_len(filter_result.units) == 0
Ejemplo n.º 19
0
    def test_isreview(self):
        """tests the extraction of items marked review"""
        filter_result = self.filter(self.translationstore,
                                    cmdlineoptions=["--test=isreview"])
        assert headerless_len(filter_result.units) == 0

        self.unit.markreviewneeded()
        filter_result = self.filter(self.translationstore,
                                    cmdlineoptions=["--test=isreview"])
        assert first_translatable(filter_result).isreview()
Ejemplo n.º 20
0
    def test_isfuzzy(self):
        """tests the extraction of items marked fuzzy"""
        self.unit.markfuzzy()

        filter_result = self.filter(self.translationstore,
                                    cmdlineoptions=["--test=isfuzzy"])
        assert "isfuzzy" in first_translatable(filter_result).geterrors()

        self.unit.markfuzzy(False)
        filter_result = self.filter(self.translationstore,
                                    cmdlineoptions=["--test=isfuzzy"])
        assert headerless_len(filter_result.units) == 0
Ejemplo n.º 21
0
    def test_translatorcomments(self):
        """Tests translator comments"""
        minixlf = self.xliffskeleton % '''<trans-unit>
        <source>nonsense</source>
        <target>matlhapolosa</target>
        <context-group name="po-entry" purpose="information">
            <context context-type="x-po-trancomment">Couldn't do
it</context>
        </context-group>
        <note from="po-translator">Couldn't do
it</note>
</trans-unit>'''
        pofile = self.xliff2po(minixlf)
        assert pofile.translate("nonsense") == "matlhapolosa"
        assert pofile.translate("bla") is None
        unit = first_translatable(pofile)
        assert unit.getnotes("translator") == "Couldn't do it"
        potext = bytes(pofile).decode('utf-8')
        assert potext.index("# Couldn't do it\n") >= 0

        minixlf = self.xliffskeleton % '''<trans-unit xml:space="preserve">
        <source>nonsense</source>
        <target>matlhapolosa</target>
        <context-group name="po-entry" purpose="information">
            <context context-type="x-po-trancomment">Couldn't do
it</context>
        </context-group>
        <note from="po-translator">Couldn't do
it</note>
</trans-unit>'''
        pofile = self.xliff2po(minixlf)
        assert pofile.translate("nonsense") == "matlhapolosa"
        assert pofile.translate("bla") is None
        unit = first_translatable(pofile)
        assert unit.getnotes("translator") == "Couldn't do\nit"
        potext = bytes(pofile).decode('utf-8')
        assert potext.index("# Couldn't do\n# it\n") >= 0
Ejemplo n.º 22
0
    def test_autocomment(self):
        """Tests automatic comments"""
        minixlf = self.xliffskeleton % '''<trans-unit>
        <source>nonsense</source>
        <target>matlhapolosa</target>
        <context-group name="po-entry" purpose="information">
            <context context-type="x-po-autocomment">Note that this is
garbage</context>
        </context-group>
        <note from="developer">Note that this is
garbage</note>
</trans-unit>'''
        pofile = self.xliff2po(minixlf)
        assert pofile.translate("nonsense") == "matlhapolosa"
        assert pofile.translate("bla") is None
        unit = first_translatable(pofile)
        assert unit.getnotes("developer") == "Note that this is garbage"
        potext = bytes(pofile).decode('utf-8')
        assert potext.index("#. Note that this is garbage\n") >= 0

        minixlf = self.xliffskeleton % '''<trans-unit xml:space="preserve">
        <source>nonsense</source>
        <target>matlhapolosa</target>
        <context-group name="po-entry" purpose="information">
            <context context-type="x-po-autocomment">Note that this is
garbage</context>
        </context-group>
        <note from="developer">Note that this is
garbage</note>
</trans-unit>'''
        pofile = self.xliff2po(minixlf)
        assert pofile.translate("nonsense") == "matlhapolosa"
        assert pofile.translate("bla") is None
        unit = first_translatable(pofile)
        assert unit.getnotes("developer") == "Note that this is\ngarbage"
        potext = bytes(pofile).decode('utf-8')
        assert potext.index("#. Note that this is\n#. garbage\n") >= 0
Ejemplo n.º 23
0
    def set_store_review(self, review=True):
        self.filetext = """<?xml version="1.0" encoding="utf-8"?>
<xliff version="1.1" xmlns="urn:oasis:names:tc:xliff:document:1.1">
<file datatype="po" original="example.po" source-language="en-US">
  <body>
    <trans-unit approved="yes">
      <source>test</source>
      <target>rest</target>
    </trans-unit>
  </body>
</file>
</xliff>"""

        self.translationstore = self.parse_text(self.filetext)
        self.unit = first_translatable(self.translationstore)
Ejemplo n.º 24
0
    def set_store_review(self, review=True):
        self.filetext = '''<?xml version="1.0" encoding="utf-8"?>
<xliff version="1.1" xmlns="urn:oasis:names:tc:xliff:document:1.1">
<file datatype="po" original="example.po" source-language="en-US">
  <body>
    <trans-unit approved="yes">
      <source>test</source>
      <target>rest</target>
    </trans-unit>
  </body>
</file>
</xliff>'''

        self.translationstore = self.parse_text(self.filetext)
        self.unit = first_translatable(self.translationstore)
Ejemplo n.º 25
0
    def test_quotes(self):
        """Test the escaping of quotes (and slash)"""
        minicsv = r''',"Hello ""Everyone""","Good day ""All"""
,"Use \"".","Gebruik \""."'''
        print(minicsv)
        csvfile = csvl10n.csvfile(wStringIO.StringIO(minicsv))
        print(bytes(csvfile))
        pofile = self.csv2po(minicsv)
        unit = first_translatable(pofile)
        assert unit.source == 'Hello "Everyone"'
        assert pofile.findunit('Hello "Everyone"').target == 'Good day "All"'
        print(bytes(pofile))
        for unit in pofile.units:
            print(unit.source)
            print(unit.target)
            print()
Ejemplo n.º 26
0
    def test_quotes(self):
        """Test the escaping of quotes (and slash)"""
        minicsv = r''',"Hello ""Everyone""","Good day ""All"""
,"Use \"".","Gebruik \""."'''
        print minicsv
        csvfile = csvl10n.csvfile(wStringIO.StringIO(minicsv))
        print str(csvfile)
        pofile = self.csv2po(minicsv)
        unit = first_translatable(pofile)
        assert unit.source == 'Hello "Everyone"'
        assert pofile.findunit('Hello "Everyone"').target == 'Good day "All"'
        print str(pofile)
        for unit in pofile.units:
            print unit.source
            print unit.target
            print
Ejemplo n.º 27
0
    def test_test_against_review(self):
        """test whether to run tests against translations marked for review"""
        self.unit.markreviewneeded()
        filter_result = self.filter(self.translationstore, cmdlineoptions=["--review"])
        assert first_translatable(filter_result).isreview()

        filter_result = self.filter(self.translationstore, cmdlineoptions=["--noreview"])
        assert headerless_len(filter_result.units) == 0

        # Re-initialize the translation store object.
        self.setup_method(self)

        filter_result = self.filter(self.translationstore, cmdlineoptions=["--review"])
        assert headerless_len(filter_result.units) == 0
        filter_result = self.filter(self.translationstore, cmdlineoptions=["--noreview"])
        assert headerless_len(filter_result.units) == 0
Ejemplo n.º 28
0
    def test_test_against_fuzzy(self):
        """test whether to run tests against fuzzy translations"""
        self.unit.markfuzzy()

        filter_result = self.filter(self.translationstore, cmdlineoptions=["--fuzzy"])
        assert "isfuzzy" in first_translatable(filter_result).geterrors()

        filter_result = self.filter(self.translationstore, cmdlineoptions=["--nofuzzy"])
        assert headerless_len(filter_result.units) == 0

        # Re-initialize the translation store object in order to get an unfuzzy
        # unit with no filter notes.
        self.setup_method(self)

        filter_result = self.filter(self.translationstore, cmdlineoptions=["--fuzzy"])
        assert headerless_len(filter_result.units) == 0

        filter_result = self.filter(self.translationstore, cmdlineoptions=["--nofuzzy"])
        assert headerless_len(filter_result.units) == 0
Ejemplo n.º 29
0
    def test_test_against_fuzzy(self):
        """test whether to run tests against fuzzy translations"""
        self.unit.markfuzzy()

        filter_result = self.filter(self.translationstore, cmdlineoptions=["--fuzzy"])
        assert first_translatable(filter_result).geterrors().has_key('isfuzzy')

        filter_result = self.filter(self.translationstore, cmdlineoptions=["--nofuzzy"])
        assert headerless_len(filter_result.units) == 0

        # Re-initialize the translation store object in order to get an unfuzzy unit
	# with no filter notes.
        self.setup_method(self)

        filter_result = self.filter(self.translationstore, cmdlineoptions=["--fuzzy"])
        assert headerless_len(filter_result.units) == 0

        filter_result = self.filter(self.translationstore, cmdlineoptions=["--nofuzzy"])
        assert headerless_len(filter_result.units) == 0
Ejemplo n.º 30
0
    def test_test_against_review(self):
        """test whether to run tests against translations marked for review"""
        self.unit.markreviewneeded()
        filter_result = self.filter(self.translationstore, cmdlineoptions=["--review"])
        assert first_translatable(filter_result).isreview()

        filter_result = self.filter(
            self.translationstore, cmdlineoptions=["--noreview"]
        )
        assert headerless_len(filter_result.units) == 0

        # Re-initialize the translation store object.
        self.setup_method(self)

        filter_result = self.filter(self.translationstore, cmdlineoptions=["--review"])
        assert headerless_len(filter_result.units) == 0
        filter_result = self.filter(
            self.translationstore, cmdlineoptions=["--noreview"]
        )
        assert headerless_len(filter_result.units) == 0
Ejemplo n.º 31
0
    def test_locations(self):
        """Tests location comments (#:)"""
        minixlf = self.xliffskeleton % '''<trans-unit id="1">
        <source>nonsense</source>
        <target>matlhapolosa</target>
        <context-group name="po-reference" purpose="location">
            <context context-type="sourcefile">example.c</context>
            <context context-type="linenumber">123</context>
            </context-group>
        <context-group name="po-reference" purpose="location">
            <context context-type="sourcefile">place.py</context>
        </context-group>
</trans-unit>'''
        pofile = self.xliff2po(minixlf)
        assert pofile.translate("nonsense") == "matlhapolosa"
        assert pofile.translate("bla") is None
        unit = first_translatable(pofile)
        locations = unit.getlocations()
        assert len(locations) == 2
        assert "example.c:123" in locations
        assert "place.py" in locations
Ejemplo n.º 32
0
 def singleelement(self, storage):
     """checks that the pofile contains a single non-header element, and returns it"""
     assert headerless_len(storage.units) == 1
     return first_translatable(storage)
Ejemplo n.º 33
0
 def setup_method(self, method):
     self.translationstore = self.parse_text(self.filetext)
     self.unit = first_translatable(self.translationstore)
Ejemplo n.º 34
0
 def setup_method(self, method):
     self.translationstore = self.parse_text(self.filetext)
     self.unit = first_translatable(self.translationstore)
Ejemplo n.º 35
0
 def singleelement(self, storage):
     """checks that the pofile contains a single non-header element, and returns it"""
     assert headerless_len(storage.units) == 1
     return first_translatable(storage)