def test_schema_extend_overrides(): """Verify that Schema.extend can override required/extra parameters.""" base = Schema({'a': int}, required=True) extended = base.extend({'b': str}, required=False, extra=ALLOW_EXTRA) assert base.required is True assert base.extra == PREVENT_EXTRA assert extended.required is False assert extended.extra == ALLOW_EXTRA
def test_schema_extend_key_swap(): """Verify that Schema.extend can replace keys, even when different markers are used""" base = Schema({Optional('a'): int}) extension = {Required('a'): int} extended = base.extend(extension) assert_equal(len(base.schema), 1) assert_true(isinstance(list(base.schema)[0], Optional)) assert_equal(len(extended.schema), 1) assert_true((list(extended.schema)[0], Required))
def test_schema_extend(): """Verify that Schema.extend copies schema keys from both.""" base = Schema({'a': int}, required=True) extension = {'b': str} extended = base.extend(extension) assert base.schema == {'a': int} assert extension == {'b': str} assert extended.schema == {'a': int, 'b': str} assert extended.required == base.required assert extended.extra == base.extra
def test_subschema_extension(): """Verify that Schema.extend adds and replaces keys in a subschema""" base = Schema({'a': {'b': int, 'c': float}}) extension = {'d': str, 'a': {'b': str, 'e': int}} extended = base.extend(extension) assert_equal(base.schema, {'a': {'b': int, 'c': float}}) assert_equal(extension, {'d': str, 'a': {'b': str, 'e': int}}) assert_equal(extended.schema, { 'a': { 'b': str, 'c': float, 'e': int }, 'd': str })