コード例 #1
0
 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')
コード例 #2
0
 def test_serialization(self):
     obj = self.make_example()
     xml_elt = X.serialize(obj, 'fancy-rect')
     xml_str = to_unicode(xml_elt)
     exp_str = remove_whitespace(
         '''<fancy-rect>
              <width>99</width>
              <height>100</height>
              <colour>red</colour>
              <stripes>3,4,5</stripes>
            </fancy-rect>''')
     assert xml_str == exp_str
コード例 #3
0
    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