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_get_object_callable_called(mocked_get_context, basic_object):
    """Test if Accessor.get() calls Accessor.getter() if getter is callable."""
    acc = Accessor()
    acc.getter = mock.Mock()
    acc.get(basic_object)

    acc.getter.assert_called_once_with(basic_object)
Beispiel #3
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 #4
0
def test_get_object_callable_called(mocked_get_context, basic_object):
    """Test if Accessor.get() calls Accessor.getter() if getter is callable."""
    acc = Accessor()
    acc.getter = mock.Mock()
    acc.get(basic_object)

    acc.getter.assert_called_once_with(basic_object)
Beispiel #5
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 #6
0
def test_get_dict_string(basic_dict_value, basic_dict):
    """Test return value of get with dict.

    Test if Accessor.get() returns correct results for an object,
    when used with a callable getter.
    """
    acc = Accessor(getter="value")
    assert acc.get(basic_dict) == basic_dict_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_get_dict_string(basic_dict_value, basic_dict):
    """Test return value of get with dict.

    Test if Accessor.get() returns correct results for an object,
    when used with a callable getter.
    """
    acc = Accessor(getter="value")
    assert acc.get(basic_dict) == 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_accessor_accessor():
    """Test if accessor returns the correct Accessor object when the attr property is an accessor."""
    attr = Attr()
    attr.name = 'name'
    acc = Accessor()
    attr.attr = acc

    assert attr.accessor == acc
Beispiel #13
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 #14
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 #15
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 #16
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 #17
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 #18
0
def test_get_object_string(basic_object, basic_object_value):
    """Test if Accessor.get() returns correct results when used with a dotted string."""
    acc = Accessor(getter="value")
    assert acc.get(basic_object) == basic_object_value
Beispiel #19
0
def test_get_object_string(basic_object, basic_object_value):
    """Test if Accessor.get() returns correct results when used with a dotted string."""
    acc = Accessor(getter="value")
    assert acc.get(basic_object) == basic_object_value
Beispiel #20
0
def test_accessor_repr():
    """Test Accessor repr."""
    acc = Accessor(getter='some.value', setter='some.other.value')
    assert repr(
        acc) == "<Accessor getter='some.value', setter='some.other.value'>"