Trees | Indices | Help |
|
---|
|
1 #!/usr/bin/env python 2 # -*- coding: utf-8 -*- 3 4 from translate.convert import prop2po 5 from translate.convert import test_convert 6 from translate.misc import wStringIO 7 from translate.storage import po 8 from translate.storage import properties 918012 """helper that converts .properties source to po source without requiring files""" 13 inputfile = wStringIO.StringIO(propsource) 14 inputprop = properties.propfile(inputfile) 15 convertor = prop2po.prop2po() 16 if proptemplate: 17 templatefile = wStringIO.StringIO(proptemplate) 18 templateprop = properties.propfile(templatefile) 19 outputpo = convertor.mergestore(templateprop, inputprop) 20 else: 21 outputpo = convertor.convertstore(inputprop) 22 return outputpo2325 """call the convertprop, return the outputfile""" 26 inputfile = wStringIO.StringIO(propsource) 27 outputfile = wStringIO.StringIO() 28 templatefile = None 29 assert prop2po.convertprop(inputfile, outputfile, templatefile) 30 return outputfile.getvalue()3133 """checks that the pofile contains a single non-header element, and returns it""" 34 assert len(pofile.units) == 2 35 assert pofile.units[0].isheader() 36 print pofile 37 return pofile.units[1]3840 """counts the number of non-header entries""" 41 assert pofile.units[0].isheader() 42 print pofile 43 return len(pofile.units) - 14446 """checks that a simple properties entry converts properly to a po entry""" 47 propsource = 'SAVEENTRY=Save file\n' 48 pofile = self.prop2po(propsource) 49 pounit = self.singleelement(pofile) 50 assert pounit.source == "Save file" 51 assert pounit.target == ""5254 """checks that the convertprop function is working""" 55 propsource = 'SAVEENTRY=Save file\n' 56 posource = self.convertprop(propsource) 57 pofile = po.pofile(wStringIO.StringIO(posource)) 58 pounit = self.singleelement(pofile) 59 assert pounit.source == "Save file" 60 assert pounit.target == ""6163 """check that we preserve tabs at the end of a string""" 64 propsource = r"TAB_AT_END=This setence has a tab at the end.\t" 65 pofile = self.prop2po(propsource) 66 pounit = self.singleelement(pofile) 67 assert pounit.source == "This setence has a tab at the end.\t" 68 69 propsource = r"SPACE_THEN_TAB_AT_END=This setence has a space then tab at the end. \t" 70 pofile = self.prop2po(propsource) 71 pounit = self.singleelement(pofile) 72 assert pounit.source == "This setence has a space then tab at the end. \t" 73 74 propsource = r"SPACE_AT_END=This setence will lose its 4 spaces at the end. " 75 pofile = self.prop2po(propsource) 76 pounit = self.singleelement(pofile) 77 assert pounit.source == "This setence will lose its 4 spaces at the end." 78 79 propsource = r"SPACE_AT_END_NO_TRIM=This setence will keep its 4 spaces at the end.\\ " 80 pofile = self.prop2po(propsource) 81 pounit = self.singleelement(pofile) 82 assert pounit.source == "This setence will keep its 4 spaces at the end. "8385 """check that tabs in a property are ignored where appropriate""" 86 propsource = r"property = value" 87 pofile = self.prop2po(propsource) 88 pounit = self.singleelement(pofile) 89 assert pounit.getlocations()[0] == "property" 90 assert pounit.source == "value"9193 """checks that unicode entries convert properly""" 94 unistring = r'Norsk bokm\u00E5l' 95 propsource = 'nb = %s\n' % unistring 96 pofile = self.prop2po(propsource) 97 pounit = self.singleelement(pofile) 98 print repr(pofile.units[0].target) 99 print repr(pounit.source) 100 assert pounit.source == u'Norsk bokm\u00E5l'101103 """checks that multiline enties can be parsed""" 104 propsource = r"""5093=Unable to connect to your IMAP server. You may have exceeded the maximum number \ 105 of connections to this server. If so, use the Advanced IMAP Server Settings dialog to \ 106 reduce the number of cached connections.""" 107 pofile = self.prop2po(propsource) 108 print repr(pofile.units[1].target) 109 assert self.countelements(pofile) == 1110112 """test to ensure that we take comments from .properties and place them in .po""" 113 propsource = '''# Comment 114 prefPanel-smime=Security''' 115 pofile = self.prop2po(propsource) 116 pounit = self.singleelement(pofile) 117 assert pounit.getnotes("developer") == "# Comment"118120 """check that we can fold various accesskeys into their associated label (bug #115)""" 121 propsource = r'''cmd_addEngine = Add Engines... 122 cmd_addEngine_accesskey = A''' 123 pofile = self.prop2po(propsource) 124 pounit = self.singleelement(pofile) 125 assert pounit.target == "&Add Engines..."126128 """check that we know how to ignore don't translate instructions in properties files (bug #116)""" 129 propsource = '''# LOCALIZATION NOTE (dont): DONT_TRANSLATE. 130 dont=don't translate me 131 do=translate me 132 ''' 133 pofile = self.prop2po(propsource) 134 assert self.countelements(pofile) == 1135137 """checks that empty property definitions survive into po file, bug 15""" 138 propsource = '# comment\ncredit=' 139 pofile = self.prop2po(propsource) 140 pounit = self.singleelement(pofile) 141 assert pounit.getlocations() == ["credit"] 142 assert pounit.getcontext() == "credit" 143 assert "#. # comment" in str(pofile) 144 assert pounit.source == ""145147 """checks that if we translate an empty property it makes it into the PO""" 148 proptemplate = 'credit=' 149 propsource = 'credit=Translators Names' 150 pofile = self.prop2po(propsource, proptemplate) 151 pounit = self.singleelement(pofile) 152 assert pounit.getlocations() == ["credit"] 153 # FIXME we don't seem to get a _: comment but we should 154 #assert pounit.getcontext() == "credit" 155 assert pounit.source == "" 156 assert pounit.target == "Translators Names"157159 """check that we can carry newlines that appear in the property value into the PO""" 160 propsource = '''prop=\\nvalue\\n\n''' 161 pofile = self.prop2po(propsource) 162 unit = self.singleelement(pofile) 163 assert unit.source == "\nvalue\n"164166 """check that we can handle comments not directly associated with a property""" 167 propsource = '''# Header comment\n\n# Comment\n\nprop=value\n''' 168 pofile = self.prop2po(propsource) 169 unit = self.singleelement(pofile) 170 assert unit.source == "value" 171 assert unit.getnotes("developer") == "# Comment"172174 """check that we can handle the order of unassociated comments""" 175 propsource = '''# Header comment\n\n# 1st Unassociated comment\n\n# 2nd Connected comment\nprop=value\n''' 176 pofile = self.prop2po(propsource) 177 unit = self.singleelement(pofile) 178 assert unit.source == "value" 179 assert unit.getnotes("developer") == "# 1st Unassociated comment\n# 2nd Connected comment"182 """Tests running actual prop2po commands on files""" 183 convertmodule = prop2po 184 defaultoptions = {"progress": "none"} 185192187 """tests getting help""" 188 options = test_convert.TestConvertCommand.test_help(self) 189 options = self.help_check(options, "-P, --pot") 190 options = self.help_check(options, "-t TEMPLATE, --template=TEMPLATE") 191 options = self.help_check(options, "--duplicates=DUPLICATESTYLE", last=True)
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Tue Sep 23 13:51:34 2008 | http://epydoc.sourceforge.net |