2 # -*- coding: utf-8 -*-
4 from translate
.storage
import test_base
5 from translate
.storage
import wordfast
as wf
7 class TestWFTime(object):
9 def test_timestring(self
):
10 """Setting and getting times set using a timestring"""
11 wftime
= wf
.WordfastTime()
12 assert wftime
.timestring
== None
13 wftime
.timestring
= "19710820~050000"
14 assert wftime
.time
[:6] == (1971, 8, 20, 5, 0, 0)
17 """Setting and getting times set using time tuple"""
18 wftime
= wf
.WordfastTime()
19 assert wftime
.time
== None
20 wftime
.time
= (1999, 3, 27)
21 wftime
.timestring
= "19990327~000000"
23 class TestWFUnit(test_base
.TestTranslationUnit
):
24 UnitClass
= wf
.WordfastUnit
26 def test_difficult_escapes(self
):
27 """Wordfast files need to perform magic with escapes.
29 Wordfast does not accept line breaks in its TM (even though they would be
30 valid in CSV) thus we turn \\n into \n and reimplement the base class test but
31 eliminate a few of the actual tests.
34 specials
= ['\\"', '\\ ',
35 '\\\n', '\\\t', '\\\\r', '\\\\"']
36 for special
in specials
:
38 print "unit.source:", repr(unit
.source
) + '|'
39 print "special:", repr(special
) + '|'
40 assert unit
.source
== special
42 def test_wordfast_escaping(self
):
43 """Check handling of &'NN; style escaping"""
44 def compare(real
, escaped
):
45 unit
= self
.UnitClass(real
)
46 print real
.encode('utf-8'), unit
.source
.encode('utf-8')
47 assert unit
.source
== real
48 assert unit
.dict['source'] == escaped
50 assert unit
.target
== real
51 assert unit
.dict['target'] == escaped
52 for escaped
, real
in wf
.WF_ESCAPE_MAP
[:16]: # Only common and Windows, not testing Mac
53 compare(real
, escaped
)
55 unit
= self
.UnitClass("Open &File. ’n Probleem.")
56 assert unit
.dict['source'] == "Open &'26;File. &'92;n Probleem."
58 def test_newlines(self
):
59 """Wordfast does not like real newlines"""
60 unit
= self
.UnitClass("One\nTwo")
61 assert unit
.dict['source'] == "One\\nTwo"
63 def test_language_setting(self
):
64 """Check that we can set the target language"""
65 unit
= self
.UnitClass("Test")
66 unit
.targetlang
= "AF"
67 assert unit
.dict['target-lang'] == 'AF'
69 def test_istranslated(self
):
70 unit
= self
.UnitClass()
71 assert not unit
.istranslated()
73 assert not unit
.istranslated()
75 assert unit
.istranslated()
77 class TestWFFile(test_base
.TestTranslationStore
):
78 StoreClass
= wf
.WordfastTMFile