[IMP]Yaltik DSL : tests, use asserRaises instead of try

This commit is contained in:
Fabien BOURGEOIS 2020-05-01 18:44:24 +02:00
parent 8859a4b340
commit 4938cec43d
2 changed files with 15 additions and 53 deletions

View File

@ -42,10 +42,8 @@ class TestXMLBase(unittest.TestCase):
attrs = {'children': 'Some text'} attrs = {'children': 'Some text'}
(xmln <**| attrs |> getattr$(?, 'children') == ['Some text']) |> self.assertTrue (xmln <**| attrs |> getattr$(?, 'children') == ['Some text']) |> self.assertTrue
try: with self.assertRaisesRegexp(TypeError, 'Invalid arguments'):
xmln <**| {'children': False} xmln <**| {'children': False}
except TypeError as err:
('Invalid arguments', err.message) |*> self.assertIn
def test_xmlchild(self): def test_xmlchild(self):
@ -53,18 +51,11 @@ class TestXMLBase(unittest.TestCase):
xmlc_par = xmlchild$ <| parent xmlc_par = xmlchild$ <| parent
# Bad arguments # Bad arguments
try: with self.assertRaisesRegexp(TypeError, 'Invalid arguments for xmlchild'):
xmlc_par <| False xmlc_par <| False
except TypeError as err: # Need XMLDictElement, not dict
'Invalid arguments for xmlchild' `self.assertIn` err.message with self.assertRaisesRegexp(TypeError, 'Invalid arguments for xmlchild'):
try:
xmlc_par <| []
except TypeError as err:
'Invalid arguments for xmlchild' `self.assertIn` err.message
try: # Need XMLDictElement, not dict
xmlc_par <| [{'tag': 't', 'attrs': {'a': 'b'}, 'children': []}] xmlc_par <| [{'tag': 't', 'attrs': {'a': 'b'}, 'children': []}]
except TypeError as err:
'Invalid arguments for xmlchild' `self.assertIn` err.message
xmlc_par <| ['some text'] xmlc_par <| ['some text']
parent.text `self.assertEquals` 'some text' parent.text `self.assertEquals` 'some text'
@ -91,22 +82,12 @@ class TestXMLBase(unittest.TestCase):
root = {'tag': 'root', 'attrs': {}, 'children': []} |> xmlroot root = {'tag': 'root', 'attrs': {}, 'children': []} |> xmlroot
isinstance <*| (root, ET.Element) |> self.assertTrue isinstance <*| (root, ET.Element) |> self.assertTrue
try: with self.assertRaisesRegexp(TypeError, 'has no attribute'):
False |> xmlroot False |> xmlroot
except TypeError as err: with self.assertRaisesRegexp(KeyError, 'tag'):
('has no attribute', err.message) |*> self.assertIn
try:
{} |> xmlroot {} |> xmlroot
except KeyError as err: with self.assertRaisesRegexp(KeyError, 'attrs'):
('tag', err.message) |*> self.assertIn
try:
{'tag': 'root'} |> xmlroot {'tag': 'root'} |> xmlroot
except KeyError as err:
('attrs', err.message) |*> self.assertIn
try:
{'tag': 'root', 'attrs': {}} |> xmlroot
except KeyError as err:
('children', err.message) |*> self.assertIn
def test_xml_write(self): def test_xml_write(self):

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python2 #!/usr/bin/env python2
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# __coconut_hash__ = 0xb50857dd # __coconut_hash__ = 0xd35c4ffa
# Compiled with Coconut version 1.4.3 [Ernest Scribbler] # Compiled with Coconut version 1.4.3 [Ernest Scribbler]
@ -68,10 +68,8 @@ class TestXMLBase(unittest.TestCase):
attrs = {'children': 'Some text'} attrs = {'children': 'Some text'}
(self.assertTrue)(((_coconut_partial(getattr, {1: 'children'}, 2))((xmln)(**attrs)) == ['Some text'])) (self.assertTrue)(((_coconut_partial(getattr, {1: 'children'}, 2))((xmln)(**attrs)) == ['Some text']))
try: with self.assertRaisesRegexp(TypeError, 'Invalid arguments'):
(xmln)(**{'children': False}) (xmln)(**{'children': False})
except TypeError as err:
(self.assertIn)(*('Invalid arguments', err.message))
def test_xmlchild(self): def test_xmlchild(self):
@ -79,18 +77,11 @@ class TestXMLBase(unittest.TestCase):
xmlc_par = (_coconut.functools.partial(_coconut.functools.partial, xmlchild))(parent) xmlc_par = (_coconut.functools.partial(_coconut.functools.partial, xmlchild))(parent)
# Bad arguments # Bad arguments
try: with self.assertRaisesRegexp(TypeError, 'Invalid arguments for xmlchild'):
(xmlc_par)(False) (xmlc_par)(False)
except TypeError as err: # Need XMLDictElement, not dict
(self.assertIn)('Invalid arguments for xmlchild', err.message) with self.assertRaisesRegexp(TypeError, 'Invalid arguments for xmlchild'):
try:
(xmlc_par)([])
except TypeError as err:
(self.assertIn)('Invalid arguments for xmlchild', err.message)
try: # Need XMLDictElement, not dict
(xmlc_par)([{'tag': 't', 'attrs': {'a': 'b'}, 'children': []}]) (xmlc_par)([{'tag': 't', 'attrs': {'a': 'b'}, 'children': []}])
except TypeError as err:
(self.assertIn)('Invalid arguments for xmlchild', err.message)
(xmlc_par)(['some text']) (xmlc_par)(['some text'])
(self.assertEquals)(parent.text, 'some text') (self.assertEquals)(parent.text, 'some text')
@ -116,22 +107,12 @@ class TestXMLBase(unittest.TestCase):
root = (xmlroot)({'tag': 'root', 'attrs': {}, 'children': []}) root = (xmlroot)({'tag': 'root', 'attrs': {}, 'children': []})
(self.assertTrue)((isinstance)(*(root, ET.Element))) (self.assertTrue)((isinstance)(*(root, ET.Element)))
try: with self.assertRaisesRegexp(TypeError, 'has no attribute'):
(xmlroot)(False) (xmlroot)(False)
except TypeError as err: with self.assertRaisesRegexp(KeyError, 'tag'):
(self.assertIn)(*('has no attribute', err.message))
try:
(xmlroot)({}) (xmlroot)({})
except KeyError as err: with self.assertRaisesRegexp(KeyError, 'attrs'):
(self.assertIn)(*('tag', err.message))
try:
(xmlroot)({'tag': 'root'}) (xmlroot)({'tag': 'root'})
except KeyError as err:
(self.assertIn)(*('attrs', err.message))
try:
(xmlroot)({'tag': 'root', 'attrs': {}})
except KeyError as err:
(self.assertIn)(*('children', err.message))
def test_xml_write(self): def test_xml_write(self):