My favorites | Sign in
Project Home Downloads Wiki Issues Source
Repository:
Checkout   Browse   Changes   Clones  
Changes to /src/lepl/_test/error.py
a30b0eaff6f7 vs. 67579ff784f3 Compare: vs.  Format:
Revision 67579ff784f3
Go to: 
Project members, sign in to write a code review
/src/lepl/_test/error.py   a30b0eaff6f7 /src/lepl/_test/error.py   67579ff784f3
1 1
2 # Copyright 2009 Andrew Cooke 2 # Copyright 2009 Andrew Cooke
3 3
4 # This file is part of LEPL. 4 # This file is part of LEPL.
5 # 5 #
6 # LEPL is free software: you can redistribute it and/or modify 6 # LEPL is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Lesser General Public License as published 7 # it under the terms of the GNU Lesser General Public License as published
8 # by the Free Software Foundation, either version 3 of the License, or 8 # by the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version. 9 # (at your option) any later version.
10 # 10 #
11 # LEPL is distributed in the hope that it will be useful, 11 # LEPL is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU Lesser General Public License for more details. 14 # GNU Lesser General Public License for more details.
15 # 15 #
16 # You should have received a copy of the GNU Lesser General Public License 16 # You should have received a copy of the GNU Lesser General Public License
17 # along with LEPL. If not, see <http://www.gnu.org/licenses/>. 17 # along with LEPL. If not, see <http://www.gnu.org/licenses/>.
18 18
19 ''' 19 '''
20 Tests for the lepl.error module. 20 Tests for the lepl.error module.
21 ''' 21 '''
22 22
23 from unittest import TestCase 23 from unittest import TestCase
24 24
25 from lepl import Literal, Error 25 from lepl import Literal, Error
26 from lepl.error import make_error 26 from lepl.error import make_error
27 27
28 28
29 # pylint: disable-msg=C0103, C0111, C0301, W0702, C0324, C0102, C0321, W0141 29 # pylint: disable-msg=C0103, C0111, C0301, W0702, C0324, C0102, C0321, W0141, R0201
30 # (dude this is just a test) 30 # (dude this is just a test)
31 31
32 32
33 class MessageTest(TestCase): 33 class MessageTest(TestCase):
34 ''' 34 '''
35 Check generation of Error nodes. 35 Check generation of Error nodes.
36 ''' 36 '''
37 37
38 def test_simple(self): 38 def test_simple(self):
39 ''' 39 '''
40 Test a message with no formatting. 40 Test a message with no formatting.
41 ''' 41 '''
42 parser = (Literal('abc') > 'name') ** make_error('msg') 42 parser = (Literal('abc') > 'name') ** make_error('msg')
43 node = parser.parse('abc')[0] 43 node = parser.parse('abc')[0]
44 assert isinstance(node, Error) 44 assert isinstance(node, Error)
45 assert node[0] == 'abc', node[0] 45 assert node[0] == 'abc', node[0]
46 assert node.name == ['abc'], node.name 46 assert node.name == ['abc'], node.name
47 assert str(node).startswith('msg ('), str(node) 47 assert str(node).startswith('msg ('), str(node)
48 assert isinstance(node, Exception), type(node) 48 assert isinstance(node, Exception), type(node)
49 49
50 def test_formatted(self): 50 def test_formatted(self):
51 ''' 51 '''
52 Test a message with formatting. 52 Test a message with formatting.
53 ''' 53 '''
54 parser = (Literal('abc') > 'name') ** make_error('msg {stream_in}') 54 parser = (Literal('abc') > 'name') ** make_error('msg {stream_in}')
55 node = parser.parse('abc')[0] 55 node = parser.parse('abc')[0]
56 assert isinstance(node, Error) 56 assert isinstance(node, Error)
57 assert node[0] == 'abc', node[0] 57 assert node[0] == 'abc', node[0]
58 assert node.name == ['abc'], node.name 58 assert node.name == ['abc'], node.name
59 assert str(node).startswith('msg abc ('), str(node) 59 assert str(node).startswith('msg abc ('), str(node)
60 assert isinstance(node, Exception), type(node) 60 assert isinstance(node, Exception), type(node)
61 61
62 def test_bad_format(self): 62 def test_bad_format(self):
63 ''' 63 '''
64 Test a message with formatting. 64 Test a message with formatting.
65 ''' 65 '''
66 parser = (Literal('abc') > 'name') ** make_error('msg {0}') 66 parser = (Literal('abc') > 'name') ** make_error('msg {0}')
67 assert None == parser.parse('abc') 67 assert None == parser.parse('abc')
68 68
69 def test_list(self): 69 def test_list(self):
70 ''' 70 '''
71 Code has an exception for handling lists. 71 Code has an exception for handling lists.
72 ''' 72 '''
73 parser = (Literal([1, 2, 3]) > 'name') ** make_error('msg {stream_in}') 73 parser = (Literal([1, 2, 3]) > 'name') ** make_error('msg {stream_in}')
74 node = parser.parse([1, 2, 3])[0] 74 node = parser.parse([1, 2, 3])[0]
75 assert isinstance(node, Error) 75 assert isinstance(node, Error)
76 assert node[0] == [1, 2, 3], node[0] 76 assert node[0] == [1, 2, 3], node[0]
77 assert node.name == [[1, 2, 3]], node.name 77 assert node.name == [[1, 2, 3]], node.name
78 assert str(node).startswith('msg [1, 2, 3] ('), str(node) 78 assert str(node).startswith('msg [1, 2, 3] ('), str(node)
79 assert isinstance(node, Exception), type(node) 79 assert isinstance(node, Exception), type(node)
80 80
Powered by Google Project Hosting