def prop2po(self, propsource, proptemplate=None): """helper that converts .properties source to po source without requiring files""" inputfile = wStringIO.StringIO(propsource) inputprop = properties.propfile(inputfile) convertor = prop2po.prop2po() if proptemplate: templatefile = wStringIO.StringIO(proptemplate) templateprop = properties.propfile(templatefile) outputpo = convertor.mergestore(templateprop, inputprop) else: outputpo = convertor.convertstore(inputprop) return outputpo
def prop2po(self, propsource, proptemplate=None, personality="java"): """helper that converts .properties source to po source without requiring files""" inputfile = BytesIO(propsource.encode()) inputprop = properties.propfile(inputfile, personality=personality) convertor = prop2po.prop2po(personality=personality) if proptemplate: templatefile = BytesIO(proptemplate.encode()) templateprop = properties.propfile(templatefile) outputpo = convertor.mergestore(templateprop, inputprop) else: outputpo = convertor.convertstore(inputprop) return outputpo
def test_accel_header(self): """Test that we correctly create the header entry for accelerators.""" propsource = '''prop=value\n''' convertor = prop2po.prop2po() inputfile = wStringIO.StringIO(propsource) inputprop = properties.propfile(inputfile, personality="mozilla") outputpo = convertor.convertstore(inputprop, personality="mozilla") assert "X-Accelerator-Marker" in str(outputpo) # Even though the gaia flavour inherrits from mozilla, it should not # get the header inputfile = wStringIO.StringIO(propsource) inputprop = properties.propfile(inputfile, personality="gaia") outputpo = convertor.convertstore(inputprop, personality="gaia") assert "X-Accelerator-Marker" not in str(outputpo)
def test_x_header(self): """Test that we correctly create the custom header entries (accelerators, merge criterion). """ propsource = '''prop=value\n''' convertor = prop2po.prop2po() inputfile = wStringIO.StringIO(propsource) inputprop = properties.propfile(inputfile, personality="mozilla") outputpo = convertor.convertstore(inputprop, personality="mozilla") assert "X-Accelerator-Marker" in str(outputpo) assert "X-Merge-On" in str(outputpo) # Even though the gaia flavour inherrits from mozilla, it should not # get the header inputfile = wStringIO.StringIO(propsource) inputprop = properties.propfile(inputfile, personality="gaia") outputpo = convertor.convertstore(inputprop, personality="gaia") assert "X-Accelerator-Marker" not in str(outputpo) assert "X-Merge-On" not in str(outputpo)
def test_gaia_plurals(self): """Test conversion of gaia plural units.""" propsource = """ message-multiedit-header={[ plural(n) ]} message-multiedit-header[zero]=Edit message-multiedit-header[one]={{ n }} selected message-multiedit-header[two]={{ n }} selected message-multiedit-header[few]={{ n }} selected message-multiedit-header[many]={{ n }} selected message-multiedit-header[other]={{ n }} selected """ convertor = prop2po.prop2po() inputfile = wStringIO.StringIO(propsource) inputprop = properties.propfile(inputfile, personality="gaia") outputpo = convertor.convertstore(inputprop, personality="gaia") pounit = outputpo.units[-1] assert pounit.hasplural() assert pounit.getlocations() == [u"message-multiedit-header"] print outputpo zero_unit = outputpo.units[-2] assert not zero_unit.hasplural() assert zero_unit.source == u"Edit"
def test_gaia_plurals(self): """Test conversion of gaia plural units.""" propsource = ''' message-multiedit-header={[ plural(n) ]} message-multiedit-header[zero]=Edit message-multiedit-header[one]={{ n }} selected message-multiedit-header[two]={{ n }} selected message-multiedit-header[few]={{ n }} selected message-multiedit-header[many]={{ n }} selected message-multiedit-header[other]={{ n }} selected ''' convertor = prop2po.prop2po() inputfile = wStringIO.StringIO(propsource) inputprop = properties.propfile(inputfile, personality="gaia") outputpo = convertor.convertstore(inputprop, personality="gaia") pounit = outputpo.units[-1] assert pounit.hasplural() assert pounit.getlocations() == [u'message-multiedit-header'] print outputpo zero_unit = outputpo.units[-2] assert not zero_unit.hasplural() assert zero_unit.source == u"Edit"