Package translate :: Package storage :: Module test_wordfast

[hide private]
[frames] | no frames]

# Source Code for Module translate.storage.test_wordfast

     1  #!/usr/bin/env python
     2  # -*- coding: utf-8 -*-
     3
     4  from translate.storage import test_base
     5  from translate.storage import wordfast as wf
     6
     7 -class TestWFTime(object):
     8
     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)
    15
    16 -    def test_time(self):
    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"
    22
    23 -class TestWFUnit(test_base.TestTranslationUnit):
    24      UnitClass = wf.WordfastUnit
    25
    26 -    def test_difficult_escapes(self):
    27          """Wordfast files need to perform magic with escapes.
    28
    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.
    32          """
    33          unit = self.unit
    34          specials = ['\\"', '\\ ',
    35                      '\\\n', '\\\t', '\\\\r', '\\\\"']
    36          for special in specials:
    37              unit.source = special
    38              print "unit.source:", repr(unit.source) + '|'
    39              print "special:", repr(special) + '|'
    40              assert unit.source == special
    41
    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
    49              unit.target = real
    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)
    54          # Real world cases
    55          unit = self.UnitClass("Open &File. ’n Probleem.")
    56          assert unit.dict['source'] == "Open &'26;File. &'92;n Probleem."
    57
    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"
    62
    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'
    68
    69 -    def test_istranslated(self):
    70          unit = self.UnitClass()
    71          assert not unit.istranslated()
    72          unit.source = "Test"
    73          assert not unit.istranslated()
    74          unit.target = "Rest"
    75          assert unit.istranslated()
    76
    77 -class TestWFFile(test_base.TestTranslationStore):
    78      StoreClass = wf.WordfastTMFile
    79