Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _():
this, that = 1, 1
e = expect(this)
with raises(ExpectationFailed):
e.not_equals(that)
hist = [
Expected(
this, op="not_equals", that=that, op_args=(), op_kwargs={}, success=False
)
]
expect(e.history).equals(hist)
def _(mock):
args = (1, 2, 3)
kwargs = {"hello": "world"}
mock(1)
mock(*args, **kwargs)
mock(2)
e = expect(mock)
with raises(ExpectationFailed):
e.called_once_with(*args, **kwargs)
hist = [
Expected(
mock,
op="called_once_with",
that=None,
op_args=args,
op_kwargs=kwargs,
success=False,
)
]
expect(e.history).equals(hist)
def _():
this = "olleh"
predicate = lambda e: this[::-1] == "hello"
e = expect(this).satisfies(predicate)
hist = [
Expected(
this=this,
op="satisfies",
that=predicate,
op_args=(),
op_kwargs={},
success=True,
)
]
expect(e.history).equals(hist)
def _store_in_history(
self,
result: bool,
called_with_args: Tuple[Any],
called_with_kwargs: Dict[str, Any],
that=None,
) -> bool:
self.history.append(
Expected(
this=self.this,
op=inspect.stack()[2].function, # :)
that=that,
success=result,
op_args=called_with_args,
op_kwargs=called_with_kwargs,
)
)
return result
def _store_in_history(
self,
result: bool,
called_with_args: Tuple[Any],
called_with_kwargs: Dict[str, Any],
that: Any = None,
) -> bool:
self.history.append(
Expected(
this=self.this,
op=inspect.stack()[2].function, # :)
that=that,
success=result,
op_args=called_with_args,
op_kwargs=called_with_kwargs,
)
)
return result
def __init__(self, this: Any):
self.this = this
self.history: List[Expected] = []
def __init__(self, this: Any):
self.this = this
self.history: List[Expected] = []