forked from vim-vdebug/vdebug
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_breakpoint_breakpoint.py
178 lines (151 loc) · 6.76 KB
/
test_breakpoint_breakpoint.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
import sys
sys.path.append('../plugin/python/')
import unittest
import vdebug.breakpoint
import vdebug.util
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 = vdebug.breakpoint.LineBreakpoint(ui,file,line)
self.assertEqual(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 = vdebug.breakpoint.LineBreakpoint(ui,file,line)
self.assertEqual(bp.get_line(),line)
def test_get_cmd(self):
""" Test that the dbgp command is correct."""
ui = None
file = vdebug.util.FilePath("/path/to/file")
line = 20
bp = vdebug.breakpoint.LineBreakpoint(ui,file,line)
self.assertEqual(bp.get_cmd(),"-t line -f file://%s -n %i -s enabled" %(file, line))
def test_on_add_sets_ui_breakpoint(self):
""" Test that the breakpoint is placed on the source window."""
ui = Mock()
file = vdebug.util.FilePath("/path/to/file")
line = 20
bp = vdebug.breakpoint.LineBreakpoint(ui,file,line)
bp.on_add()
ui.register_breakpoint.assert_called_with(bp)
def test_on_remove_deletes_ui_breakpoint(self):
""" Test that the breakpoint is removed from the source window."""
ui = Mock()
file = vdebug.util.FilePath("/path/to/file")
line = 20
bp = vdebug.breakpoint.LineBreakpoint(ui,file,line)
bp.on_remove()
ui.remove_breakpoint.assert_called_with(bp)
class ConditionalBreakpointTest(unittest.TestCase):
def setUp(self):
vdebug.opts.Options.set({})
def test_get_cmd(self):
""" Test that the dbgp command is correct."""
ui = None
file = vdebug.util.FilePath("/path/to/file")
line = 20
condition = "$x > 20"
bp = vdebug.breakpoint.ConditionalBreakpoint(ui,file,line,condition)
b64cond = base64.encodestring(condition)
exp_cmd = "-t conditional -f file://%s -n %i -s enabled -- %s" %(file, line, b64cond)
self.assertEqual(bp.get_cmd(), exp_cmd)
class ExceptionBreakpointTest(unittest.TestCase):
def test_get_cmd(self):
""" Test that the dbgp command is correct."""
ui = None
exception = "ExampleException"
bp = vdebug.breakpoint.ExceptionBreakpoint(ui,exception)
exp_cmd = "-t exception -x %s -s enabled" % exception
self.assertEqual(bp.get_cmd(), exp_cmd)
class CallBreakpointTest(unittest.TestCase):
def test_get_cmd(self):
""" Test that the dbgp command is correct."""
ui = None
function = "myfunction"
bp = vdebug.breakpoint.CallBreakpoint(ui,function)
exp_cmd = "-t call -m %s -s enabled" % function
self.assertEqual(bp.get_cmd(), exp_cmd)
class ReturnBreakpointTest(unittest.TestCase):
def test_get_cmd(self):
""" Test that the dbgp command is correct."""
ui = None
function = "myfunction"
bp = vdebug.breakpoint.ReturnBreakpoint(ui,function)
exp_cmd = "-t return -m %s -s enabled" % function
self.assertEqual(bp.get_cmd(), exp_cmd)
class BreakpointTest(unittest.TestCase):
def test_id_is_unique(self):
"""Test that each vdebug.breakpoint has a unique ID.
Consecutively generated breakpoints should have
different IDs."""
bp1 = vdebug.breakpoint.Breakpoint(None)
bp2 = vdebug.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 = vdebug.breakpoint.Breakpoint.parse(ui,"")
self.assertIsInstance(ret,vdebug.breakpoint.LineBreakpoint)
def test_parse_with_conditional_breakpoint(self):
""" Test that a ConditionalBreakpoint is created."""
ui = Mock()
ret = vdebug.breakpoint.Breakpoint.parse(ui,"conditional $x == 3")
self.assertIsInstance(ret,vdebug.breakpoint.ConditionalBreakpoint)
self.assertEqual(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(vdebug.breakpoint.BreakpointError,\
re, vdebug.breakpoint.Breakpoint.parse, ui, args)
def test_parse_with_exception_breakpoint(self):
""" Test that a ExceptionBreakpoint is created."""
ui = Mock()
ret = vdebug.breakpoint.Breakpoint.parse(ui,"exception ExampleException")
self.assertIsInstance(ret,vdebug.breakpoint.ExceptionBreakpoint)
self.assertEqual(ret.exception, "ExampleException")
def test_parse_with_exception_raises_error(self):
""" Test that an exception is raised with invalid exception args."""
ui = Mock()
args = "exception"
re = "Exception breakpoints require an exception name "+\
"to be specified"
self.assertRaisesRegexp(vdebug.breakpoint.BreakpointError,\
re, vdebug.breakpoint.Breakpoint.parse, ui, args)
def test_parse_with_call_breakpoint(self):
""" Test that a CallBreakpoint is created."""
ui = Mock()
ret = vdebug.breakpoint.Breakpoint.parse(ui,"call myfunction")
self.assertIsInstance(ret,vdebug.breakpoint.CallBreakpoint)
self.assertEqual(ret.function , "myfunction")
def test_parse_with_call_raises_error(self):
""" Test that an exception is raised with invalid call args."""
ui = Mock()
args = "call"
re = "Call breakpoints require a function name "+\
"to be specified"
self.assertRaisesRegexp(vdebug.breakpoint.BreakpointError,\
re, vdebug.breakpoint.Breakpoint.parse, ui, args)
def test_parse_with_return_breakpoint(self):
""" Test that a ReturnBreakpoint is created."""
ui = Mock()
ret = vdebug.breakpoint.Breakpoint.parse(ui,"return myfunction")
self.assertIsInstance(ret,vdebug.breakpoint.ReturnBreakpoint)
self.assertEqual(ret.function, "myfunction")
def test_parse_with_return_raises_error(self):
""" Test that an exception is raised with invalid return args."""
ui = Mock()
args = "return"
re = "Return breakpoints require a function name "+\
"to be specified"
self.assertRaisesRegexp(vdebug.breakpoint.BreakpointError,\
re, vdebug.breakpoint.Breakpoint.parse, ui, args)