Skip to content

2.0.0a6

Pre-release
Pre-release

Choose a tag to compare

@kaste kaste released this 06 Mar 22:41
· 28 commits to master since this release
68ada9c
  • Extend captor to be used as a rest matcher

    E.g., support

    args = captor()
    when(freud).says(*args).thenReturn("Yes.")
    assert freud.says("Are", "you", "dreaming?") == "Yes."
    assert args.value == ("Are", "you", "dreaming?")
    # or
    kwargs = captor()
    when(freud).does(**kwargs).thenReturn(False)
    
  • Added call_captor

    call = call_captor()
    when(mock).do(call).thenReturn("ok")
    mock.do(1, 2, x=3)
    assert call.value == ((1, 2), {"x": 3})
    
  • Added patch_attr and patch_dict for non-callable monkeypatch-style use cases
    (e.g. sys.stdout, sys.argv, and environment/config dictionaries) with
    context-manager support and restoration through unstub.

    E.g.

    patch_attr("sys.argv", ["foo", "bar"])
    with patch_attr("sys.stdout", StringIO()) as stdout: ...
    with patch_dict(os.environ, {"user": "bob"}): ...
    
  • Added explicit partial-unstub targeting by host + attribute name.
    This complements method-reference partial unstub (e.g. unstub(cat.meow))
    and supports tuple form and shorthand form, including multiple attributes
    in one call.

    E.g.

    unstub(cat.meow)
    unstub((cat, "meow"))
    unstub(cat, "meow")
    unstub((cat, "meow"), (os.path, "exists"))
    
  • Also implemented unstub("os.path")