def test_str_nested(self): compare( str( required(convert(source['foo'].y, int)).insert(0).append().merge()), expected= ("required(convert(source['foo'].y, int)).insert(0).append().merge()" ))
def test_str_nested(self): compare(str( required(convert(source['foo'].y, int)).insert(0).append().merge() ), expected=( "required(convert(source['foo'].y, int)).insert(0).append().merge()" ))
def test_string_item_not_present_required(self): data = {} with ShouldRaise(NotPresent('foo')): load(data, required('foo'))
def test_attr_nested_not_present(self): data = Namespace() with ShouldRaise(NotPresent('x')): load(data, required(source.x.y))
def test_index_not_present(self): data = ['a'] with ShouldRaise(NotPresent(1)): load(data, required(source[1]))
def test_getitem_nested_not_present(self): data = {} with ShouldRaise(NotPresent('foo')): load(data, required(source['foo']['bar']))
def test_ensure_on_required(self): data = '1' with ShouldRaise(TypeError('Cannot use required() as target')): store(data, required(target).x, 'y')
def test_required_and_present(self): data = ['a', 'b'] compare(load(data, required(source[1])), expected='b')
def test_if_supplied_required_falsy(self): data = Namespace(x=None) with ShouldRaise(NotPresent(None)): load(data, required(if_supplied(source.x)))