Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added test for context property

  • Loading branch information...
commit 6b98a573f88b7c29636ef6a6d4a3f368ea6367c1 1 parent 7a3cfc0
@joonty authored
View
56 plugin/python/dbgp.py
@@ -76,14 +76,20 @@ def get_stack(self):
return self.as_xml().getchildren()
class ContextGetResponse(Response):
- """Response object used by the context_get command."""
- properties = []
+ """Response object used by the context_get command.
+
+ The property nodes are converted into ContextProperty
+ objects, which are much easier to use."""
+
+ def __init__(self,response,cmd,cmd_args):
+ Response.__init__(self,response,cmd,cmd_args)
+ self.properties = []
def get_context(self):
for c in self.as_xml().getchildren():
self.__create_properties(ContextProperty(c))
- return self.as_xml().getchildren()
+ return self.properties
def __create_properties(self,property):
self.properties.append(property)
@@ -226,7 +232,7 @@ def feature_set(self,name,value):
def run(self):
"""Tell the debugger to start or resume
execution."""
- return self.send_cmd('run','',Response)
+ return self.send_cmd('run','',StatusResponse)
def step_into(self):
"""Tell the debugger to step to the next
@@ -235,7 +241,7 @@ def step_into(self):
If there's a function call, the debugger engine
will break on the first statement in the function.
"""
- return self.send_cmd('step_into','',Response)
+ return self.send_cmd('step_into','',StatusResponse)
def step_over(self):
"""Tell the debugger to step to the next
@@ -244,20 +250,20 @@ def step_over(self):
If there's a function call, the debugger engine
will stop at the next statement after the function call.
"""
- return self.send_cmd('step_over','',Response)
+ return self.send_cmd('step_over','',StatusResponse)
def step_out(self):
"""Tell the debugger to step out of the statement.
The debugger will step out of the current scope.
"""
- return self.send_cmd('step_out','',Response)
+ return self.send_cmd('step_out','',StatusResponse)
def stop(self):
"""Tell the debugger to stop execution.
The script is terminated immediately."""
- return self.send_cmd('stop','',Response)
+ return self.send_cmd('stop','',StatusResponse)
def stack_get(self):
"""Get the stack information.
@@ -280,7 +286,7 @@ def detach(self):
The script is not terminated, but runs as normal
from this point."""
- return self.send_cmd('detach','',Response)
+ return self.send_cmd('detach','',StatusResponse)
def breakpoint_set(self,cmd_args):
"""Set a breakpoint.
@@ -422,6 +428,8 @@ def send_msg(self, cmd):
class ContextProperty:
+ ns = '{urn:debugger_protocol_v1}'
+
def __init__(self,node,parent = None,depth = 0):
self.parent = parent
self.__determine_type(node)
@@ -460,10 +468,24 @@ def __determine_type(self,node):
def __determine_displayname(self,node):
display_name = node.get('fullname')
+ if display_name == None:
+ display_name = self.__get_enc_node_text(node,'name',"")
if display_name == '::':
display_name = self.type
self.display_name = display_name
+ def __get_enc_node_text(self,node,name,default =
+ None):
+ n = node.find('%s%s' %(self.ns, name))
+ if n is not None and n.text is not None:
+ val = base64.decodestring(n.text)
+ else:
+ val = None
+ if val is None:
+ return default
+ else:
+ return val
+
def __determine_children(self,node):
children = node.get('children')
self.num_declared_children = children
@@ -477,12 +499,16 @@ def __determine_children(self,node):
def __init_children(self,node):
if self.has_children:
idx = 0
- for c in node.getchildren():
- idx += 1
- p = ContextProperty(c,self,self.depth+1)
- self.children.append(p)
- if idx == self.num_declared_children:
- p.mark_as_last_child()
+ children = node.find('%sproperty'%self.ns)
+ print "Length of childrent: %i" % len(children)
+ if children is not None:
+ for c in children:
+ print c.tag
+ idx += 1
+ p = ContextProperty(c,self,self.depth+1)
+ self.children.append(p)
+ if idx == self.num_declared_children:
+ p.mark_as_last_child()
def mark_as_last_child(self):
self.is_last_child = True
View
22 plugin/python/debugger.py
@@ -95,7 +95,10 @@ def set_breakpoint(self,args = None):
self.handle_general_exception()
def close(self):
- self.runner.close()
+ if self.runner.is_alive():
+ self.runner.close_connection()
+ else:
+ self.runner.close()
class Runner:
@@ -121,14 +124,13 @@ def open(self,server='',port=9000,timeout=30):
addr = str(self.api.conn.address)
log.Log("Found connection from " + addr,log.Logger.INFO)
self.breakpoints.link_api(self.api)
- self.api.step_into()
- self.refresh()
+ status = self.api.step_into()
+ self.refresh(status)
- def refresh(self):
+ def refresh(self,status):
if not self.is_alive():
self.ui.error("Cannot update: no connection")
else:
- status = self.api.status()
if str(status) in ("stopping","stopped"):
self.ui.statuswin.set_status("stopped")
@@ -163,8 +165,8 @@ def run(self):
else:
self.ui.statuswin.set_status("running")
self.ui.sourcewin.remove_pointer()
- self.api.run()
- self.refresh()
+ res = self.api.run()
+ self.refresh(res)
def step_over(self):
if not self.is_alive():
@@ -172,8 +174,8 @@ def step_over(self):
else:
self.ui.statuswin.set_status("running")
self.ui.sourcewin.remove_pointer()
- self.api.step_over()
- self.refresh()
+ res = self.api.step_over()
+ self.refresh(res)
def set_breakpoint(self,args):
bp = breakpoint.Breakpoint.parse(self.ui,args)
@@ -249,9 +251,11 @@ def close_connection(self):
self.breakpoints.unlink_api()
self.api.stop()
self.api.conn.close()
+ self.ui.statuswin.set_status("stopped")
self.api = None
except EOFError:
self.ui.say("Connection has been closed")
+ self.ui.statuswin.set_status("stopped")
def close(self):
""" Close both the connection and UI.
View
15 plugin/python/ui/vimui.py
@@ -341,7 +341,7 @@ def render(self,indent = 0):
def __render_property(self,p,next_p,last = False,indent = 0):
line = "%(indent)s %(marker)s %(name)s = (%(type)s) %(value)s\n" \
%{'indent':"".rjust((p.depth * 2)+indent),\
- 'marker':p.marker(),'name':p.display_name,\
+ 'marker':self.__get_marker(p),'name':p.display_name,\
'type':p.type_and_size(),'value':p.value}
depth = p.depth
@@ -363,12 +363,11 @@ def __render_property(self,p,next_p,last = False,indent = 0):
return line
- def marker(self):
- char = "¿"
- if self.has_children:
- if self.child_count() == 0:
- char = "¿"
+ def __get_marker(self,property):
+ char = ""
+ if property.has_children:
+ if property.child_count() == 0:
+ char = ""
else:
- char = "¿"
+ char = ""
return char
-
View
95 tests/test_dbgp_context_property.py
@@ -0,0 +1,95 @@
+import sys
+sys.path.append('../plugin/python')
+import unittest
+import dbgp
+import xml
+
+class ResponseTest(unittest.TestCase):
+ """Test the response class in the dbgp module."""
+
+ def test_get_cmd(self):
+ """Test that the get_cmd() method returns the command"""
+ cmd = "status"
+ res = dbgp.Response("",cmd,"")
+ assert res.get_cmd() == cmd
+
+ def test_get_cmd_args(self):
+ """Test that the get_cmd_args() method return command arguments"""
+ cmd_args = "-a abcd"
+ res = dbgp.Response("","",cmd_args)
+ assert res.get_cmd_args() == cmd_args
+
+ def test_as_string(self):
+ """Test that the as_string() method returns the
+ raw response string"""
+ response = "<?xml..."
+ res = dbgp.Response(response,"","")
+ assert res.as_string() == response
+
+ def test_as_xml_is_element(self):
+ """Test that the as_xml() method returns an XML
+ element"""
+ response = """<?xml version="1.0" encoding="iso-8859-1"?>
+ <response xmlns="urn:debugger_protocol_v1"
+ xmlns:xdebug="http://xdebug.org/dbgp/xdebug"
+ command="status" transaction_id="1" status="starting"
+ reason="ok"></response>"""
+ res = dbgp.Response(response,"","")
+ self.assertIsInstance(res.as_xml(),xml.etree.ElementTree.Element)
+
+ def test_error_tag_raises_exception(self):
+ response = """<?xml version="1.0" encoding="iso-8859-1"?>
+ <response xmlns="urn:debugger_protocol_v1"
+ xmlns:xdebug="http://xdebug.org/dbgp/xdebug"
+ command="stack_get" transaction_id="4"><error
+ code="5"><message><![CDATA[command is not available]]>
+ </message></error></response>"""
+ re = "command is not available"
+ self.assertRaisesRegexp(dbgp.DBGPError,re,dbgp.Response,response,"","")
+
+class StatusResponseTest(unittest.TestCase):
+ """Test the behaviour of the StatusResponse class."""
+ def test_string_is_status_text(self):
+ response = """<?xml version="1.0" encoding="iso-8859-1"?>
+ <response xmlns="urn:debugger_protocol_v1"
+ xmlns:xdebug="http://xdebug.org/dbgp/xdebug"
+ command="status" transaction_id="1" status="starting"
+ reason="ok"></response>"""
+ res = dbgp.StatusResponse(response,"","")
+ assert str(res) == "starting"
+
+class FeatureResponseTest(unittest.TestCase):
+ """Test the behaviour of the FeatureResponse class."""
+ def test_feature_is_supported(self):
+ response = """<?xml version="1.0" encoding="iso-8859-1"?>
+ <response xmlns="urn:debugger_protocol_v1"
+ xmlns:xdebug="http://xdebug.org/dbgp/xdebug"
+ command="feature_get" transaction_id="2"
+ feature_name="max_depth" supported="1"><![CDATA[1]]></response>"""
+ res = dbgp.FeatureGetResponse(response,"","")
+ assert res.is_supported() == 1
+
+ def test_feature_is_not_supported(self):
+ response = """<?xml version="1.0" encoding="iso-8859-1"?>
+ <response xmlns="urn:debugger_protocol_v1"
+ xmlns:xdebug="http://xdebug.org/dbgp/xdebug"
+ command="feature_get" transaction_id="2"
+ feature_name="max_depth" supported="0"><![CDATA[0]]></response>"""
+ res = dbgp.FeatureGetResponse(response,"","")
+ assert res.is_supported() == 0
+
+class StackGetTest(unittest.TestCase):
+ """Test the behaviour of the StackGetResponse class."""
+ def test_string_is_status_text(self):
+ response = """<?xml version="1.0" encoding="iso-8859-1"?>
+ <response xmlns="urn:debugger_protocol_v1"
+ xmlns:xdebug="http://xdebug.org/dbgp/xdebug"
+ command="stack_get" transaction_id="8">
+ <stack where="{main}" level="0" type="file"
+ filename="file:///usr/local/bin/cake" lineno="4">
+ </stack>
+ </response>"""
+ res = dbgp.StackGetResponse(response,"","")
+ stack = res.get_stack()
+ assert stack[0].get('filename') == "file:///usr/local/bin/cake"
+ assert len(stack) == 1
View
109 tests/test_dbgp_response.py
@@ -93,3 +93,112 @@ def test_string_is_status_text(self):
stack = res.get_stack()
assert stack[0].get('filename') == "file:///usr/local/bin/cake"
assert len(stack) == 1
+
+class ContextGetTest(unittest.TestCase):
+ response = """<?xml version="1.0" encoding="iso-8859-1"?>
+<response xmlns="urn:debugger_protocol_v1"
+xmlns:xdebug="http://xdebug.org/dbgp/xdebug"
+command="context_get" transaction_id="3"
+context="0"><property name="$argc" fullname="$argc"
+address="39795424"
+type="int"><![CDATA[4]]></property><property name="$argv"
+fullname="$argv" address="39794056" type="array"
+children="1" numchildren="4" page="0"
+pagesize="32"><property name="0" fullname="$argv[0]"
+address="39794368" type="string" size="19"
+encoding="base64"><![CDATA[L3Vzci9sb2NhbC9iaW4vY2FrZQ==]]></property><property
+name="1" fullname="$argv[1]" address="39794640"
+type="string" size="8"
+encoding="base64"><![CDATA[VGRkLnRlc3Q=]]></property><property
+name="2" fullname="$argv[2]" address="39794904"
+type="string" size="8"
+encoding="base64"><![CDATA[LS1zdGRlcnI=]]></property><property
+name="3" fullname="$argv[3]" address="39795168"
+type="string" size="3"
+encoding="base64"><![CDATA[QWxs]]></property></property><property
+name="$cdstring" fullname="$cdstring"
+type="uninitialized"></property><property name="$cdup"
+fullname="$cdup" type="uninitialized"></property><property
+name="$cwd" fullname="$cwd"
+type="uninitialized"></property><property name="$dir"
+fullname="$dir" type="uninitialized"></property><property
+name="$dirs" fullname="$dirs"
+type="uninitialized"></property><property name="$f"
+fullname="$f" type="uninitialized"></property><property
+name="$f_parts" fullname="$f_parts"
+type="uninitialized"></property><property name="$f_user"
+fullname="$f_user"
+type="uninitialized"></property><property name="$i"
+fullname="$i" type="uninitialized"></property><property
+name="$idx" fullname="$idx"
+type="uninitialized"></property><property name="$op"
+fullname="$op" type="uninitialized"></property><property
+name="$pass" fullname="$pass"
+type="uninitialized"></property><property
+name="$require_chown" fullname="$require_chown"
+type="uninitialized"></property><property name="$retval"
+fullname="$retval"
+type="uninitialized"></property><property name="$tmp_files"
+fullname="$tmp_files"
+type="uninitialized"></property><property name="$uid"
+fullname="$uid" type="uninitialized"></property><property
+name="$user" fullname="$user"
+type="uninitialized"></property></response>
+"""
+
+ def test_properties_are_objects(self):
+ res = dbgp.ContextGetResponse(self.response,"","")
+ context = res.get_context()
+ assert len(context) == 23
+ self.assertIsInstance(context[0],dbgp.ContextProperty)
+
+ def test_int_property_attributes(self):
+ res = dbgp.ContextGetResponse(self.response,"","")
+ context = res.get_context()
+ prop = context[0]
+
+ assert prop.display_name == "$argc"
+ assert prop.type == "int"
+ assert prop.value == "4"
+ assert prop.has_children == False
+
+ def test_array_property_attributes(self):
+ res = dbgp.ContextGetResponse(self.response,"","")
+ context = res.get_context()
+ prop = context[1]
+
+ assert prop.display_name == "$argv"
+ assert prop.type == "array"
+ assert prop.value == ""
+ assert prop.has_children == True
+ assert prop.child_count() == 4
+
+ def test_string_property_attributes(self):
+ res = dbgp.ContextGetResponse(self.response,"","")
+ context = res.get_context()
+ prop = context[2]
+
+ assert prop.display_name == "$argv[0]"
+ assert prop.type == "string"
+ assert prop.value == "`/usr/local/bin/cake`"
+ assert prop.has_children == False
+ assert prop.size == "19"
+
+class ContextGetAlternateTest(unittest.TestCase):
+ response = """<?xml version="1.0" encoding="utf-8"?>
+<response xmlns="urn:debugger_protocol_v1" command="context_get" context="0" transaction_id="15"><property pagesize="10" numchildren="3" children="1" type="list" page="0" size="3"><name encoding="base64"><![CDATA[bXlsaXN0
+]]></name><fullname encoding="base64"><![CDATA[bXlsaXN0
+]]></fullname></property><property type="int" children="0" size="0"><value><![CDATA[1]]></value><name encoding="base64"><![CDATA[bXl2YXI=
+]]></name><fullname encoding="base64"><![CDATA[bXl2YXI=
+]]></fullname></property><property pagesize="10" numchildren="4" children="1" type="Example" page="0" size="0"><name encoding="base64"><![CDATA[b2Jq
+]]></name><fullname encoding="base64"><![CDATA[b2Jq
+]]></fullname></property></response>"""
+
+ def test_properties_are_objects(self):
+ res = dbgp.ContextGetResponse(self.response,"","")
+ context = res.get_context()
+ p = context[0]
+ print "Display name: "+p.display_name
+ assert len(context) == 3
+ self.assertIsInstance(context[0],dbgp.ContextProperty)
+
Please sign in to comment.
Something went wrong with that request. Please try again.