Esempio n. 1
0
    def test_prepare_value_uses__hinted_value(self,
                                              mock_hv: MagicMock) -> None:
        hp = HasProps()
        p = bcpb.Property()

        p.prepare_value(hp, "foo", 10)
        assert mock_hv.called
Esempio n. 2
0
    def test_assert_bools(self) -> None:
        hp = HasProps()
        p = bcpb.Property()

        p.asserts(True, "true")
        assert p.prepare_value(hp, "foo", 10) == 10

        p.asserts(False, "false")
        with pytest.raises(ValueError) as e:
            p.prepare_value(hp, "foo", 10)
            assert str(e) == "false"
Esempio n. 3
0
    def test_assert_msg_funcs(self) -> None:
        hp = HasProps()
        p = bcpb.Property()

        def raise_(ex):
                raise ex

        p.asserts(False, lambda obj, name, value: raise_(ValueError("bad %s %s %s" % (hp==obj, name, value))))

        with pytest.raises(ValueError) as e:
                p.prepare_value(hp, "foo", 10)
                assert str(e) == "bad True name, 10"
Esempio n. 4
0
    def test_assert_functions(self) -> None:
        hp = HasProps()
        p = bcpb.Property()

        p.asserts(lambda obj, value: True, "true")
        p.asserts(lambda obj, value: obj is hp, "true")
        p.asserts(lambda obj, value: value == 10, "true")
        assert p.prepare_value(hp, "foo", 10) == 10

        p.asserts(lambda obj, value: False, "false")
        with pytest.raises(ValueError) as e:
            p.prepare_value(hp, "foo", 10)
            assert str(e) == "false"