Пример #1
0
def test_serialize():
    """Serialize the Plug to json."""
    n1 = NodeForTesting()
    n2 = NodeForTesting()
    out_plug = OutputPlug('out', n1)
    in_plug = InputPlug('in', n2)
    out_plug >> in_plug

    in_serialized = in_plug.serialize()
    out_serialized = out_plug.serialize()

    assert in_plug.name == in_serialized['name']
    assert in_plug.value == in_serialized['value']
    assert 'out' == in_serialized['connections'][out_plug.node.identifier]

    assert out_plug.name == out_serialized['name']
    assert out_plug.value == out_serialized['value']
    assert 'in' == out_serialized['connections'][in_plug.node.identifier]
Пример #2
0
def test_serialize(clear_default_graph):
    """Serialize the Plug to json."""
    n1 = NodeForTesting(name="n1")
    n2 = NodeForTesting(name="n2")
    out_plug = OutputPlug("out", n1)
    out_plug.value = "out_value"
    in1_plug = InputPlug("in1", n2)
    in2_plug = InputPlug("in2", n2)
    in_plug_with_value = InputPlug("in_value", n2, "value")
    compound_out_plug = OutputPlug("compound_out", n1)
    compound_in_plug = InputPlug("compound_in", n2)
    out_plug >> in1_plug
    out_plug >> compound_in_plug["incoming"]
    compound_out_plug["0"] >> in2_plug

    compound_in_plug["0"].value = 0
    compound_in_plug["key"].value = "value"

    in_serialized = in1_plug.serialize()
    assert in_serialized == {
        "name": "in1",
        "value": "out_value",
        "connections": {out_plug.node.identifier: "out"},
        "sub_plugs": {},
    }

    in_plug_with_value_serialized = in_plug_with_value.serialize()
    assert in_plug_with_value_serialized == {
        "name": "in_value",
        "value": "value",
        "connections": {},
        "sub_plugs": {},
    }

    compound_in_serialized = compound_in_plug.serialize()
    assert compound_in_serialized == {
        "name": "compound_in",
        "value": None,
        "connections": {},
        "sub_plugs": {
            "0": {"connections": {}, "name": "compound_in.0", "value": 0},
            "incoming": {
                "connections": {out_plug.node.identifier: "out"},
                "name": "compound_in.incoming",
                "value": "out_value",
            },
            "key": {
                "connections": {},
                "name": "compound_in.key",
                "value": "value",
            },
        },
    }

    out_serialized = out_plug.serialize()
    assert out_serialized == {
        "name": "out",
        "value": "out_value",
        "connections": {
            in1_plug.node.identifier: ["in1", "compound_in.incoming"]
        },
        "sub_plugs": {},
    }

    compound_out_serialized = compound_out_plug.serialize()
    assert compound_out_serialized == {
        "connections": {},
        "name": "compound_out",
        "value": None,
        "sub_plugs": {
            "0": {
                "connections": {in2_plug.node.identifier: ["in2"]},
                "name": "compound_out.0",
                "value": None,
            }
        },
    }

    in2_plug_serialized = in2_plug.serialize()
    assert in2_plug_serialized == {
        "connections": {compound_out_plug.node.identifier: "compound_out.0"},
        "name": "in2",
        "value": None,
        "sub_plugs": {},
    }
Пример #3
0
def test_serialize():
    """Serialize the Plug to json."""
    n1 = NodeForTesting()
    n2 = NodeForTesting()
    out_plug = OutputPlug('out', n1)
    out_plug.value = 'out_value'
    in1_plug = InputPlug('in1', n2)
    in2_plug = InputPlug('in2', n2)
    in_plug_with_value = InputPlug('in_value', n2, 'value')
    compound_out_plug = OutputPlug('compound_out', n1)
    compound_in_plug = InputPlug('compound_in', n2)
    out_plug >> in1_plug
    out_plug >> compound_in_plug['incoming']
    compound_out_plug['0'] >> in2_plug

    compound_in_plug['0'].value = 0
    compound_in_plug['key'].value = 'value'

    in_serialized = in1_plug.serialize()
    assert in_serialized == {
        'name': 'in1',
        'value': 'out_value',
        'connections': {
            out_plug.node.identifier: 'out'
        },
        'sub_plugs': {}
    }

    in_plug_with_value_serialized = in_plug_with_value.serialize()
    assert in_plug_with_value_serialized == {
        'name': 'in_value',
        'value': 'value',
        'connections': {},
        'sub_plugs': {}
    }

    compound_in_serialized = compound_in_plug.serialize()
    assert compound_in_serialized == {
        'name': 'compound_in',
        'value': None,
        'connections': {},
        'sub_plugs': {
            '0': {
                'connections': {},
                'name': 'compound_in.0',
                'value': 0
            },
            'incoming': {
                'connections': {
                    out_plug.node.identifier: 'out'
                },
                'name': 'compound_in.incoming',
                'value': 'out_value'
            },
            'key': {
                'connections': {},
                'name': 'compound_in.key',
                'value': 'value'
            }
        }
    }

    out_serialized = out_plug.serialize()
    assert out_serialized == {
        'name': 'out',
        'value': 'out_value',
        'connections': {
            in1_plug.node.identifier: [
                'in1',
                'compound_in.incoming'
            ]
        },
        'sub_plugs': {}
    }

    compound_out_serialized = compound_out_plug.serialize()
    assert compound_out_serialized == {
        'connections': {},
        'name': 'compound_out',
        'value': None,
        'sub_plugs': {
            '0': {
                'connections': {
                    in2_plug.node.identifier: [
                        'in2'
                    ]
                },
                'name': 'compound_out.0',
                'value': None
            }
        }
    }

    in2_plug_serialized = in2_plug.serialize()
    assert in2_plug_serialized == {
        'connections': {
            compound_out_plug.node.identifier: 'compound_out.0'
        },
        'name': 'in2',
        'value': None,
        'sub_plugs': {}
    }