• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python util.s函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中util.s函数的典型用法代码示例。如果您正苦于以下问题:Python s函数的具体用法?Python s怎么用?Python s使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了s函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:brianbaquiran,项目名称:jsl,代码行数:31,代码来源:test_fields.py


示例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}
        )
开发者ID:clementtrebuchet,项目名称:email-hook,代码行数:60,代码来源:post-receive-email.py


示例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'
开发者ID:brianbaquiran,项目名称:jsl,代码行数:25,代码来源:test_fields.py


示例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)}
            )
开发者ID:clementtrebuchet,项目名称:email-hook,代码行数:27,代码来源:post-receive-email.py


示例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
开发者ID:jcristau,项目名称:jsl,代码行数:35,代码来源:test_fields.py


示例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',
    }
开发者ID:brianbaquiran,项目名称:jsl,代码行数:31,代码来源:test_fields.py


示例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',
    }
开发者ID:brianbaquiran,项目名称:jsl,代码行数:28,代码来源:test_fields.py


示例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'],
    })
开发者ID:bdue-bilanz,项目名称:jsl,代码行数:57,代码来源:test_roles.py


示例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)
开发者ID:jcristau,项目名称:jsl,代码行数:55,代码来源:test_inheritance.py


示例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)
开发者ID:jcristau,项目名称:jsl,代码行数:52,代码来源:test_document.py


示例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),
            }
        )
开发者ID:clementtrebuchet,项目名称:email-hook,代码行数:26,代码来源:post-receive-email.py


示例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
开发者ID:brianbaquiran,项目名称:jsl,代码行数:7,代码来源:test_fields.py


示例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)
开发者ID:zlsa,项目名称:acrobot,代码行数:29,代码来源:slack.py


示例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'
开发者ID:bdue-bilanz,项目名称:jsl,代码行数:16,代码来源:test_roles.py


示例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,
    })
开发者ID:bdue-bilanz,项目名称:jsl,代码行数:30,代码来源:test_roles.py


示例16: generate_body_normal

    def generate_body_normal(self):
        return s("""
Summary of changes:

%(summary)s

""") % {
            'summary': self.generate_commit_summary(self.added_commits)
       }
开发者ID:tmorgner,项目名称:email-hook,代码行数:9,代码来源:post-receive-email.py


示例17: get_body

    def get_body(self):
        return s("""
The lighweight tag '%(short_refname)s' was deleted. It previously pointed to:

%(commit_oneline)s

""") % {
            'short_refname': self.short_refname,
            'commit_oneline': commit_oneline(self.oldrev)
       }
开发者ID:tmorgner,项目名称:email-hook,代码行数:10,代码来源:post-receive-email.py


示例18: parse_argument_list

 def parse_argument_list(klass, args):
     """ Collects options from the given argument list,
         returning any unparsable ones.
     """  #'''
     if klass._cache:
         print (
             "Warning: Option%s %s set before command-line parsing"
             % (s(len(klass._cache)), expand_list(klass._cache.keys()))
         )
     result = [arg for arg in args if not klass.parse_argument(arg)]
     return result
开发者ID:eswald,项目名称:parlance,代码行数:11,代码来源:config.py


示例19: test_recursive_definitions_6

def test_recursive_definitions_6():
    # regression test for https://github.com/aromanovich/jsl/issues/16

    class Children(Document):
        class Options(object):
            definition_id = 'children'
        children = OneOfField([
            DocumentField('A',),
        ])

    class A(Document):
        class Options(object):
            definition_id = 'a'
        derived_from = DocumentField(Children, as_ref=True)

    assert s(A.get_schema()) == s({
        '$schema': 'http://json-schema.org/draft-04/schema#',
        'definitions': {
            'a': {
                'type': 'object',
                'properties': {
                    'derived_from': {
                        '$ref': '#/definitions/children',
                    },
                },
                'additionalProperties': False,
            },
            'children': {
                'type': 'object',
                'properties': {
                    'children': {
                        'oneOf': [{'$ref': '#/definitions/a'}],
                    },
                },
                'additionalProperties': False,
            },
        },
        '$ref': '#/definitions/a',
    })
开发者ID:jcristau,项目名称:jsl,代码行数:39,代码来源:test_document.py


示例20: test_recursive_definitions_5

def test_recursive_definitions_5():
    # regression test for https://github.com/aromanovich/jsl/issues/14
    class Test(Document):
        class Options(object):
            definition_id = 'test'
        with Scope('test') as test:
            test.field = DocumentField(RECURSIVE_REFERENCE_CONSTANT)

    assert s(Test.get_schema(role='test')) == s({
        '$schema': 'http://json-schema.org/draft-04/schema#',
        '$ref': '#/definitions/test',
        'definitions': {
            'test': {
                'additionalProperties': False, 'type': 'object',
                'properties': {
                    'field': {
                        '$ref': '#/definitions/test'
                    }
                }
            }
        },
    })
开发者ID:jcristau,项目名称:jsl,代码行数:22,代码来源:test_document.py



注:本文中的util.s函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python util.safehasattr函数代码示例发布时间:2022-05-26
下一篇:
Python util.run_impala_shell_cmd函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap