当前位置: 首页>>代码示例>>Python>>正文


Python types.StringType方法代码示例

本文整理汇总了Python中schematics.types.StringType方法的典型用法代码示例。如果您正苦于以下问题:Python types.StringType方法的具体用法?Python types.StringType怎么用?Python types.StringType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在schematics.types的用法示例。


在下文中一共展示了types.StringType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_autoname_lists

# 需要导入模块: from schematics import types [as 别名]
# 或者: from schematics.types import StringType [as 别名]
def test_autoname_lists():
    """Tests that autoname works with lists."""

    class Model(optplan.ProblemGraphNode):
        type = types.StringType(default="Model")
        value = types.ListType(types.ModelType(ModelB))

    modelb1 = ModelB(int_field=1)
    modelb2 = ModelB(int_field=2)
    model = Model(value=[modelb1, modelb2])

    optplan.autoname(model)

    assert model.name
    assert modelb1.name
    assert modelb2.name 
开发者ID:stanfordnqp,项目名称:spins-b,代码行数:18,代码来源:test_optplan.py

示例2: test_autoname_dicts

# 需要导入模块: from schematics import types [as 别名]
# 或者: from schematics.types import StringType [as 别名]
def test_autoname_dicts():
    """Tests that autoname works with lists."""

    class Model(optplan.ProblemGraphNode):
        type = types.StringType(default="Model")
        value = types.DictType(types.ModelType(ModelB))

    modelb1 = ModelB(int_field=1)
    modelb2 = ModelB(int_field=2)
    model = Model(value={"1": modelb1, "2": modelb2})

    optplan.autoname(model)

    assert model.name
    assert modelb1.name
    assert modelb2.name 
开发者ID:stanfordnqp,项目名称:spins-b,代码行数:18,代码来源:test_optplan.py

示例3: test_autoname_nested

# 需要导入模块: from schematics import types [as 别名]
# 或者: from schematics.types import StringType [as 别名]
def test_autoname_nested():

    class OuterModel(optplan.ProblemGraphNode):
        type = types.StringType(default="Model")
        value = optplan.ReferenceType(optplan.ProblemGraphNode)

    class InnerModel(optplan.ProblemGraphNode):
        type = types.StringType(default="Model2")
        value = optplan.ReferenceType(optplan.ProblemGraphNode)

    modelb = ModelB()
    inner_model = InnerModel(value=modelb)
    outer_model = OuterModel(value=inner_model)

    optplan.autoname(outer_model)

    assert outer_model.name
    assert inner_model.name
    assert modelb.name 
开发者ID:stanfordnqp,项目名称:spins-b,代码行数:21,代码来源:test_optplan.py

示例4: test_extract_nodes_lists

# 需要导入模块: from schematics import types [as 别名]
# 或者: from schematics.types import StringType [as 别名]
def test_extract_nodes_lists():
    """Tests that it works with lists."""

    class Model(optplan.ProblemGraphNode):
        type = types.StringType(default="Model")
        value = types.ListType(types.ModelType(ModelB))

    modelb1 = ModelB(int_field=1)
    modelb2 = ModelB(int_field=2)
    model = Model(value=[modelb1, modelb2])

    model_list = []
    io._extract_nodes(model, model_list)

    assert len(model_list) == 3
    assert model in model_list
    assert modelb1 in model_list
    assert modelb2 in model_list 
开发者ID:stanfordnqp,项目名称:spins-b,代码行数:20,代码来源:test_optplan.py

示例5: test_extract_nodes_nested

# 需要导入模块: from schematics import types [as 别名]
# 或者: from schematics.types import StringType [as 别名]
def test_extract_nodes_nested():

    class OuterModel(optplan.ProblemGraphNode):
        type = types.StringType(default="Model")
        value = optplan.ReferenceType(optplan.ProblemGraphNode)

    class InnerModel(optplan.ProblemGraphNode):
        type = types.StringType(default="Model2")
        value = optplan.ReferenceType(optplan.ProblemGraphNode)

    modelb = ModelB()
    inner_model = InnerModel(value=modelb)
    outer_model = OuterModel(value=inner_model)

    model_list = []
    io._extract_nodes(outer_model, model_list)

    assert len(model_list) == 3
    assert modelb in model_list
    assert inner_model in model_list
    assert outer_model in model_list 
开发者ID:stanfordnqp,项目名称:spins-b,代码行数:23,代码来源:test_optplan.py

示例6: test_replace_ref_nodes_with_names_nested

# 需要导入模块: from schematics import types [as 别名]
# 或者: from schematics.types import StringType [as 别名]
def test_replace_ref_nodes_with_names_nested():

    class OuterModel(optplan.ProblemGraphNode):
        type = types.StringType(default="Model")
        value = optplan.ReferenceType(optplan.ProblemGraphNode)

    class InnerModel(optplan.ProblemGraphNode):
        type = types.StringType(default="Model2")
        value = optplan.ReferenceType(optplan.ProblemGraphNode)

    modelb = ModelB(name="m1")
    inner_model = InnerModel(name="m2", value=modelb)
    outer_model = OuterModel(name="m3", value=inner_model)

    model_list = [outer_model, inner_model, modelb]
    io._replace_ref_nodes_with_names(outer_model, model_list)

    assert outer_model.value == inner_model.name
    assert inner_model.value == modelb.name 
开发者ID:stanfordnqp,项目名称:spins-b,代码行数:21,代码来源:test_optplan.py

示例7: test_extract_nodes_dicts

# 需要导入模块: from schematics import types [as 别名]
# 或者: from schematics.types import StringType [as 别名]
def test_extract_nodes_dicts():
    """Tests that autoname works with lists."""

    class Model(optplan.ProblemGraphNode.Schema):
        type = types.StringType(default="Model")
        value = types.DictType(types.ModelType(ModelB))

    modelb1 = ModelB(int_field=1)
    modelb2 = ModelB(int_field=2)
    model = Model(value={"1": modelb1, "2": modelb2})

    model_list = []
    schema._extract_nodes(model, model_list)

    assert len(model_list) == 3
    assert model in model_list
    assert modelb1 in model_list
    assert modelb2 in model_list 
开发者ID:stanfordnqp,项目名称:spins-b,代码行数:20,代码来源:test_schema.py

示例8: test_extract_nodes_nested

# 需要导入模块: from schematics import types [as 别名]
# 或者: from schematics.types import StringType [as 别名]
def test_extract_nodes_nested():

    class OuterModel(optplan.ProblemGraphNode.Schema):
        type = types.StringType(default="Model")
        value = optplan.ReferenceType(optplan.ProblemGraphNode.Schema)

    class InnerModel(optplan.ProblemGraphNodeSchema):
        type = types.StringType(default="Model2")
        value = optplan.ReferenceType(optplan.ProblemGraphNode.Schema)

    modelb = ModelB()
    inner_model = InnerModel(value=modelb)
    outer_model = OuterModel(value=inner_model)

    model_list = []
    schema._extract_nodes(outer_model, model_list)

    assert len(model_list) == 3
    assert modelb in model_list
    assert inner_model in model_list
    assert outer_model in model_list 
开发者ID:stanfordnqp,项目名称:spins-b,代码行数:23,代码来源:test_schema.py

示例9: test_replace_ref_nodes_with_names_lists

# 需要导入模块: from schematics import types [as 别名]
# 或者: from schematics.types import StringType [as 别名]
def test_replace_ref_nodes_with_names_lists():
    """Tests that it works with lists."""

    class Model(optplan.ProblemGraphNodeSchema):
        type = types.StringType(default="Model")
        value = types.ListType(
            optplan.ReferenceType(optplan.ProblemGraphNodeSchema))

    modelb1 = ModelB(name="m1", int_field=1)
    modelb2 = ModelB(name="m2", int_field=2)
    model = Model(name="m3", value=[modelb1, modelb2])

    model_list = [modelb1, modelb2, model]
    schema._replace_ref_nodes_with_names(model, model_list)

    assert model.value == [modelb1.name, modelb2.name] 
开发者ID:stanfordnqp,项目名称:spins-b,代码行数:18,代码来源:test_schema.py

示例10: test_replace_ref_nodes_with_names_dicts

# 需要导入模块: from schematics import types [as 别名]
# 或者: from schematics.types import StringType [as 别名]
def test_replace_ref_nodes_with_names_dicts():
    """Tests that it works with lists."""

    class Model(optplan.ProblemGraphNodeSchema):
        type = types.StringType(default="Model")
        value = types.DictType(
            optplan.ReferenceType(optplan.ProblemGraphNodeSchema))

    modelb1 = ModelB(name="m1", int_field=1)
    modelb2 = ModelB(name="m2", int_field=2)
    model = Model(name="m3", value={"1": modelb1, "2": modelb2})

    model_list = [modelb1, modelb2, model]
    schema._replace_ref_nodes_with_names(model, model_list)

    assert model.value == {"1": modelb1.name, "2": modelb2.name} 
开发者ID:stanfordnqp,项目名称:spins-b,代码行数:18,代码来源:test_schema.py

示例11: test_replace_ref_nodes_with_names_nested

# 需要导入模块: from schematics import types [as 别名]
# 或者: from schematics.types import StringType [as 别名]
def test_replace_ref_nodes_with_names_nested():

    class OuterModel(optplan.ProblemGraphNode.Schema):
        type = types.StringType(default="Model")
        value = optplan.ReferenceType(optplan.ProblemGraphNode.Schema)

    class InnerModel(optplan.ProblemGraphNode.Schema):
        type = types.StringType(default="Model2")
        value = optplan.ReferenceType(optplan.ProblemGraphNode.Schema)

    modelb = ModelB(name="m1")
    inner_model = InnerModel(name="m2", value=modelb)
    outer_model = OuterModel(name="m3", value=inner_model)

    model_list = [outer_model, inner_model, modelb]
    schema._replace_ref_nodes_with_names(outer_model, model_list)

    assert outer_model.value == inner_model.name
    assert inner_model.value == modelb.name 
开发者ID:stanfordnqp,项目名称:spins-b,代码行数:21,代码来源:test_schema.py

示例12: test_field_inflection

# 需要导入模块: from schematics import types [as 别名]
# 或者: from schematics.types import StringType [as 别名]
def test_field_inflection():
    class FakeModel(BetfairModel):
        underscore_separated_field = StringType()

    record = FakeModel(underscoreSeparatedField='test')
    assert record.underscore_separated_field == 'test'
    serialized = record.serialize()
    assert 'underscoreSeparatedField' in serialized
    assert serialized['underscoreSeparatedField'] == 'test' 
开发者ID:jmcarp,项目名称:betfair.py,代码行数:11,代码来源:test_models.py

示例13: test_json_list

# 需要导入模块: from schematics import types [as 别名]
# 或者: from schematics.types import StringType [as 别名]
def test_json_list():
    class MyModel(Model):
        a = JSONListType(StringType)

    a = MyModel({'a': [1, 2, 3]})
    a.validate()

    b = MyModel({'a': json.dumps([1, 2, 3])})
    b.validate() 
开发者ID:fy0,项目名称:slim,代码行数:11,代码来源:test_schematics_ext.py

示例14: test_json_dict

# 需要导入模块: from schematics import types [as 别名]
# 或者: from schematics.types import StringType [as 别名]
def test_json_dict():
    class MyModel(Model):
        a = JSONDictType(StringType)

    a = MyModel({'a': {
        'a': 'b'
    }})
    a.validate()

    a = MyModel({'a': json.dumps({
        'a': 'b'
    })})
    a.validate() 
开发者ID:fy0,项目名称:slim,代码行数:15,代码来源:test_schematics_ext.py

示例15: polymorphic_model_type

# 需要导入模块: from schematics import types [as 别名]
# 或者: from schematics.types import StringType [as 别名]
def polymorphic_model_type(name: str) -> types.StringType:
    """Returns a `StringType` for defining polymorphic models.

    See `polymorphic_model` decorator for more details.

    Args:
        name: Name identifying polymorphic model.
    """
    return types.StringType(default=name, choices=(name,), required=True) 
开发者ID:stanfordnqp,项目名称:spins-b,代码行数:11,代码来源:schema_utils.py


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