本文整理汇总了Python中util.s函数的典型用法代码示例。如果您正苦于以下问题:Python s函数的具体用法?Python s怎么用?Python s使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了s函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_recursive_document_field
def test_recursive_document_field():
class Tree(Document):
node = fields.OneOfField([
fields.ArrayField(fields.DocumentField('self')),
fields.StringField(),
])
expected_schema = {
'$schema': 'http://json-schema.org/draft-04/schema#',
'definitions': {
'test_fields.Tree': {
'type': 'object',
'additionalProperties': False,
'properties': {
'node': {
'oneOf': [
{
'type': 'array',
'items': {'$ref': '#/definitions/test_fields.Tree'},
},
{
'type': 'string',
},
],
},
},
},
},
'$ref': '#/definitions/test_fields.Tree',
}
assert s(Tree.get_schema()) == s(expected_schema)
示例2: generate_tag_info
def generate_tag_info(self):
# We take the creation of an annotated tag as being a "mini-release-announcement"
# and show a 'git shortlog' of the changes since the last tag that was an
# ancestor of the new tag.
last_tag = None
try:
# A bit of a hack to get that previous tag
last_tag = git.describe(self.newrev + "^", abbrev="0", _quiet=True)
except CalledProcessError:
# Assume that this means no older tag
pass
extra = ""
if last_tag:
revision_range = last_tag + ".." + self.newrev
extra = (
s(
"""
Changes since the last tag '%(last_tag)s':
"""
)
% {"last_tag": last_tag}
)
else:
extra = s(
"""
Changes:
"""
)
revision_range = self.newrev
extra += (
s(
"""
%(short_log)s
%(short_stat)s
"""
)
% {"short_log": git.shortlog(revision_range), "short_stat": git.diff(revision_range, shortstat=True)}
)
return (
s(
"""
Tagger: %(tagger)s
Date: %(date)s
%(message)s
%(extra)s
"""
)
% {"tagger": self.tagger, "date": self.date, "message": self.message, "extra": extra}
)
示例3: test_string_field
def test_string_field():
f = fields.StringField()
definitions, schema = f.get_definitions_and_schema()
assert s(schema) == {'type': 'string'}
f = fields.StringField(min_length=1, max_length=10, pattern='^test$',
enum=('a', 'b', 'c'), title='Pururum')
expected_items = [
('type', 'string'),
('title', 'Pururum'),
('enum', ['a', 'b', 'c']),
('pattern', '^test$'),
('minLength', 1),
('maxLength', 10),
]
definitions, schema = f.get_definitions_and_schema()
assert s(schema) == dict(expected_items)
definitions, ordered_schema = f.get_definitions_and_schema(ordered=True)
assert isinstance(ordered_schema, OrderedDict)
assert s(ordered_schema) == OrderedDict(expected_items)
with pytest.raises(ValueError) as e:
fields.StringField(pattern='(')
assert str(e.value) == 'Invalid regular expression: unbalanced parenthesis'
示例4: get_body
def get_body(self):
if len(self.added_commits) > 0:
return (
s(
"""
The branch '%(short_refname)s' was created.
Summary of new commits:
%(summary)s
"""
)
% {"short_refname": self.short_refname, "summary": self.generate_commit_summary(self.added_commits)}
)
else:
return (
s(
"""
The branch '%(short_refname)s' was created pointing to:
%(commit_oneline)s
"""
)
% {"short_refname": self.short_refname, "commit_oneline": commit_oneline(self.newrev)}
)
示例5: test_document_field
def test_document_field():
document_cls_mock = mock.Mock()
expected_schema = mock.Mock()
attrs = {
'get_definitions_and_schema.return_value': ({}, expected_schema),
'get_definition_id.return_value': 'document.Document',
'is_recursive.return_value': False,
}
document_cls_mock.configure_mock(**attrs)
f = fields.DocumentField(document_cls_mock)
definitions, schema = f.get_definitions_and_schema()
assert schema == expected_schema
assert not definitions
definitions, schema = f.get_definitions_and_schema(ref_documents=set([document_cls_mock]))
assert s(schema) == {'$ref': '#/definitions/document.Document'}
f = fields.DocumentField(document_cls_mock, as_ref=True)
definitions, schema = f.get_definitions_and_schema()
assert definitions == {'document.Document': expected_schema}
assert s(schema) == {'$ref': '#/definitions/document.Document'}
attrs = {
'get_definitions_and_schema.return_value': ({}, expected_schema),
'get_definition_id.return_value': 'document.Document',
'is_recursive.return_value': True,
}
document_cls_mock.reset_mock()
document_cls_mock.configure_mock(**attrs)
f = fields.DocumentField(document_cls_mock, as_ref=True)
definitions, schema = f.get_definitions_and_schema()
assert schema == expected_schema
assert not definitions
示例6: test_number_and_int_fields
def test_number_and_int_fields():
f = fields.NumberField(multiple_of=10)
definitions, schema = f.get_definitions_and_schema()
assert s(schema) == {
'type': 'number',
'multipleOf': 10,
}
f = fields.NumberField(minimum=0, maximum=10,
exclusive_minimum=True, exclusive_maximum=True)
definitions, schema = f.get_definitions_and_schema()
assert s(schema) == {
'type': 'number',
'exclusiveMinimum': True,
'exclusiveMaximum': True,
'minimum': 0,
'maximum': 10,
}
f = fields.NumberField(enum=(1, 2, 3))
definitions, schema = f.get_definitions_and_schema()
assert s(schema) == {
'type': 'number',
'enum': [1, 2, 3],
}
f = fields.IntField()
definitions, schema = f.get_definitions_and_schema()
assert s(schema) == {
'type': 'integer',
}
示例7: test_string_derived_fields
def test_string_derived_fields():
f = fields.EmailField()
definitions, schema = f.get_definitions_and_schema()
assert s(schema) == {
'type': 'string',
'format': 'email',
}
f = fields.IPv4Field()
definitions, schema = f.get_definitions_and_schema()
assert s(schema) == {
'type': 'string',
'format': 'ipv4',
}
f = fields.DateTimeField()
definitions, schema = f.get_definitions_and_schema()
assert s(schema) == {
'type': 'string',
'format': 'date-time',
}
f = fields.UriField()
definitions, schema = f.get_definitions_and_schema()
assert s(schema) == {
'type': 'string',
'format': 'uri',
}
示例8: test_basics
def test_basics():
class User(Document):
id = Var({
'response': IntField(required=True)
})
login = StringField(required=True)
class Task(Document):
class Options(object):
title = 'Task'
description = 'A task.'
definition_id = 'task'
id = IntField(required=Var({'response': True}))
name = StringField(required=True, min_length=5)
type = StringField(required=True, enum=['TYPE_1', 'TYPE_2'])
created_at = DateTimeField(required=True)
author = Var({'response': DocumentField(User)})
assert s(Task.get_schema()) == s({
'$schema': 'http://json-schema.org/draft-04/schema#',
'additionalProperties': False,
'description': 'A task.',
'properties': {
'created_at': {'format': 'date-time', 'type': 'string'},
'id': {'type': 'integer'},
'name': {'minLength': 5, 'type': 'string'},
'type': {'enum': ['TYPE_1', 'TYPE_2'], 'type': 'string'}
},
'required': ['created_at', 'type', 'name'],
'title': 'Task',
'type': 'object'
})
assert s(Task.get_schema(role='response')) == s({
'$schema': 'http://json-schema.org/draft-04/schema#',
'title': 'Task',
'description': 'A task.',
'type': 'object',
'additionalProperties': False,
'properties': {
'created_at': {'format': 'date-time', 'type': 'string'},
'id': {'type': 'integer'},
'name': {'minLength': 5, 'type': 'string'},
'type': {'enum': ['TYPE_1', 'TYPE_2'], 'type': 'string'},
'author': {
'additionalProperties': False,
'properties': {
'id': {'type': 'integer'},
'login': {'type': 'string'}
},
'required': ['id', 'login'],
'type': 'object'
},
},
'required': ['created_at', 'type', 'name', 'id'],
})
示例9: test_inheritance_2
def test_inheritance_2():
class Base(Document):
class Options(object):
inheritance_mode = ALL_OF
definition_id = 'base'
title = 'Base'
a = StringField()
class Child(Base):
class Options(object):
definition_id = 'child'
title = 'Child'
b = StringField()
c = DocumentField(RECURSIVE_REFERENCE_CONSTANT)
expected_schema = {
"definitions": {
"base": {
"type": "object",
"title": "Base",
"properties": {
"a": {
"type": "string"
}
},
"additionalProperties": False,
},
"child": {
"allOf": [
{
"$ref": "#/definitions/base"
},
{
"type": "object",
"title": "Child",
"properties": {
"c": {
"$ref": "#/definitions/child"
},
"b": {
"type": "string"
}
},
"additionalProperties": False,
}
]
}
},
"$schema": "http://json-schema.org/draft-04/schema#",
"$ref": "#/definitions/child"
}
schema = Child.get_schema()
assert s(schema) == s(expected_schema)
示例10: test_recursive_definitions_3
def test_recursive_definitions_3():
class Main(Document):
a = DocumentField('test_document.A')
b = DocumentField('B')
class A(Document):
name = StringField()
a = DocumentField('A', as_ref=True)
class B(Document):
c = DocumentField('C')
class C(Document):
name = StringField()
c = DocumentField('C')
expected_schema = {
'$schema': 'http://json-schema.org/draft-04/schema#',
'definitions': {
'test_document.A': {
'type': 'object',
'additionalProperties': False,
'properties': {
'a': {'$ref': '#/definitions/test_document.A'},
'name': {'type': 'string'}
},
},
'test_document.C': {
'type': 'object',
'additionalProperties': False,
'properties': {
'c': {'$ref': '#/definitions/test_document.C'},
'name': {'type': 'string'}
},
}
},
'type': 'object',
'additionalProperties': False,
'properties': {
'a': {'$ref': '#/definitions/test_document.A'},
'b': {
'type': 'object',
'additionalProperties': False,
'properties': {
'c': {
'$ref': '#/definitions/test_document.C'
}
},
}
},
}
assert s(Main.get_schema()) == s(expected_schema)
示例11: generate_body_non_fast_forward
def generate_body_non_fast_forward(self):
return (
s(
"""
The branch '%(short_refname)s' was changed in a way that was not a fast-forward update.
NOTE: This may cause problems for people pulling from the branch. For more information,
please see:
http://live.gnome.org/Git/Help/NonFastForward
Commits removed from the branch:
%(commits_removed)s
Commits added to the branch:
%(commits_added)s
"""
)
% {
"short_refname": self.short_refname,
"commits_removed": self.generate_commit_summary(self.removed_commits, show_details=False),
"commits_added": self.generate_commit_summary(self.added_commits),
}
)
示例12: test_not_field
def test_not_field():
f = fields.NotField(fields.StringField(), description='Not a string.')
expected_schema = {
'description': 'Not a string.',
'not': {'type': 'string'},
}
assert s(f.get_schema()) == expected_schema
示例13: sendDefinitions
def sendDefinitions(self, acronyms, channel):
if not acronyms:
self.sendMessage(channel, 'No acronyms found.')
return
attachments = []
definition_number = 0
for abbreviation, acronym, confidence in acronyms:
attachment = {}
attachment['title'] = abbreviation.upper()
attachment['mrkdwn_in'] = ['text']
if acronym:
attachment['fallback'] = acronym.getFallbackText()
attachment['text'] = '\n'.join([md.toSlack(x.definition) for x in acronym.definitions])
attachment['color'] = '#ccaa55'
definition_number += len(acronym.definitions)
else:
attachment['fallback'] = abbreviation.upper() + ': not found'
attachment['text'] = 'not found'
attachment['color'] = 'danger'
attachments.append(attachment)
self.sendMessage(channel, 'Found ' + str(definition_number) + ' definition' + util.s(definition_number), attachments)
示例14: test_string_field
def test_string_field():
_ = lambda value: Var({'role_1': value})
field = StringField(format=_('date-time'), min_length=_(1), max_length=_(2))
assert s(field.get_schema()) == s({
'type': 'string'
})
assert s(field.get_schema(role='role_1')) == s({
'type': 'string',
'format': 'date-time',
'minLength': 1,
'maxLength': 2,
})
with pytest.raises(ValueError) as e:
StringField(pattern=_('('))
assert str(e.value) == 'Invalid regular expression: unbalanced parenthesis'
示例15: test_array_field
def test_array_field():
s_f = StringField()
n_f = NumberField()
field = ArrayField(Var({
'role_1': s_f,
'role_2': n_f,
}))
schema = s(field.get_schema(role='role_1'))
assert s(schema['items']) == s_f.get_schema()
schema = s(field.get_schema(role='role_2'))
assert schema['items'] == n_f.get_schema()
schema = s(field.get_schema())
assert 'items' not in schema
_ = lambda value: Var({'role_1': value})
field = ArrayField(s_f, min_items=_(1), max_items=_(2), unique_items=_(True), additional_items=_(True))
assert s(field.get_schema()) == s({
'type': 'array',
'items': s_f.get_schema(),
})
assert field.get_schema(role='role_1') == s({
'type': 'array',
'items': s_f.get_schema(),
'minItems': 1,
'maxItems': 2,
'uniqueItems': True,
'additionalItems': True,
})