summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJon Cairns <jon@joncairns.com>2012-07-31 11:30:04 +0100
committerJon Cairns <jon@ggapps.co.uk>2012-07-31 11:30:04 +0100
commit673b7d98869d6da730bb69224887d1a793c66f38 (patch)
tree95b304473f73ef0c49be1c9c0d5b60b5d9387835 /tests
parentd8307b2d36d5ada11d9c340b72d5a03c182488cc (diff)
downloadvdebug-673b7d98869d6da730bb69224887d1a793c66f38.zip
Added tests for breakpoints
Diffstat (limited to 'tests')
-rw-r--r--tests/test_breakpoint_breakpoint.py102
-rw-r--r--tests/test_dbgp_response.py31
2 files changed, 133 insertions, 0 deletions
diff --git a/tests/test_breakpoint_breakpoint.py b/tests/test_breakpoint_breakpoint.py
new file mode 100644
index 0000000..01ac146
--- /dev/null
+++ b/tests/test_breakpoint_breakpoint.py
@@ -0,0 +1,102 @@
+import sys
+sys.path.append('../plugin/python/')
+import unittest
+import breakpoint
+import base64
+from mock import Mock
+
+class LineBreakpointTest(unittest.TestCase):
+
+ def test_get_file(self):
+ """ Test that the line number is retrievable."""
+ ui = None
+ file = "/path/to/file"
+ line = 1
+ bp = breakpoint.LineBreakpoint(ui,file,line)
+ assert bp.get_file() == file
+
+ def test_get_line(self):
+ """ Test that the line number is retrievable."""
+ ui = None
+ file = "/path/to/file"
+ line = 10
+ bp = breakpoint.LineBreakpoint(ui,file,line)
+ assert bp.get_line() == line
+
+ def test_get_cmd(self):
+ """ Test that the dbgp command is correct."""
+ ui = None
+ file = "/path/to/file"
+ line = 20
+ bp = breakpoint.LineBreakpoint(ui,file,line)
+ assert bp.get_cmd() == "-t line -f %s -n %i" %(file, line)
+
+ def test_on_add_sets_ui_breakpoint(self):
+ """ Test that the breakpoint is placed on the source window."""
+ ui = Mock()
+ file = "/path/to/file"
+ line = 20
+ bp = breakpoint.LineBreakpoint(ui,file,line)
+ bp.on_add()
+ ui.place_breakpoint.assert_called_with(\
+ bp.get_id(),\
+ file,\
+ line)
+
+ def test_on_remove_deletes_ui_breakpoint(self):
+ """ Test that the breakpoint is removed from the source window."""
+ ui = Mock()
+ file = "/path/to/file"
+ line = 20
+ bp = breakpoint.LineBreakpoint(ui,file,line)
+ bp.on_remove()
+ ui.remove_breakpoint.assert_called_with(bp.get_id())
+
+class ConditionalBreakpointTest(unittest.TestCase):
+ def test_get_cmd(self):
+ """ Test that the dbgp command is correct."""
+ ui = None
+ file = "/path/to/file"
+ line = 20
+ condition = "$x > 20"
+ bp = breakpoint.ConditionalBreakpoint(ui,file,line,condition)
+ b64cond = base64.encodestring(condition)
+ exp_cmd = "-t conditional -f %s -n %i -- %s" %(file, line, b64cond)
+ assert bp.get_cmd() == exp_cmd
+
+
+class BreakpointTest(unittest.TestCase):
+
+ def test_id_is_unique(self):
+ """Test that each Breakpoint has a unique ID.
+
+ Consecutively generated breakpoints should have
+ different IDs."""
+ bp1 = breakpoint.Breakpoint(None)
+ bp2 = breakpoint.Breakpoint(None)
+
+ self.assertNotEqual(bp1.get_id(),bp2.get_id())
+
+ def test_parse_with_line_breakpoint(self):
+ """ Test that a LineBreakpoint is created."""
+ ui = Mock()
+ ret = breakpoint.Breakpoint.parse(ui,"")
+ self.assertIsInstance(ret,breakpoint.LineBreakpoint)
+
+ def test_parse_with_conditional_breakpoint(self):
+ """ Test that a ConditionalBreakpoint is created."""
+ ui = Mock()
+ ret = breakpoint.Breakpoint.parse(ui,"conditional $x == 3")
+ self.assertIsInstance(ret,breakpoint.ConditionalBreakpoint)
+ assert ret.condition == "$x == 3"
+
+ def test_parse_with_conditional_raises_error(self):
+ """ Test that an exception is raised with invalid conditional args."""
+ ui = Mock()
+ args = "conditional"
+ re = "Conditional breakpoints require a condition "+\
+ "to be specified"
+ self.assertRaisesRegexp(breakpoint.BreakpointError,\
+ re, breakpoint.Breakpoint.parse, ui, args)
+
+
diff --git a/tests/test_dbgp_response.py b/tests/test_dbgp_response.py
index af0a5ee..caca089 100644
--- a/tests/test_dbgp_response.py
+++ b/tests/test_dbgp_response.py
@@ -49,3 +49,34 @@ class ResponseTest(unittest.TestCase):
</response>"""
re = "An error message"
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