示例#1
0
def test_extract_nodes():
    modela = ModelA()
    modelb = ModelB()
    modela.ref_field = modelb
    modela.ref_field2 = "user_set_name"

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

    assert len(model_list) == 2
    assert modela in model_list
    assert modelb in model_list
示例#2
0
def test_extract_nodes_dups():
    """Tests where the same model shows up twice in the graph."""
    modela = ModelA()
    modelb = ModelB()
    modela.ref_field = modelb
    modela.ref_field2 = modelb

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

    assert len(model_list) == 2
    assert modela in model_list
    assert modelb in model_list
示例#3
0
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
示例#4
0
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