Beispiel #1
0
def test_set_object_callable_called(basic_object):
    """Test if Accessor.set() calls Accessor.setter() if setter is callable."""
    acc = Accessor()
    acc.setter = mock.Mock()
    acc.set(basic_object, "")

    acc.setter.assert_called_once_with(basic_object, "")
Beispiel #2
0
def test_set_object_callable_called(basic_object):
    """Test if Accessor.set() calls Accessor.setter() if setter is callable."""
    acc = Accessor()
    acc.setter = mock.Mock()
    acc.set(basic_object, "")

    acc.setter.assert_called_once_with(basic_object, "")
Beispiel #3
0
def test_set_dict_string(basic_dict, basic_dict_value):
    """Test if setting values in a dict works if setter is a string."""
    acc = Accessor(setter="value")
    acc.set(basic_dict, "")
    assert basic_dict["value"] == ""

    acc.set(basic_dict, basic_dict_value)
    assert basic_dict["value"] == basic_dict_value
Beispiel #4
0
def test_set_dict_callable(basic_dict, basic_dict_value):
    """Test if Accessor.set() sets the value of an dict if setter is callable."""
    acc = Accessor(setter=basic_set_dict)
    acc.set(basic_dict, "")
    assert basic_dict["value"] == ""

    acc.set(basic_dict, basic_dict_value)
    assert basic_dict["value"] == basic_dict_value
Beispiel #5
0
def test_set_object_string(basic_object, basic_object_value):
    """Test if Accessor.set() sets the value of an object when setter is a string."""
    acc = Accessor(setter="value")
    acc.set(basic_object, "")
    assert basic_object.value == ""

    acc.set(basic_object, basic_object_value)
    assert basic_object.value == basic_object_value
Beispiel #6
0
def test_set_object_callable(basic_object, basic_object_value):
    """Test if Accessor.set() sets the value of an object when setter is callable."""
    acc = Accessor(setter=basic_set_object)
    acc.set(basic_object, "")
    assert basic_object.value == ""

    acc.set(basic_object, basic_object_value)
    assert basic_object.value == basic_object_value
Beispiel #7
0
def test_set_dict_string(basic_dict, basic_dict_value):
    """Test if setting values in a dict works if setter is a string."""
    acc = Accessor(setter="value")
    acc.set(basic_dict, "")
    assert basic_dict["value"] == ""

    acc.set(basic_dict, basic_dict_value)
    assert basic_dict["value"] == basic_dict_value
Beispiel #8
0
def test_set_dict_callable(basic_dict, basic_dict_value):
    """Test if Accessor.set() sets the value of an dict if setter is callable."""
    acc = Accessor(setter=basic_set_dict)
    acc.set(basic_dict, "")
    assert basic_dict["value"] == ""

    acc.set(basic_dict, basic_dict_value)
    assert basic_dict["value"] == basic_dict_value
Beispiel #9
0
def test_set_object_string(basic_object, basic_object_value):
    """Test if Accessor.set() sets the value of an object when setter is a string."""
    acc = Accessor(setter="value")
    acc.set(basic_object, "")
    assert basic_object.value == ""

    acc.set(basic_object, basic_object_value)
    assert basic_object.value == basic_object_value
Beispiel #10
0
def test_set_object_callable(basic_object, basic_object_value):
    """Test if Accessor.set() sets the value of an object when setter is callable."""
    acc = Accessor(setter=basic_set_object)
    acc.set(basic_object, "")
    assert basic_object.value == ""

    acc.set(basic_object, basic_object_value)
    assert basic_object.value == basic_object_value
Beispiel #11
0
def test_set_object_nested_dotted(basic_object, basic_object_value):
    """Test if accessor.get() correctly navigates nested values."""
    acc = Accessor(getter="value.key.key", setter="value.key.key")

    acc.set(basic_object, "")
    assert acc.get(basic_object) == ""

    acc.set(basic_object, "value")
    assert acc.get(basic_object) == "value"
Beispiel #12
0
def test_set_object_nested_dotted(basic_object, basic_object_value):
    """Test if accessor.get() correctly navigates nested values."""
    acc = Accessor(getter="value.key.key", setter="value.key.key")

    acc.set(basic_object, "")
    assert acc.get(basic_object) == ""

    acc.set(basic_object, "value")
    assert acc.get(basic_object) == "value"