def test_one_of(self): # literals (behaviour implicitly turned on) assert one_of(['foo', 'bar']) == Equals('foo') | Equals('bar') v = one_of(['foo', 'bar']) v('foo') with pytest.raises(errors.ValidationError) as excinfo: v('quux') assert "AllFailed: must equal 'foo' or must equal 'bar'" in excinfo.exconly() # non-literals → rules (behaviour explicitly turned on) shortcut_rule = one_of(['foo', 'bar'], as_rules=True) verbose_rule = Any(['foo', 'bar']) assert shortcut_rule == verbose_rule v = one_of(['foo', 123], as_rules=True) v('hello') v(456) with pytest.raises(errors.ValidationError) as excinfo: v(5.5) assert "AllFailed: must be str or must be int" in excinfo.exconly()
def test_one_of(self): # literals (behaviour implicitly turned on) assert one_of(['foo', 'bar']) == Equals('foo') | Equals('bar') v = one_of(['foo', 'bar']) v('foo') with pytest.raises(errors.ValidationError) as excinfo: v('quux') assert "AllFailed: must equal 'foo' or must equal 'bar'" in excinfo.exconly( ) # non-literals → rules (behaviour explicitly turned on) shortcut_rule = one_of(['foo', 'bar'], as_rules=True) verbose_rule = Any(['foo', 'bar']) assert shortcut_rule == verbose_rule v = one_of(['foo', 123], as_rules=True) v('hello') v(456) with pytest.raises(errors.ValidationError) as excinfo: v(5.5) assert "AllFailed: must be str or must be int" in excinfo.exconly()
return opt_key(other) maybe = OptionalKey() COMMON_SCHEMA = { maybe-'_id': ObjectId, # specific to MongoDB storage backend maybe-'handle': str, # Gramps-specific internal ID maybe-'change': datetime.datetime, # last changed timestamp maybe-'priv': False, # is this a private record? } COMMON_SCHEMA_WITH_ID = { 'id': str, **COMMON_SCHEMA } ID_OR_HLINK = one_of(['id', 'hlink']) LIST_OF_IDS = [str] # TODO use this (see above) LIST_OF_IDS = [{ID_OR_HLINK: str}] # TODO drop this (need ID manager first) LIST_OF_IDS_WITH_ROLES = [ { ID_OR_HLINK: str, # TODO ID instead of hlink maybe-'role': str, } ] LIST_OF_URLS = [ { 'type': str,
{ maybe-'foo': str } """ def __sub__(self, other): return opt_key(other) maybe = OptionalKey() COMMON_SCHEMA = { maybe - '_id': ObjectId, # specific to MongoDB storage backend maybe - 'handle': str, # Gramps-specific internal ID maybe - 'change': datetime.datetime, # last changed timestamp maybe - 'priv': False, # is this a private record? } COMMON_SCHEMA_WITH_ID = {'id': str, **COMMON_SCHEMA} ID_OR_HLINK = one_of(['id', 'hlink']) LIST_OF_IDS = [str] # TODO use this (see above) LIST_OF_IDS = [{ID_OR_HLINK: str}] # TODO drop this (need ID manager first) LIST_OF_IDS_WITH_ROLES = [{ ID_OR_HLINK: str, # TODO ID instead of hlink maybe - 'role': str, }] LIST_OF_URLS = [ { 'type': str, 'href': str, maybe - 'description': str, }, ]
opt_key('contacts'): referenced_item_schema, opt_key('projects'): referenced_item_schema, opt_key('reference'): referenced_item_schema, }) & Length(min=1) STATUS_TODO = u'todo' STATUS_WAITING = u'waiting' STATUS_DONE = u'done' STATUS_CANCELLED = u'cancelled' plan_status_choices = STATUS_TODO, STATUS_WAITING, STATUS_DONE, STATUS_CANCELLED plan_schema = { 'action': unicode, 'status': one_of(plan_status_choices, first_is_default=True), opt_key('refers'): referenced_items_schema, opt_key('repeat'): unicode, opt_key('effort'): unicode, opt_key('context'): [u'anywhere'], opt_key('srcmeta'): dict, opt_key('delegated'): unicode, opt_key('log'): [ log_schema ], opt_key('opened'): nullable(datetime.datetime), opt_key('closed'): nullable(datetime.datetime), opt_key('result'): nullable(unicode), # комментарий о результате выполнения действия: грабли, особенности, ... opt_key('reqs'): [unicode], # требования (напр., какие документы нужно принести и т.д.) opt_key('time'): datetime.datetime, }
{ opt_key('foo'): str } { maybe-'foo': str } """ def __sub__(self, other): return opt_key(other) maybe = OptionalKey() COMMON_SCHEMA = { 'id': str, maybe-'handle': str, # Gramps-specific internal ID maybe-'change': datetime.datetime, # last changed timestamp maybe-'priv': False, # is this a private record? } ID_OR_HLINK = one_of(['id', 'hlink']) LIST_OF_IDS = [str] # TODO use this (see above) LIST_OF_IDS = [{ID_OR_HLINK: str}] # TODO drop this (need ID manager first) LIST_OF_IDS_WITH_ROLES = [ { ID_OR_HLINK: str, # TODO ID instead of hlink maybe-'role': str, } ] LIST_OF_URLS = [ { 'type': str,