[REF]Yaltik DSL Test XML reindentation

This commit is contained in:
Fabien BOURGEOIS 2020-05-03 13:07:27 +02:00
parent 32dff3cce7
commit c48c086a0b
2 changed files with 82 additions and 82 deletions

View File

@ -24,109 +24,109 @@ from xml_base import xmln, xmlroot, xmlchild, xml_write
class TestXMLBase(unittest.TestCase):
""" XML Helpers tests """
""" XML Helpers tests """
def test_xmln(self):
# Tags
(xmln()._asdict(), {'tag': '', 'attrs': {}, 'children': []}) |*> self.assertEquals
(xmln <| 'a tag' |> getattr$(?, 'tag'), 'a tag') |*> self.assertEquals
def test_xmln(self):
# Tags
(xmln()._asdict(), {'tag': '', 'attrs': {}, 'children': []}) |*> self.assertEquals
(xmln <| 'a tag' |> getattr$(?, 'tag'), 'a tag') |*> self.assertEquals
# Attrs
(xmln(attrs={'a good': 'one'}).attrs, {'a good': 'one'}) |*> self.assertEquals
(xmln <**| {'attrs': {'a good': 'one'}} |> getattr$(?, 'attrs'), {'a good': 'one'}) |*> self.assertEquals
# Attrs
(xmln(attrs={'a good': 'one'}).attrs, {'a good': 'one'}) |*> self.assertEquals
(xmln <**| {'attrs': {'a good': 'one'}} |> getattr$(?, 'attrs'), {'a good': 'one'}) |*> self.assertEquals
# Childrens
attrs ={'children': [1, 2, 3]}
(xmln <**| attrs |> getattr$(?, 'children') == [1, 2, 3]) |> self.assertTrue
# Childrens
attrs ={'children': [1, 2, 3]}
(xmln <**| attrs |> getattr$(?, 'children') == [1, 2, 3]) |> self.assertTrue
attrs = {'children': 'Some text'}
(xmln <**| attrs |> getattr$(?, 'children') == ['Some text']) |> self.assertTrue
attrs = {'children': 'Some text'}
(xmln <**| attrs |> getattr$(?, 'children') == ['Some text']) |> self.assertTrue
with self.assertRaisesRegexp(TypeError, 'Invalid arguments'):
xmln <**| {'children': False}
with self.assertRaisesRegexp(TypeError, 'Invalid arguments'):
xmln <**| {'children': False}
# Ensure that only children after tags is managed
element = xmln <*| ('tag', {'something': 'inside'})
element.attrs `self.assertIsInstance` dict
element.children `self.assertIsInstance` list
# Ensure that only children after tags is managed
element = xmln <*| ('tag', {'something': 'inside'})
element.attrs `self.assertIsInstance` dict
element.children `self.assertIsInstance` list
element = xmln <*| ('tag', ['something', 'inside'])
element.attrs `self.assertIsInstance` dict
element.children `self.assertIsInstance` list
element = xmln <*| ('tag', ['something', 'inside'])
element.attrs `self.assertIsInstance` dict
element.children `self.assertIsInstance` list
def test_xmlchild(self):
parent = {'tag': 'root', 'attrs': {}, 'children': []} |> xmlroot
xmlc_par = xmlchild$ <| parent
def test_xmlchild(self):
parent = {'tag': 'root', 'attrs': {}, 'children': []} |> xmlroot
xmlc_par = xmlchild$ <| parent
# Bad arguments
with self.assertRaisesRegexp(TypeError, 'Invalid arguments for xmlchild'):
xmlc_par <| False
# Need XMLDictElement, not dict
with self.assertRaisesRegexp(TypeError, 'Invalid arguments for xmlchild'):
xmlc_par <| [{'tag': 't', 'attrs': {'a': 'b'}, 'children': []}]
# Bad arguments
with self.assertRaisesRegexp(TypeError, 'Invalid arguments for xmlchild'):
xmlc_par <| False
# Need XMLDictElement, not dict
with self.assertRaisesRegexp(TypeError, 'Invalid arguments for xmlchild'):
xmlc_par <| [{'tag': 't', 'attrs': {'a': 'b'}, 'children': []}]
xmlc_par <| ['some text']
parent.text `self.assertEquals` 'some text'
xmlc_par <| ['some text']
parent.text `self.assertEquals` 'some text'
xmlc_par <| [xmln <**| {'tag': 't', 'attrs': {'a': 'b'}, 'children': []}]
child = parent.iter <| 't' |> next
child.tag `self.assertEquals` 't'
child.attrib `self.assertEquals` {'a': 'b'}
(child |> list) `self.assertEquals` []
xmlc_par <| [xmln <**| {'tag': 't', 'attrs': {'a': 'b'}, 'children': []}]
child = parent.iter <| 't' |> next
child.tag `self.assertEquals` 't'
child.attrib `self.assertEquals` {'a': 'b'}
(child |> list) `self.assertEquals` []
xmlc_par <| [xmln <**| {'tag': 't2', 'attrs': {1: 2}, 'children': []}]
child = parent.iter <| 't2' |> next
child.attrib `self.assertEquals` {'1': '2'}
xmlc_par <| [xmln <**| {'tag': 't2', 'attrs': {1: 2}, 'children': []}]
child = parent.iter <| 't2' |> next
child.attrib `self.assertEquals` {'1': '2'}
xmlc_par <| [xmln <**| {'tag': 'tchildren', 'attrs': {},
'children': [xmln <**| {'tag': 'subchild', 'attrs': {}, 'children': []}]}]
child = parent.iter <| 'tchildren' |> next
subchildren = (child |> list)
(subchildren |> len) `self.assertEquals` 1
subchildren[0].tag `self.assertEquals` 'subchild'
xmlc_par <| [xmln <**| {'tag': 'tchildren', 'attrs': {},
'children': [xmln <**| {'tag': 'subchild', 'attrs': {}, 'children': []}]}]
child = parent.iter <| 'tchildren' |> next
subchildren = (child |> list)
(subchildren |> len) `self.assertEquals` 1
subchildren[0].tag `self.assertEquals` 'subchild'
def test_xmlroot(self):
root = {'tag': 'root', 'attrs': {}, 'children': []} |> xmlroot
isinstance <*| (root, ET.Element) |> self.assertTrue
def test_xmlroot(self):
root = {'tag': 'root', 'attrs': {}, 'children': []} |> xmlroot
isinstance <*| (root, ET.Element) |> self.assertTrue
with self.assertRaisesRegexp(TypeError, 'has no attribute'):
False |> xmlroot
with self.assertRaisesRegexp(KeyError, 'tag'):
{} |> xmlroot
with self.assertRaisesRegexp(KeyError, 'attrs'):
{'tag': 'root'} |> xmlroot
with self.assertRaisesRegexp(TypeError, 'has no attribute'):
False |> xmlroot
with self.assertRaisesRegexp(KeyError, 'tag'):
{} |> xmlroot
with self.assertRaisesRegexp(KeyError, 'attrs'):
{'tag': 'root'} |> xmlroot
def test_xml_write(self):
children = [('child1', {'attr': 'value'}, []) |*> xmln,
('child2', {}, "Some text") |*> xmln]
tree = xmlroot({'tag': 'root', 'attrs': {}, 'children': children})
xmlw = xml_write$(?, tree)
def test_xml_write(self):
children = [('child1', {'attr': 'value'}, []) |*> xmln,
('child2', {}, "Some text") |*> xmln]
tree = xmlroot({'tag': 'root', 'attrs': {}, 'children': children})
xmlw = xml_write$(?, tree)
('/badpath' |> xmlw) `self.assertEquals` None
('/bad.ext' |> xmlw) `self.assertEquals` None
('/badpath' |> xmlw) `self.assertEquals` None
('/bad.ext' |> xmlw) `self.assertEquals` None
xmlw(__file__) # Default to pretty
filepath = __file__.replace('.py', '_views.xml')
with open(filepath, 'r') as output_file:
output_xml = output_file.read()
'<?xml version' `self.assertIn` output_xml
'<root>' `self.assertIn` output_xml
'<child1 attr="value"/>' `self.assertIn` output_xml
'<child2>Some text</child2>' `self.assertIn` output_xml
unlink(filepath)
xmlw(__file__) # Default to pretty
filepath = __file__.replace('.py', '_views.xml')
with open(filepath, 'r') as output_file:
output_xml = output_file.read()
'<?xml version' `self.assertIn` output_xml
'<root>' `self.assertIn` output_xml
'<child1 attr="value"/>' `self.assertIn` output_xml
'<child2>Some text</child2>' `self.assertIn` output_xml
unlink(filepath)
xmlw(__file__, pretty=False)
filepath = __file__.replace('.py', '_views.xml')
with open(filepath, 'r') as output_file:
output_xml = output_file.read()
'<?xml version' `self.assertNotIn` output_xml
'<root>' `self.assertIn` output_xml
'<child1 attr="value" />' `self.assertIn` output_xml
'<child2>Some text</child2>' `self.assertIn` output_xml
unlink(filepath)
xmlw(__file__, pretty=False)
filepath = __file__.replace('.py', '_views.xml')
with open(filepath, 'r') as output_file:
output_xml = output_file.read()
'<?xml version' `self.assertNotIn` output_xml
'<root>' `self.assertIn` output_xml
'<child1 attr="value" />' `self.assertIn` output_xml
'<child2>Some text</child2>' `self.assertIn` output_xml
unlink(filepath)
if __name__ == '__main__':
unittest.main()

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# __coconut_hash__ = 0x470897d2
# __coconut_hash__ = 0x731dbc72
# Compiled with Coconut version 1.4.3 [Ernest Scribbler]