/
test_dbgp_api.py
180 lines (162 loc) · 7.15 KB
/
test_dbgp_api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
if __name__ == "__main__":
import sys
sys.path.append('../plugin/python/')
import unittest
import vdebug.dbgp
from mock import MagicMock, patch
class ApiTest(unittest.TestCase):
"""Test the Api class in the vdebug.dbgp module."""
init_msg = """<?xml version="1.0"
encoding="iso-8859-1"?>\n<init
xmlns="urn:debugger_api_v1"
xmlns:xdebug="http://xdebug.org/dbgp/xdebug"
fileuri="file:///usr/local/bin/cake" language="PHP"
api_version="1.0" appid="30130"
idekey="netbeans-xdebug"><engine
version="2.2.0"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick
Rethans]]></author><url><![CDATA[http://xdebug.org]]></url><copyright><![CDATA[Copyright
(c) 2002-2012 by Derick
Rethans]]></copyright></init>"""
def setUp(self):
with patch('vdebug.dbgp.Connection') as c:
self.c = c.return_value
self.c.recv_msg.return_value = self.init_msg
self.c.isconnected.return_value = 1
self.p = vdebug.dbgp.Api(self.c)
def test_init_msg_parsed(self):
"""Test that the init message from the debugger is
parsed successfully"""
assert self.p.language == "php"
assert self.p.version == "1.0"
assert self.p.idekey == "netbeans-xdebug"
def test_status_send_adds_trans_id(self):
"""Test that the status command sends the right
format command and adds a transaction ID"""
self.p.conn.send_msg = MagicMock()
self.p.status()
self.p.conn.send_msg.assert_called_once_with('status -i 1')
def test_status_retval(self):
"""Test that the status command receives a message from the api."""
self.p.conn.recv_msg.return_value = """<?xml
version="1.0" encoding="iso-8859-1"?>\n
<response command="status"
xmlns="urn:debugger_api_v1"
status="starting"
reason="ok"
transaction_id="transaction_id">
message data
</response>"""
status_res = self.p.status()
assert str(status_res) == "starting"
def test_run_retval(self):
"""Test that the run command receives a message from the api."""
self.p.conn.recv_msg.return_value = """<?xml
version="1.0" encoding="iso-8859-1"?>\n
<response command="run"
xmlns="urn:debugger_api_v1"
status="running"
reason="ok"
transaction_id="transaction_id">
message data
</response>"""
status_res = self.p.run()
assert str(status_res) == "running"
def test_step_into_retval(self):
"""Test that the step_into command receives a message from the api."""
self.p.conn.recv_msg.return_value = """<?xml
version="1.0" encoding="iso-8859-1"?>\n
<response command="step_into"
xmlns="urn:debugger_api_v1"
status="break"
reason="ok"
transaction_id="transaction_id">
message data
</response>"""
status_res = self.p.run()
assert str(status_res) == "break"
def test_step_over_retval(self):
"""Test that the step_over command receives a message from the api."""
self.p.conn.recv_msg.return_value = """<?xml
version="1.0" encoding="iso-8859-1"?>\n
<response command="step_into"
xmlns="urn:debugger_api_v1"
status="break"
reason="ok"
transaction_id="transaction_id">
message data
</response>"""
status_res = self.p.run()
assert str(status_res) == "break"
def test_step_out_retval(self):
"""Test that the step_out command receives a message from the api."""
self.p.conn.recv_msg.return_value = """<?xml
version="1.0" encoding="iso-8859-1"?>\n
<response command="step_into"
xmlns="urn:debugger_api_v1"
status="break"
reason="ok"
transaction_id="transaction_id">
message data
</response>"""
status_res = self.p.run()
assert str(status_res) == "break"
def test_stop_retval(self):
"""Test that the stop command receives a message from the api."""
self.p.conn.recv_msg.return_value = """<?xml
version="1.0" encoding="iso-8859-1"?>\n
<response command="stop"
xmlns="urn:debugger_api_v1"
status="stopping"
reason="ok"
transaction_id="transaction_id">
message data
</response>"""
status_res = self.p.run()
assert str(status_res) == "stopping"
def test_detatch_retval(self):
"""Test that the detatch command receives a message from the api."""
self.p.conn.recv_msg.return_value = """<?xml
version="1.0" encoding="iso-8859-1"?>\n
<response command="detatch"
xmlns="urn:debugger_api_v1"
status="stopped"
reason="ok"
transaction_id="transaction_id">
message data
</response>"""
status_res = self.p.run()
assert str(status_res) == "stopped"
def test_feature_get_retval(self):
"""Test that the feature_get command receives a message from the api."""
self.p.conn.recv_msg.return_value = """<?xml
version="1.0" encoding="iso-8859-1"?>\n<response
xmlns="urn:debugger_api_v1"
xmlns:xdebug="http://xdebug.org/dbgp/xdebug"
command="feature_get" transaction_id="2"
feature_name="encoding"
supported="1"><![CDATA[iso-8859-1]]></response>"""
res = self.p.feature_get('encoding')
self.assertEqual(str(res),"iso-8859-1")
self.assertEqual(res.is_supported(),1)
class apiInvalidInitTest(unittest.TestCase):
init_msg = """<?xml version="1.0"
encoding="iso-8859-1"?>\n<init
xmlns="urn:debugger_api_v1"
xmlns:xdebug="http://xdebug.org/dbgp/xdebug"
fileuri="file:///usr/local/bin/cake" language="PHP"
api_version="1.0" appid="30130"
idekey="netbeans-xdebug"><engine
version="2.2.0"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick
Rethans]]></author><url><![CDATA[http://xdebug.org]]></url><copyright><![CDATA[Copyright
(c) 2002-2012 by Derick
Rethans]]></copyright></init>"""
invalid_init_msg = """<?xml version="1.0"
encoding="iso-8859-1"?>\n<invalid
xmlns="urn:debugger_api_v1">\n</invalid>"""
def test_invalid_response_raises_error(self):
with patch('vdebug.dbgp.Connection') as c:
c = c.return_value
c.recv_msg.return_value = self.invalid_init_msg
c.isconnected.return_value = 1
re = "Invalid XML response from debugger"
self.assertRaisesRegexp(vdebug.dbgp.ResponseError,re,vdebug.dbgp.Api,c)