mirror of
https://github.com/microsoft/debugpy.git
synced 2025-12-23 08:48:12 +00:00
Add a Stub testing helper.
This commit is contained in:
parent
2fc452e3d8
commit
66224aa085
1 changed files with 25 additions and 0 deletions
25
tests/helpers/stub.py
Normal file
25
tests/helpers/stub.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
|
||||
|
||||
class Stub(object):
|
||||
"""A testing double that tracks calls."""
|
||||
|
||||
def __init__(self):
|
||||
self.calls = []
|
||||
self._exceptions = []
|
||||
|
||||
def set_exceptions(self, *exceptions):
|
||||
self._exceptions = list(exceptions)
|
||||
|
||||
def add_call(self, name, *args, **kwargs):
|
||||
self.add_call_exact(name, args, kwargs)
|
||||
|
||||
def add_call_exact(self, name, args, kwargs):
|
||||
self.calls.append((name, args, kwargs))
|
||||
|
||||
def maybe_raise(self):
|
||||
if not self._exceptions:
|
||||
return
|
||||
exc = self._exceptions.pop(0)
|
||||
if exc is None:
|
||||
return
|
||||
raise exc
|
||||
Loading…
Add table
Add a link
Reference in a new issue