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

View File

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