| LEFT | RIGHT |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 | 2 |
| 3 from translate.storage import xliff | 3 from translate.storage import xliff |
| 4 from translate.storage import test_base | 4 from translate.storage import test_base |
| 5 | 5 |
| 6 class TestXLIFFUnit(test_base.TestTranslationUnit): | 6 class TestXLIFFUnit(test_base.TestTranslationUnit): |
| 7 UnitClass = xliff.xliffunit | 7 UnitClass = xliff.xliffunit |
| 8 | 8 |
| 9 def test_isfuzzy(self): | 9 def test_isfuzzy(self): |
| 10 """The default behaviour for XLIFF is different, so we adapt the test | 10 """The default behaviour for XLIFF is different, so we adapt the test |
| 11 from test_base.py""" | 11 from test_base.py""" |
| 12 assert self.unit.isfuzzy() | 12 assert self.unit.isfuzzy() |
| 13 | 13 |
| 14 def test_markreview(self): | 14 def test_markreview(self): |
| 15 """Tests if we can mark the unit to need review.""" | 15 """Tests if we can mark the unit to need review.""" |
| 16 unit = self.unit | 16 unit = self.unit |
| 17 # We have to explicitly set the target to nothing, otherwise xliff | 17 # We have to explicitly set the target to nothing, otherwise xliff |
| 18 # tests will fail. | 18 # tests will fail. |
| 19 # Can we make it default behavior for the UnitClass? | 19 # Can we make it default behavior for the UnitClass? |
| 20 unit.target = "" | 20 unit.target = "" |
| 21 | 21 |
| 22 unit.addnote("Test note 1", origin="translator") | 22 unit.addnote("Test note 1", origin="translator") |
| 23 unit.addnote("Test note 2", origin="translator") | 23 unit.addnote("Test note 2", origin="translator") |
| 24 original_notes = unit.getnotes(origin="translator") | 24 original_notes = unit.getnotes(origin="translator") |
| 25 | 25 |
| 26 assert not unit.isreview() | 26 assert not unit.isreview() |
| 27 unit.markreviewneeded() | 27 unit.markreviewneeded() |
| 28 assert unit.isreview() | 28 assert unit.isreview() |
| 29 unit.markreviewneeded(False) | 29 unit.markreviewneeded(False) |
| 30 assert not unit.isreview() | 30 assert not unit.isreview() |
| 31 assert unit.getnotes(origin="translator") == original_notes | 31 assert unit.getnotes(origin="translator") == original_notes |
| 32 unit.markreviewneeded(explanation="Double check spelling.") | 32 unit.markreviewneeded(explanation="Double check spelling.") |
| 33 assert unit.isreview() | 33 assert unit.isreview() |
| 34 notes = unit.getnotes(origin="translator") | 34 notes = unit.getnotes(origin="translator") |
| 35 assert notes.count("Double check spelling.") == 1 | 35 assert notes.count("Double check spelling.") == 1 |
| 36 | 36 |
| 37 def test_errors(self): | 37 def test_errors(self): |
| 38 """Tests that we can add and retrieve error messages for a unit.""" | 38 """Tests that we can add and retrieve error messages for a unit.""" |
| 39 unit = self.unit | 39 unit = self.unit |
| 40 | 40 |
| 41 assert len(unit.geterrors()) == 0 | 41 assert len(unit.geterrors()) == 0 |
| 42 unit.adderror(errorname='test1', errortext='Test error message 1.') | 42 unit.adderror(errorname='test1', errortext='Test error message 1.') |
| 43 unit.adderror(errorname='test2', errortext='Test error message 2.') | 43 unit.adderror(errorname='test2', errortext='Test error message 2.') |
| 44 unit.adderror(errorname='test3', errortext='Test error message 3.') | 44 unit.adderror(errorname='test3', errortext='Test error message 3.') |
| 45 assert len(unit.geterrors()) == 3 | 45 assert len(unit.geterrors()) == 3 |
| 46 assert unit.geterrors()['test1'] == 'Test error message 1.' | 46 assert unit.geterrors()['test1'] == 'Test error message 1.' |
| 47 assert unit.geterrors()['test2'] == 'Test error message 2.' | 47 assert unit.geterrors()['test2'] == 'Test error message 2.' |
| 48 assert unit.geterrors()['test3'] == 'Test error message 3.' | 48 assert unit.geterrors()['test3'] == 'Test error message 3.' |
| 49 unit.adderror(errorname='test1', errortext='New error 1.') | 49 unit.adderror(errorname='test1', errortext='New error 1.') |
| 50 assert unit.geterrors()['test1'] == 'New error 1.' | 50 assert unit.geterrors()['test1'] == 'New error 1.' |
| (...skipping 129 matching lines...) Show 10 above Show 10 below |
| 180 def test_fuzzy(self): | 180 def test_fuzzy(self): |
| 181 xlifffile = xliff.xlifffile() | 181 xlifffile = xliff.xlifffile() |
| 182 unit = xlifffile.addsourceunit("Concept") | 182 unit = xlifffile.addsourceunit("Concept") |
| 183 unit.markfuzzy() | 183 unit.markfuzzy() |
| 184 assert unit.isfuzzy() | 184 assert unit.isfuzzy() |
| 185 unit.target = "Konsep" | 185 unit.target = "Konsep" |
| 186 assert unit.isfuzzy() | 186 assert unit.isfuzzy() |
| 187 unit.markfuzzy() | 187 unit.markfuzzy() |
| 188 assert unit.isfuzzy() | 188 assert unit.isfuzzy() |
| 189 unit.markfuzzy(False) | 189 unit.markfuzzy(False) |
| 190 assert not unit.isfuzzy() | 190 assert not unit.isfuzzy() |
| 191 unit.markfuzzy(True) | 191 unit.markfuzzy(True) |
| 192 assert unit.isfuzzy() | 192 assert unit.isfuzzy() |
| 193 | 193 |
| 194 #If there is no target, we can't really indicate fuzzyness, so we set | 194 #If there is no target, we can't really indicate fuzzyness, so we set |
| 195 #approved to "no". If we want isfuzzy() to reflect that, the line can | 195 #approved to "no". If we want isfuzzy() to reflect that, the line can |
| 196 #be uncommented | 196 #be uncommented |
| 197 unit.target = None | 197 unit.target = None |
| 198 assert unit.target is None | 198 assert unit.target is None |
| 199 print unit | 199 print unit |
| 200 unit.markfuzzy(True) | 200 unit.markfuzzy(True) |
| 201 assert 'approved="no"' in str(unit) | 201 assert 'approved="no"' in str(unit) |
| 202 #assert unit.isfuzzy() | 202 #assert unit.isfuzzy() |
| 203 | 203 |
| 204 def test_parsing(self): | 204 def test_parsing(self): |
| 205 xlfsource = self.skeleton \ | 205 xlfsource = self.skeleton \ |
| 206 % '''<trans-unit id="1" xml:space="preserve"> | 206 % '''<trans-unit id="1" xml:space="preserve"> |
| 207 <source>File</source> | 207 <source>File</source> |
| 208 <target/> | 208 <target/> |
| 209 </trans-unit>''' | 209 </trans-unit>''' |
| 210 xlifffile = xliff.xlifffile.parsestring(xlfsource) | 210 xlifffile = xliff.xlifffile.parsestring(xlfsource) |
| 211 assert xlifffile.units[0].istranslatable() | 211 assert xlifffile.units[0].istranslatable() |
| 212 | 212 |
| 213 xlfsource = self.skeleton \ | 213 xlfsource = self.skeleton \ |
| 214 % '''<trans-unit id="1" xml:space="preserve" translate="no"> | 214 % '''<trans-unit id="1" xml:space="preserve" translate="no"> |
| 215 <source>File</source> | 215 <source>File</source> |
| 216 <target/> | 216 <target/> |
| 217 </trans-unit>''' | 217 </trans-unit>''' |
| 218 xlifffile = xliff.xlifffile.parsestring(xlfsource) | 218 xlifffile = xliff.xlifffile.parsestring(xlfsource) |
| 219 assert not xlifffile.units[0].istranslatable() | 219 assert not xlifffile.units[0].istranslatable() |
| 220 | 220 |
| 221 xlfsource = self.skeleton \ | 221 xlfsource = self.skeleton \ |
| 222 % '''<trans-unit id="1" xml:space="preserve" translate="yes"> | 222 % '''<trans-unit id="1" xml:space="preserve" translate="yes"> |
| 223 <source>File</source> | 223 <source>File</source> |
| 224 <target/> | 224 <target/> |
| 225 </trans-unit>''' | 225 </trans-unit>''' |
| 226 xlifffile = xliff.xlifffile.parsestring(xlfsource) | 226 xlifffile = xliff.xlifffile.parsestring(xlfsource) |
| 227 assert xlifffile.units[0].istranslatable() | 227 assert xlifffile.units[0].istranslatable() |
| 228 | 228 |
| 229 | 229 |
| LEFT | RIGHT |