當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。