def test_nested_to_tree(self, NestedValue): simple = NestedValue(4) xml = tostring(simple.to_tree()) expected = """ <simple> <size val="4"/> </simple> """ diff = compare_xml(xml, expected) assert diff is None, diff
class ColorChoice(Serialisable): tagname = "colorChoice" namespace = DRAWING_NS scrgbClr = Typed(expected_type=RGBPercent, allow_none=True) RGBPercent = Alias('scrgbClr') srgbClr = NestedValue(expected_type=unicode, allow_none=True) # needs pattern and can have transform RGB = Alias('srgbClr') hslClr = Typed(expected_type=HSLColor, allow_none=True) sysClr = Typed(expected_type=SystemColor, allow_none=True) schemeClr = Typed(expected_type=SchemeColor, allow_none=True) prstClr = NestedNoneSet(values=PRESET_COLORS) __elements__ = ('scrgbClr', 'srgbClr', 'hslClr', 'sysClr', 'schemeClr', 'prstClr') def __init__(self, scrgbClr=None, srgbClr=None, hslClr=None, sysClr=None, schemeClr=None, prstClr=None, ): self.scrgbClr = scrgbClr self.srgbClr = srgbClr self.hslClr = hslClr self.sysClr = sysClr self.schemeClr = schemeClr self.prstClr = prstClr
def test_tag_mismatch(self, NestedValue): xml = """ <length val="4"></length> """ node = fromstring(xml) with pytest.raises(ValueError): simple = NestedValue(size=node)
def test_from_tree(self, NestedValue): xml = """ <size val="4"></size> """ node = fromstring(xml) simple = NestedValue(size=node) assert simple.size == 4
class Simple(Serialisable): tagname = "simple" size = NestedValue(expected_type=int, attribute="something") def __init__(self, size): self.size = size
class Simple(Serialisable): tagname = "simple" size = NestedValue(expected_type=int) def __init__(self, size): self.size = size
def test_nested_from_tree(self, NestedValue): xml = """ <simple> <size val="4"/> </simple> """ node = fromstring(xml) obj = NestedValue.from_tree(node) assert obj.size == 4
def test_to_tree(self, NestedValue): simple = NestedValue(4) assert simple.size == 4 xml = tostring(NestedValue.size.to_tree("size", simple.size)) expected = """ <size val="4"></size> """ diff = compare_xml(xml, expected) assert diff is None, diff
class ParagraphProperties(Serialisable): tagname = "pPr" namespace = DRAWING_NS marL = Integer(allow_none=True) marR = Integer(allow_none=True) lvl = Integer(allow_none=True) indent = Integer(allow_none=True) algn = NoneSet(values=(['l', 'ctr', 'r', 'just', 'justLow', 'dist', 'thaiDist'])) defTabSz = Integer(expected_type=Coordinate, allow_none=True) rtl = Bool(allow_none=True) eaLnBrk = Bool(allow_none=True) fontAlgn = NoneSet(values=(['auto', 't', 'ctr', 'base', 'b'])) latinLnBrk = Bool(allow_none=True) hangingPunct = Bool(allow_none=True) # uses element group EG_TextBulletColor # uses element group EG_TextBulletSize # uses element group EG_TextBulletTypeface # uses element group EG_TextBullet lnSpc = Typed(expected_type=Spacing, allow_none=True) spcBef = Typed(expected_type=Spacing, allow_none=True) spcAft = Typed(expected_type=Spacing, allow_none=True) tabLst = Typed(expected_type=TabStopList, allow_none=True) defRPr = Typed(expected_type=CharacterProperties, allow_none=True) extLst = Typed(expected_type=OfficeArtExtensionList, allow_none=True) buClrTx = EmptyTag() buClr = Typed(expected_type=Color, allow_none=True) buSzTx = EmptyTag() buSzPct = NestedInteger(allow_none=True) buSzPts = NestedInteger(allow_none=True) buFontTx = EmptyTag() buFont = Typed(expected_type=Font, allow_none=True) buNone = EmptyTag() buAutoNum = EmptyTag() buChar = NestedValue(expected_type=unicode, attribute="char", allow_none=True) buBlip = NestedValue(expected_type=Blip, attribute="blip", allow_none=True) __elements__ = ('lnSpc', 'spcBef', 'spcAft', 'tabLst', 'defRPr', 'buClrTx', 'buClr', 'buSzTx', 'buSzPct', 'buSzPts', 'buFontTx', 'buFont', 'buNone', 'buAutoNum', 'buChar', 'buBlip') def __init__(self, marL=None, marR=None, lvl=None, indent=None, algn=None, defTabSz=None, rtl=None, eaLnBrk=None, fontAlgn=None, latinLnBrk=None, hangingPunct=None, lnSpc=None, spcBef=None, spcAft=None, tabLst=None, defRPr=None, extLst=None, buClrTx=None, buClr=None, buSzTx=None, buSzPct=None, buSzPts=None, buFontTx=None, buFont=None, buNone=None, buAutoNum=None, buChar=None, buBlip=None, ): self.marL = marL self.marR = marR self.lvl = lvl self.indent = indent self.algn = algn self.defTabSz = defTabSz self.rtl = rtl self.eaLnBrk = eaLnBrk self.fontAlgn = fontAlgn self.latinLnBrk = latinLnBrk self.hangingPunct = hangingPunct self.lnSpc = lnSpc self.spcBef = spcBef self.spcAft = spcAft self.tabLst = tabLst self.defRPr = defRPr self.buClrTx = buClrTx self.buClr = buClr self.buSzTx = buSzTx self.buSzPct = buSzPct self.buSzPts = buSzPts self.buFontTx = buFontTx self.buFont = buFont self.buNone = buNone self.buAutoNum = buAutoNum self.buChar = buChar self.buBlip = buBlip self.defRPr = defRPr