コード例 #1
0
ファイル: test_decoy.py プロジェクト: mcous/decoy
def test_property_deleter_stub_then_rase(decoy: Decoy) -> None:
    """It should be able to stub a property deleter to raise."""
    subject = decoy.mock()
    prop_rehearser = decoy.prop(subject.prop_name)

    decoy.when(prop_rehearser.delete()).then_raise(ValueError("oh no"))

    with pytest.raises(ValueError, match="oh no"):
        del subject.prop_name
コード例 #2
0
ファイル: test_decoy.py プロジェクト: mcous/decoy
def test_property_setter_stub_then_raise(decoy: Decoy) -> None:
    """It should be able to stub a property setter to raise."""
    subject = decoy.mock()
    prop_rehearser = decoy.prop(subject.prop_name)

    decoy.when(prop_rehearser.set(42)).then_raise(ValueError("oh no"))

    subject.prop_name = 41
    assert subject.prop_name == 41

    with pytest.raises(ValueError, match="oh no"):
        subject.prop_name = 42
コード例 #3
0
ファイル: test_decoy.py プロジェクト: mcous/decoy
def test_verify_property_access(decoy: Decoy) -> None:
    """It should be able to verify property setters and deleters."""
    subject_1 = decoy.mock()
    subject_2 = decoy.mock()

    subject_1.hello("world")
    subject_1.some_property = "fizzbuzz"
    del subject_2.another_property
    subject_2.answer(42)

    decoy.verify(
        subject_1.hello("world"),
        decoy.prop(subject_1.some_property).set("fizzbuzz"),
        decoy.prop(subject_2.another_property).delete(),
        subject_2.answer(42),
    )

    with pytest.raises(errors.VerifyError):
        decoy.verify(
            subject_1.hello("world"),
            decoy.prop(subject_1.some_property).set("fizzbuzz"),
            subject_2.answer(42),
            decoy.prop(subject_2.another_property).delete(),
        )