Exemple #1
0
    def test_add_elem(self):
        # tag name
        parent = new_elem('foo')
        add_elem(parent, 'bar', a='100', b='200', attrib=dict(c="300"))
        self.assertEqual(to_xml(parent),
                         '<foo><bar a="100" b="200" c="300" /></foo>')

        # element
        parent = new_elem('foo')
        add_elem(parent,
                 new_elem('bar', a='100', b='200'),
                 attrib=dict(c="300"),
                 other='value')
        self.assertEqual(
            to_xml(parent),
            '<foo><bar a="100" b="200" c="300" other="value" /></foo>')

        # XML
        parent = new_elem('foo')
        add_elem(parent,
                 '<bar b="200" a="100" />',
                 attrib=dict(c="300"),
                 other='value')
        self.assertEqual(
            to_xml(parent),
            '<foo><bar a="100" b="200" c="300" other="value" /></foo>')
    def test_add_elem(self):
        # tag name
        parent = new_elem('foo')
        add_elem(parent, 'bar', a='100', b='200', attrib=dict(c="300"))
        self.assertEqual(to_xml(parent), '<foo><bar a="100" b="200" c="300" /></foo>')

        # element
        parent = new_elem('foo')
        add_elem(parent, new_elem('bar', a='100', b='200'), attrib=dict(c="300"), other='value')
        self.assertEqual(to_xml(parent), '<foo><bar a="100" b="200" c="300" other="value" /></foo>')

        # XML
        parent = new_elem('foo')
        add_elem(parent, '<bar b="200" a="100" />', attrib=dict(c="300"), other='value')
        self.assertEqual(to_xml(parent), '<foo><bar a="100" b="200" c="300" other="value" /></foo>')
Exemple #3
0
    def test_to_element(self):
        win = self.query['w_data']
        elem = win.to_element()
        out = xml.to_xml(elem, pretty=True)
        self.assertEqual(
            out.strip(),
            '''<window-source index="pi_EMPTY" insert-only="true" name="w_data">
  <schema>
    <fields>
      <field key="true" name="id" type="int64" />
      <field key="false" name="x_c" type="double" />
      <field key="false" name="y_c" type="double" />
    </fields>
  </schema>
  <connectors>
    <connector class="fs" name="publisher" type="publish">
      <properties>
        <property name="blocksize">1</property>
        <property name="fsname">/u/kesmit/gitlab/python-esp/esppy/tests/data//data_sa.csv</property>
        <property name="fstype">csv</property>
        <property name="transactional">true</property>
      </properties>
    </connector>
  </connectors>
</window-source>''')
    def test_new_elem(self):
        # empty
        elem = new_elem('foo')
        self.assertEqual(to_xml(elem), '<foo />')

        # With attributes
        elem = new_elem('foo', attrib=dict(a='100', b='200'))
        self.assertEqual(to_xml(elem), '<foo a="100" b="200" />')

        # With text content
        elem = new_elem('foo', attrib=dict(a='100', b='200'), text_content='Hi')
        self.assertEqual(to_xml(elem), '<foo a="100" b="200">Hi</foo>')

        # With keyword parameters
        elem = new_elem('foo', attrib=dict(a='100', b='200'), other='value')
        self.assertEqual(to_xml(elem), '<foo a="100" b="200" other="value" />')
 def test_xml_indent(self):
     a = new_elem('a', x='100', y='200')
     b = new_elem('b', m='1000', n='2000')
     c = new_elem('c', text_content='Hi')
     add_elem(a, b)
     add_elem(b, c)
     xml_indent(a)
     self.assertEqual(to_xml(a), '<a x="100" y="200">\n  <b m="1000" n="2000">\n    <c>Hi</c>\n  </b>\n</a>\n')
Exemple #6
0
    def test_new_elem(self):
        # empty
        elem = new_elem('foo')
        self.assertEqual(to_xml(elem), '<foo />')

        # With attributes
        elem = new_elem('foo', attrib=dict(a='100', b='200'))
        self.assertEqual(to_xml(elem), '<foo a="100" b="200" />')

        # With text content
        elem = new_elem('foo',
                        attrib=dict(a='100', b='200'),
                        text_content='Hi')
        self.assertEqual(to_xml(elem), '<foo a="100" b="200">Hi</foo>')

        # With keyword parameters
        elem = new_elem('foo', attrib=dict(a='100', b='200'), other='value')
        self.assertEqual(to_xml(elem), '<foo a="100" b="200" other="value" />')
Exemple #7
0
 def test_xml_indent(self):
     a = new_elem('a', x='100', y='200')
     b = new_elem('b', m='1000', n='2000')
     c = new_elem('c', text_content='Hi')
     add_elem(a, b)
     add_elem(b, c)
     xml_indent(a)
     self.assertEqual(
         to_xml(a),
         '<a x="100" y="200">\n  <b m="1000" n="2000">\n    <c>Hi</c>\n  </b>\n</a>\n'
     )
    def test_to_xml(self):
        a = new_elem('a', x='100', y='200')
        b = new_elem('b', m='1000', n='2000')
        c = new_elem('c', text_content='Hi')
        add_elem(a, b)
        add_elem(b, c)
        self.assertEqual(to_xml(a), '<a x="100" y="200"><b m="1000" n="2000"><c>Hi</c></b></a>')

        a = new_elem('a', x='100', y='200')
        b = new_elem('b', m='1000', n='2000')
        c = new_elem('c', text_content='Hi')
        add_elem(a, b)
        add_elem(b, c)
        self.assertEqual(to_xml(a, pretty=True), '<a x="100" y="200">\n  <b m="1000" n="2000">\n    <c>Hi</c>\n  </b>\n</a>\n')

        a = new_elem('a', x='100', y='200')
        b = new_elem('b', m='1000', n='2000')
        c = new_elem('c', text_content='Hi')
        add_elem(a, b)
        add_elem(b, c)
        self.assertEqual(to_xml(to_xml(a), pretty=True), '<a x="100" y="200">\n  <b m="1000" n="2000">\n    <c>Hi</c>\n  </b>\n</a>\n')

        a = new_elem('a', x='100', y='200')
        b = new_elem('b', m='1000', n='2000')
        c = new_elem('c', text_content='Hi')
        add_elem(a, b)
        add_elem(b, c)
        print(to_xml(a, encoding='ascii'))
        self.assertEqual(to_xml(a, encoding='ascii'), b'<?xml version=\'1.0\' encoding=\'ascii\'?>\n<a x="100" y="200"><b m="1000" n="2000"><c>Hi</c></b></a>')
    def test_to_element(self):
        win = self.query['w_data']
        elem = win.to_element()
        out = xml.to_xml(elem, pretty=True)
        self.assertEqual(out.strip(), '''<window-source index="pi_EMPTY" insert-only="true" name="w_data">
  <schema>
    <fields>
      <field key="true" name="id" type="int64" />
      <field key="false" name="x_c" type="double" />
      <field key="false" name="y_c" type="double" />
    </fields>
  </schema>
  <connectors>
    <connector class="fs" name="publisher" type="publish">
      <properties>
        <property name="blocksize">1</property>
        <property name="fsname">/u/kesmit/gitlab/python-esp/esppy/tests/data//data_sa.csv</property>
        <property name="fstype">csv</property>
        <property name="transactional">true</property>
      </properties>
    </connector>
  </connectors>
</window-source>''')
Exemple #10
0
    def test_to_xml(self):
        a = new_elem('a', x='100', y='200')
        b = new_elem('b', m='1000', n='2000')
        c = new_elem('c', text_content='Hi')
        add_elem(a, b)
        add_elem(b, c)
        self.assertEqual(
            to_xml(a),
            '<a x="100" y="200"><b m="1000" n="2000"><c>Hi</c></b></a>')

        a = new_elem('a', x='100', y='200')
        b = new_elem('b', m='1000', n='2000')
        c = new_elem('c', text_content='Hi')
        add_elem(a, b)
        add_elem(b, c)
        self.assertEqual(
            to_xml(a, pretty=True),
            '<a x="100" y="200">\n  <b m="1000" n="2000">\n    <c>Hi</c>\n  </b>\n</a>\n'
        )

        a = new_elem('a', x='100', y='200')
        b = new_elem('b', m='1000', n='2000')
        c = new_elem('c', text_content='Hi')
        add_elem(a, b)
        add_elem(b, c)
        self.assertEqual(
            to_xml(to_xml(a), pretty=True),
            '<a x="100" y="200">\n  <b m="1000" n="2000">\n    <c>Hi</c>\n  </b>\n</a>\n'
        )

        a = new_elem('a', x='100', y='200')
        b = new_elem('b', m='1000', n='2000')
        c = new_elem('c', text_content='Hi')
        add_elem(a, b)
        add_elem(b, c)
        print(to_xml(a, encoding='ascii'))
        self.assertEqual(
            to_xml(a, encoding='ascii'),
            b'<?xml version=\'1.0\' encoding=\'ascii\'?>\n<a x="100" y="200"><b m="1000" n="2000"><c>Hi</c></b></a>'
        )
Exemple #11
0
 def test_to_element(self):
     before_xml = self.project.to_xml(pretty=True)
     after_xml = xml.to_xml(self.project.to_element(), pretty=True)
     self.assertEqual(before_xml, after_xml)