Exemplo n.º 1
0
 def attrisToXml(self):
     resultAttris = []
     
     quantity = self.properties.get(WordProperty.QUANTITY)
     if quantity:
         if "—" in quantity:
             atLeastAtMost = quantity.split("—")
             resultAttris.append('atLeast="{}"'.format(str2Quantity(atLeastAtMost[0]))) 
             resultAttris.append('atMost="{}"'.format(str2Quantity(atLeastAtMost[1]))) 
         else:
             resultAttris.append('quantity="{}"'.format(str2Quantity(quantity))) 
             
     unit = self.properties.get(WordProperty.UNIT)
     if unit:
         resultAttris.append('unit="{}"'.format(unit))
     
     refCandis = [candi.xmlID for candi in self.properties.get(WordProperty.INGREDIENT)]
     if refCandis:
         resultAttris.append('ref="{}"'.format(" ".join(["#"+candi for candi in refCandis])))
     
     if self.properties.get(WordProperty.OPTIONAL):
         resultAttris.append('optional="True"')
     
     altGrp = self.properties.get(WordProperty.ALT_GRP)
     if altGrp:
         resultAttris.append('altGrp="{}"'.format(altGrp))
         
     return " ".join(resultAttris)
 def testQuantity2StringAHalf(self):
     self.assertEqual("0.5", str2Quantity("½"))
 def testQuantity2StringFloat(self):
     self.assertEqual("2", str2Quantity("2"))
 def testQuantity2String1AndHalf(self):
     self.assertEqual("1.5", str2Quantity("1½"))
 def testQuantity2String16(self):
     self.assertEqual("16", str2Quantity("16"))