def test_1(self):
     layout = Layout('dark-blue',
                     [['rounded', 'red'],
                      ['chamfered', 'matt'],
                      ['pointy', 'anodized', 'black'],
                      ['bevelled', 'twisted', 'plastic-coated']],
                     ['red', 'burnt-ochre', 'orange'],
                     np.array([99, 42, 123], dtype=np.uint32),
                     Rectangle(210, 297),
                     np.array([(20, 30), (40, 50)], dtype=RectangleDType))
     xml = X.serialize(layout, 'layout')
     xml_str = XU.str_from_xml_elt(xml)
     expected_str = remove_whitespace(
         """<layout>
              <colour>dark-blue</colour>
              <corner-properties>
                <corner>
                  <prop>rounded</prop>
                  <prop>red</prop>
                </corner>
                <corner>
                  <prop>chamfered</prop>
                  <prop>matt</prop>
                </corner>
                <corner>
                  <prop>pointy</prop>
                  <prop>anodized</prop>
                  <prop>black</prop>
                </corner>
                <corner>
                  <prop>bevelled</prop>
                  <prop>twisted</prop>
                  <prop>plastic-coated</prop>
                </corner>
              </corner-properties>
              <stripes>
                <stripe-colour>red</stripe-colour>
                <stripe-colour>burnt-ochre</stripe-colour>
                <stripe-colour>orange</stripe-colour>
              </stripes>
              <product-id-codes>99,42,123</product-id-codes>
              <shape>
                <width>210</width>
                <height>297</height>
              </shape>
              <components>
                <rect>
                  <width>20</width>
                  <height>30</height>
                </rect>
                <rect>
                  <width>40</width>
                  <height>50</height>
                </rect>
              </components>
            </layout>""")
     assert xml_str == expected_str
     X.deserialize(Layout, xml, 'layout')
Exemplo n.º 2
0
 def test_deserialization(self):
     xml_str = '''<fancy-rect>
                    <width>42</width>
                    <height>99</height>
                    <colour>blue</colour>
                    <stripes>30,40,50</stripes>
                  </fancy-rect>'''
     xml_elt = etree.fromstring(xml_str)
     obj = X.deserialize(self.FancyRectangle, xml_elt, 'fancy-rect')
     assert obj.width == 42
     assert obj.height == 99
     assert obj.colour == 'blue'
     assert obj.stripes.dtype is np.dtype(np.uint8)
     assert obj.stripes.size == 3
     assert np.all(obj.stripes == np.array([30, 40, 50], dtype=np.uint8))
 def test_bad_input(self, xml_str, des_tag, exc_re, exp_xpath):
     bad_xml = etree.fromstring(xml_str)
     with pytest.raises_regexp(XMLSerDesError, exc_re, exp_xpath):
         X.deserialize(Rectangle, bad_xml, des_tag)
    def test_1(self):
        serialized_xml = X.serialize(self.rect, 'rect')
        assert XU.str_from_xml_elt(serialized_xml) == expected_rect_xml(42, 123)

        rect_round_trip = X.deserialize(Rectangle, serialized_xml, 'rect')
        assert rect_round_trip == self.rect