Package translate :: Package storage :: Module test_properties

[hide private]
[frames] | no frames]

# Source Code for Module translate.storage.test_properties

     1  #!/usr/bin/env python
     2  # -*- coding: utf-8 -*-
     3
     4  from translate.storage import properties
     5  from translate.storage import test_monolingual
     6  from translate.misc import wStringIO
     7
     8 -class TestPropUnit(test_monolingual.TestMonolingualUnit):
     9      UnitClass = properties.propunit
    10
    11 -    def test_difficult_escapes(self):
    12          """It doesn't seem that properties files can store double backslashes.
    13
    14          We are disabling the double-backslash tests for now.
    15          If we are mistaken in the above assumption, we need to fix getsource()
    16          and setsource() and delete this test override.
    17
    18          """
    19          pass
    20
    21 -class TestProp(test_monolingual.TestMonolingualStore):
    22      StoreClass = properties.propfile
    23
    24 -    def propparse(self, propsource):
    25          """helper that parses properties source without requiring files"""
    26          dummyfile = wStringIO.StringIO(propsource)
    27          propfile = properties.propfile(dummyfile)
    28          return propfile
    29
    30 -    def propregen(self, propsource):
    31          """helper that converts properties source to propfile object and back"""
    32          return str(self.propparse(propsource))
    33
    34 -    def test_simpledefinition(self):
    35          """checks that a simple properties definition is parsed correctly"""
    36          propsource = 'test_me=I can code!'
    37          propfile = self.propparse(propsource)
    38          assert len(propfile.units) == 1
    39          propunit = propfile.units[0]
    40          assert propunit.name == "test_me"
    41          assert propunit.source == "I can code!"
    42
    43 -    def test_simpledefinition_source(self):
    44          """checks that a simple properties definition can be regenerated as source"""
    45          propsource = 'test_me=I can code!'
    46          propregen = self.propregen(propsource)
    47          assert propsource + '\n' == propregen
    48
    49 -    def test_unicode_escaping(self):
    50          """check that escapes unicode is converted properly"""
    51          propsource = "unicode=\u0411\u0416\u0419\u0428"
    52          messagevalue = u'\u0411\u0416\u0419\u0428'.encode("UTF-8")
    53          propfile = self.propparse(propsource)
    54          assert len(propfile.units) == 1
    55          propunit = propfile.units[0]
    56          assert propunit.name == "unicode"
    57          assert propunit.source.encode("UTF-8") == "БЖЙШ"
    58          regensource = str(propfile)
    59          assert messagevalue in regensource
    60          assert "\\u" not in regensource
    61
    62 -    def test_newlines_startend(self):
    63          """check that we preserver \n that appear at start and end of properties"""
    64          propsource = "newlines=\\ntext\\n"
    65          propregen = self.propregen(propsource)
    66          assert propsource + '\n' == propregen
    67
    68 -    def test_whitespace_removal(self):
    69          """check that we remove extra whitespace around property"""
    70          propsource = '''  whitespace  =  Start \n'''
    71          propfile = self.propparse(propsource)
    72          propunit = propfile.units[0]
    73          assert propunit.name == "whitespace"
    74          assert propunit.source == "Start"
    75