3 from translate
.storage
import tmx
4 from translate
.storage
import test_base
5 from translate
.misc
import wStringIO
7 class TestTMXUnit(test_base
.TestTranslationUnit
):
8 UnitClass
= tmx
.tmxunit
10 class TestTMXUnitFromParsedString(TestTMXUnit
):
11 tmxsource
= '''<?xml version="1.0" encoding="utf-8"?>
15 <header adminlang="en" creationtool="Translate Toolkit - po2tmx" creationtoolversion="1.0beta" datatype="PlainText" o-tmf="UTF-8" segtype="sentence" srclang="en"/>
19 <seg>Test String</seg>
25 def setup_method(self
, method
):
26 store
= tmx
.tmxfile
.parsestring(self
.tmxsource
)
27 self
.unit
= store
.units
[0]
29 class TestTMXfile(test_base
.TestTranslationStore
):
30 StoreClass
= tmx
.tmxfile
32 def tmxparse(self
, tmxsource
):
33 """helper that parses tmx source without requiring files"""
34 dummyfile
= wStringIO
.StringIO(tmxsource
)
36 tmxfile
= tmx
.tmxfile(dummyfile
)
39 def test_translate(self
):
40 tmxfile
= tmx
.tmxfile()
41 assert tmxfile
.translate("Anything") is None
42 tmxfile
.addtranslation("A string of characters", "en", "'n String karakters", "af")
43 assert tmxfile
.translate("A string of characters") == "'n String karakters"
45 def test_addtranslation(self
):
46 """tests that addtranslation() stores strings correctly"""
47 tmxfile
= tmx
.tmxfile()
48 tmxfile
.addtranslation("A string of characters", "en", "'n String karakters", "af")
49 newfile
= self
.tmxparse(str(tmxfile
))
51 assert newfile
.translate("A string of characters") == "'n String karakters"
53 def test_withnewlines(self
):
54 """test addtranslation() with newlines"""
55 tmxfile
= tmx
.tmxfile()
56 tmxfile
.addtranslation("First line\nSecond line", "en", "Eerste lyn\nTweede lyn", "af")
57 newfile
= self
.tmxparse(str(tmxfile
))
59 assert newfile
.translate("First line\nSecond line") == "Eerste lyn\nTweede lyn"
61 def test_xmlentities(self
):
62 """Test that the xml entities '&' and '<' are escaped correctly"""
63 tmxfile
= tmx
.tmxfile()
64 tmxfile
.addtranslation("Mail & News", "en", "Nuus & pos", "af")
65 tmxfile
.addtranslation("Five < ten", "en", "Vyf < tien", "af")
66 xmltext
= str(tmxfile
)
67 print "The generated xml:"
69 assert tmxfile
.translate('Mail & News') == 'Nuus & pos'
70 assert xmltext
.index('Mail & News')
71 assert xmltext
.find('Mail & News') == -1
72 assert tmxfile
.translate('Five < ten') == 'Vyf < tien'
73 assert xmltext
.index('Five < ten')
74 assert xmltext
.find('Five < ten') == -1