コード例 #1
0
ファイル: properties_test.py プロジェクト: lineCode/genpybind
def test_readonly_property():
    obj = m.Something()
    assert obj.readonly is True
    assert not hasattr(obj, "computed")

    with pytest.raises(AttributeError, match="can't set attribute"):
        obj.readonly = 5
コード例 #2
0
ファイル: properties_test.py プロジェクト: lineCode/genpybind
def test_property():
    obj = m.Something()
    assert obj.value == 0
    assert not hasattr(obj, "get_value")

    obj.value = 5
    assert not hasattr(obj, "set_value")
    assert obj.value == 5
コード例 #3
0
ファイル: properties_test.py プロジェクト: lineCode/genpybind
def test_other_property():
    obj = m.Something()
    assert obj.other == 0
    assert not hasattr(obj, "get_other")

    obj.other = 5
    assert not hasattr(obj, "set_other")
    assert obj.other == 5
コード例 #4
0
def test_readonly_property():
    obj = m.Something()
    assert obj.readonly is True

    with pytest.raises(AttributeError) as excinfo:
        obj.computed  # pylint: disable=pointless-statement
    assert "has no attribute" in str(excinfo.value)

    with pytest.raises(AttributeError) as excinfo:
        obj.readonly = 5
    assert "can't set attribute" in str(excinfo.value)
コード例 #5
0
def test_property():
    obj = m.Something()
    assert obj.value == 0

    with pytest.raises(AttributeError) as excinfo:
        obj.get_value  # pylint: disable=pointless-statement
    assert "has no attribute" in str(excinfo.value)

    obj.value = 5

    with pytest.raises(AttributeError) as excinfo:
        obj.set_value  # pylint: disable=pointless-statement
    assert "has no attribute" in str(excinfo.value)

    assert obj.value == 5