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, "")
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)
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
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
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
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
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
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
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"
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
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'>"