Example #1
0
def test_plug_gets_dirty_only_on_change(clear_default_graph):
    """Test that plugs only change dirtyness if a real change happens."""
    in_test, out_test = "foo", "bar"
    n1 = NodeForTesting(name="n1")
    n2 = NodeForTesting(name="n2")
    out_plug = OutputPlug("out", n1)
    in_plug = InputPlug("in", n2)

    out_plug >> in_plug

    in_plug.value = in_test
    out_plug.value = out_test
    assert in_plug.is_dirty
    assert out_plug.is_dirty

    in_plug.is_dirty = False
    out_plug.is_dirty = False
    assert not in_plug.is_dirty
    assert not out_plug.is_dirty

    same_val = in_plug.value
    in_plug.value = same_val
    assert not in_plug.is_dirty
    assert not out_plug.is_dirty

    out_plug.value = out_test
    assert not in_plug.is_dirty
    assert not out_plug.is_dirty

    out_plug.value = "baz"
    assert in_plug.is_dirty
    assert out_plug.is_dirty
Example #2
0
def test_connect_and_dicsonnect_nodes():
    """Connect and disconnect nodes."""
    n1 = NodeForTesting()
    n2 = NodeForTesting()
    out_plug_a = OutputPlug('out', n1)
    out_plug_b = OutputPlug('out', n1)
    in_plug_a = InputPlug('in', n2)
    in_plug_b = InputPlug('in', n2)

    # Connect the out to the in
    out_plug_a >> in_plug_a
    assert 1 == len(out_plug_a.connections)
    assert 1 == len(in_plug_a.connections)

    # Connect the same nodes multiple times
    out_plug_a >> in_plug_a
    assert 1 == len(out_plug_a.connections)
    assert 1 == len(in_plug_a.connections)

    # Connect the in to the out
    in_plug_b >> out_plug_a
    assert 2 == len(out_plug_a.connections)
    assert 1 == len(in_plug_b.connections)

    # Connect the in to the multiple times
    in_plug_b >> out_plug_a
    assert 2 == len(out_plug_a.connections)
    assert 1 == len(in_plug_b.connections)

    # Connecting a different input disconnects the existing one
    assert out_plug_a == in_plug_a.connections[0]
    out_plug_b >> in_plug_a
    print(in_plug_a.connections)
    assert out_plug_b == in_plug_a.connections[0]
Example #3
0
 def __init__(self, name=None):
     """Initialize WriteTextToFileNode."""
     super(WriteTextToFileNode, self).__init__(name)
     InputPlug('text', self)
     InputPlug('file_path', self)
     OutputPlug('text', self)
     OutputPlug('file_path', self)
Example #4
0
 def __init__(self, name=None):
     """Init the node."""
     super(SquareNode, self).__init__(name)
     InputPlug('in1', self)
     InputPlug('compound_in', self)
     OutputPlug('out', self)
     OutputPlug('compound_out', self)
Example #5
0
 def __init__(self, name=None, in1=None, *args, **kwargs):
     """Init the node."""
     super(SquareNode, self).__init__(name, *args, **kwargs)
     InputPlug('in1', self, value=in1)
     InputPlug('compound_in', self)
     OutputPlug('out', self)
     OutputPlug('compound_out', self)
Example #6
0
def test_assign_initial_value_to_input_plug():
    """Assign an initial value to an InputPlug."""
    n = NodeForTesting()
    in_plug = InputPlug('in', n)
    assert in_plug.value is None

    in_plug = InputPlug('in', n, 123)
    assert 123 == in_plug.value
Example #7
0
def test_assign_initial_value_to_input_plug(clear_default_graph):
    """Assign an initial value to an InputPlug."""
    n = NodeForTesting()
    in_plug = InputPlug("in", n)
    assert in_plug.value is None

    in_plug = InputPlug("in", n, 123)
    assert 123 == in_plug.value
Example #8
0
def test_set_value_sets_plug_dirty():
    """Connecting and disconnecting sets the plug dirty."""
    n = NodeForTesting()
    in_plug = InputPlug('in', n)

    in_plug.is_dirty = False
    assert not in_plug.is_dirty
    in_plug.value = 'NewValue'
    assert in_plug.is_dirty
Example #9
0
def test_connect_and_disconnect_nodes(clear_default_graph):
    """Connect and disconnect nodes."""
    n1 = NodeForTesting(name="n1")
    n2 = NodeForTesting(name="n2")
    out_plug_a = OutputPlug("out", n1)
    in_plug_a = InputPlug("in_a", n2)
    in_plug_b = InputPlug("in_b", n2)
    in_plug_c = InputPlug("in_c", n2)
    in_plug_d = InputPlug("in_d", n2)
    in_plug_compound = InputPlug("in_compound", n2)
    out_plug_compound = OutputPlug("out_compound", n1)

    # Connect the out to the in
    out_plug_a >> in_plug_a
    assert 1 == len(out_plug_a.connections)
    assert 1 == len(in_plug_a.connections)
    out_plug_compound["0"] >> in_plug_c
    assert 1 == len(out_plug_compound["0"].connections)
    assert 1 == len(in_plug_c.connections)
    out_plug_compound["1"] >> in_plug_compound["1"]
    assert 1 == len(out_plug_compound["1"].connections)
    assert 1 == len(in_plug_compound["1"].connections)

    # Connect the same nodes multiple times
    out_plug_a >> in_plug_a
    assert 1 == len(out_plug_a.connections)
    assert 1 == len(in_plug_a.connections)
    out_plug_compound["0"] >> in_plug_c
    assert 1 == len(out_plug_compound["0"].connections)
    assert 1 == len(in_plug_c.connections)
    out_plug_compound["1"] >> in_plug_compound["1"]
    assert 1 == len(out_plug_compound["1"].connections)
    assert 1 == len(in_plug_compound["1"].connections)

    # Connect the in to the out
    in_plug_b >> out_plug_a
    assert 2 == len(out_plug_a.connections)
    assert 1 == len(in_plug_b.connections)
    in_plug_d >> out_plug_compound["0"]
    assert 2 == len(out_plug_compound["0"].connections)
    assert 1 == len(in_plug_d.connections)
    in_plug_compound["2"] >> out_plug_compound["1"]
    assert 2 == len(out_plug_compound["1"].connections)
    assert 1 == len(in_plug_compound["1"].connections)

    # Connect the in to the multiple times
    in_plug_b >> out_plug_a
    assert 2 == len(out_plug_a.connections)
    assert 1 == len(in_plug_b.connections)
    in_plug_d >> out_plug_compound["0"]
    assert 2 == len(out_plug_compound["0"].connections)
    assert 1 == len(in_plug_d.connections)
    in_plug_compound["2"] >> out_plug_compound["1"]
    assert 2 == len(out_plug_compound["1"].connections)
    assert 1 == len(in_plug_compound["1"].connections)
Example #10
0
def test_connect_and_dicsonnect_nodes():
    """Connect and disconnect nodes."""
    n1 = NodeForTesting()
    n2 = NodeForTesting()
    out_plug_a = OutputPlug('out', n1)
    in_plug_a = InputPlug('in_a', n2)
    in_plug_b = InputPlug('in_b', n2)
    in_plug_c = InputPlug('in_c', n2)
    in_plug_d = InputPlug('in_d', n2)
    in_plug_compound = InputPlug('in_compound', n2)
    out_plug_compound = OutputPlug('out_compound', n1)

    # Connect the out to the in
    out_plug_a >> in_plug_a
    assert 1 == len(out_plug_a.connections)
    assert 1 == len(in_plug_a.connections)
    out_plug_compound['0'] >> in_plug_c
    assert 1 == len(out_plug_compound['0'].connections)
    assert 1 == len(in_plug_c.connections)
    out_plug_compound['1'] >> in_plug_compound['1']
    assert 1 == len(out_plug_compound['1'].connections)
    assert 1 == len(in_plug_compound['1'].connections)

    # Connect the same nodes multiple times
    out_plug_a >> in_plug_a
    assert 1 == len(out_plug_a.connections)
    assert 1 == len(in_plug_a.connections)
    out_plug_compound['0'] >> in_plug_c
    assert 1 == len(out_plug_compound['0'].connections)
    assert 1 == len(in_plug_c.connections)
    out_plug_compound['1'] >> in_plug_compound['1']
    assert 1 == len(out_plug_compound['1'].connections)
    assert 1 == len(in_plug_compound['1'].connections)

    # Connect the in to the out
    in_plug_b >> out_plug_a
    assert 2 == len(out_plug_a.connections)
    assert 1 == len(in_plug_b.connections)
    in_plug_d >> out_plug_compound['0']
    assert 2 == len(out_plug_compound['0'].connections)
    assert 1 == len(in_plug_d.connections)
    in_plug_compound['2'] >> out_plug_compound['1']
    assert 2 == len(out_plug_compound['1'].connections)
    assert 1 == len(in_plug_compound['1'].connections)

    # Connect the in to the multiple times
    in_plug_b >> out_plug_a
    assert 2 == len(out_plug_a.connections)
    assert 1 == len(in_plug_b.connections)
    in_plug_d >> out_plug_compound['0']
    assert 2 == len(out_plug_compound['0'].connections)
    assert 1 == len(in_plug_d.connections)
    in_plug_compound['2'] >> out_plug_compound['1']
    assert 2 == len(out_plug_compound['1'].connections)
    assert 1 == len(in_plug_compound['1'].connections)
Example #11
0
    def __init__(self, name=None):
        """Init the node."""
        super(AssetNode, self).__init__(name)
        InputPlug('project', self)
        InputPlug('name', self)
        InputPlug('kind', self)

        OutputPlug('asset', self)
        OutputPlug('next_version', self)
        OutputPlug('next_version_notes', self)
        OutputPlug('latest_version', self)
        OutputPlug('latest_version_notes', self)
Example #12
0
def test_change_connections_sets_plug_dirty():
    """Connecting and disconnecting sets the plug dirty."""
    n1 = NodeForTesting()
    n2 = NodeForTesting()
    out_plug = OutputPlug('in', n1)
    in_plug = InputPlug('in', n2)

    in_plug.is_dirty = False
    out_plug >> in_plug
    assert in_plug.is_dirty

    in_plug.is_dirty = False
    out_plug << in_plug
    assert in_plug.is_dirty
Example #13
0
def test_set_output_pushes_value_to_connected_input():
    """OutPlugs push their values to their connected input plugs."""
    n1 = NodeForTesting()
    n2 = NodeForTesting()
    out_plug = OutputPlug('in', n1)
    in_plug = InputPlug('in', n2)

    out_plug.value = 'OldValue'
    assert in_plug.value != out_plug.value

    out_plug >> in_plug
    in_plug.is_dirty = False
    assert in_plug.value == out_plug.value
    assert not in_plug.is_dirty

    out_plug.value = 'NewValue'
    assert in_plug.is_dirty
    assert in_plug.value == out_plug.value
Example #14
0
def test_forbidden_connect(clear_default_graph):
    """Test connections between plugs that are forbidden."""
    n1 = NodeForTesting(name="n1")
    in_plug1 = InputPlug("in", n1)
    out_plug1 = OutputPlug("out", n1)

    n2 = NodeForTesting(name="n2")
    InputPlug("in", n2)
    out_plug2 = OutputPlug("out", n2)

    with pytest.raises(TypeError):
        out_plug1.connect(out_plug2)

    with pytest.raises(TypeError):
        in_plug1.connect(in_plug1)

    with pytest.raises(TypeError):
        out_plug1.connect("a string")
Example #15
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]
Example #16
0
def test_plugs_can_not_contain_dots(clear_default_graph):
    @Node()
    def A():
        pass

    with pytest.raises(ValueError):
        OutputPlug(name="name.with.dots", node=A(graph=None))

    with pytest.raises(ValueError):
        InputPlug(name="name.with.dots", node=A(graph=None))
Example #17
0
def test_rshift_into_node(clear_default_graph):
    """Test the syntactic sugar for rshift operator between plug and node."""
    n1 = NodeForTesting(name="n1")
    n2 = NodeForTesting(name="n2")
    out_plug = OutputPlug("foo", n1)
    in_plug = InputPlug("foo", n2)

    out_plug >> n2

    assert in_plug in out_plug.connections
Example #18
0
def test_plugs_can_not_contain_dots():

    @Node()
    def A():
        pass

    with pytest.raises(ValueError):
        OutputPlug(name='name.with.dots', node=A())

    with pytest.raises(ValueError):
        InputPlug(name='name.with.dots', node=A())
Example #19
0
def test_set_output_pushes_value_to_connected_input(clear_default_graph):
    """OutPlugs push their values to their connected input plugs."""
    n1 = NodeForTesting(name='n1')
    n2 = NodeForTesting(name='n2')
    out_plug = OutputPlug('out', n1)
    in_plug = InputPlug('in', n2)

    out_compound_plug = OutputPlug('out_compound', n1)
    in_compound_plug = InputPlug('in_compound', n2)

    out_plug.value = 'OldValue'
    assert in_plug.value != out_plug.value

    out_plug >> in_plug
    in_plug.is_dirty = False
    assert in_plug.value == out_plug.value
    assert not in_plug.is_dirty

    out_plug.value = 'NewValue'
    assert in_plug.is_dirty
    assert in_plug.value == out_plug.value

    out_compound_plug.value = 'OldValue'
    assert in_compound_plug.value != out_compound_plug.value

    out_compound_plug >> in_compound_plug
    in_compound_plug.is_dirty = False
    assert in_compound_plug.value == out_compound_plug.value
    assert not in_compound_plug.is_dirty

    out_compound_plug.value = 'NewValue'
    assert in_compound_plug.is_dirty
    assert in_compound_plug.value == out_compound_plug.value
Example #20
0
def test_set_output_pushes_value_to_connected_input(clear_default_graph):
    """OutPlugs push their values to their connected input plugs."""
    n1 = NodeForTesting(name="n1")
    n2 = NodeForTesting(name="n2")
    out_plug = OutputPlug("out", n1)
    in_plug = InputPlug("in", n2)

    out_compound_plug = OutputPlug("out_compound", n1)
    in_compound_plug = InputPlug("in_compound", n2)

    out_plug.value = "OldValue"
    assert in_plug.value != out_plug.value

    out_plug >> in_plug
    in_plug.is_dirty = False
    assert in_plug.value == out_plug.value
    assert not in_plug.is_dirty

    out_plug.value = "NewValue"
    assert in_plug.is_dirty
    assert in_plug.value == out_plug.value

    out_compound_plug.value = "OldValue"
    assert in_compound_plug.value != out_compound_plug.value

    out_compound_plug >> in_compound_plug
    in_compound_plug.is_dirty = False
    assert in_compound_plug.value == out_compound_plug.value
    assert not in_compound_plug.is_dirty

    out_compound_plug.value = "NewValue"
    assert in_compound_plug.is_dirty
    assert in_compound_plug.value == out_compound_plug.value
Example #21
0
 def __init__(self, *args, **kwargs):
     super(DivideNode, self).__init__(*args, **kwargs)
     InputPlug('number_1', self, 0)
     InputPlug('number_2', self, 0)
     OutputPlug('result', self)
     self.metadata = {
         "datatypes": {
             "inputs": {
                 "number_1": {
                     "type": "float",
                 },
                 "number_2": {
                     "type": "float"
                 }
             },
             "outputs": {
                 "result": {
                     "type": "float"
                 }
             }
         }
     }
Example #22
0
def test_set_value_sets_plug_dirty(clear_default_graph):
    """Connecting and disconnecting sets the plug dirty."""
    n = NodeForTesting()
    in_plug = InputPlug("in", n)
    in_compound_plug = InputPlug("in_compound", n)

    in_plug.is_dirty = False
    assert not in_plug.is_dirty
    in_plug.value = "NewValue"
    assert in_plug.is_dirty

    in_compound_plug.is_dirty = False
    assert not in_compound_plug.is_dirty
    in_compound_plug.value = "NewValue"
    assert in_compound_plug.is_dirty
 def post_deserialize(self, data):
     """Perform more data operations after initial serialization."""
     self.name = data['name']
     self.identifier = data['identifier']
     self.metadata = data['metadata']
     self.file_location = data['file_location']
     for name, input_ in data['inputs'].items():
         if name not in self.inputs:
             InputPlug(name, self)
         self.inputs[name].value = input_['value']
     for name, output in data['outputs'].items():
         if name not in self.outputs:
             OutputPlug(name, self)
         self.outputs[name].value = output['value']
Example #24
0
def test_change_connections_sets_plug_dirty(clear_default_graph):
    """Connecting and disconnecting sets the plug dirty."""
    n1 = NodeForTesting(name='n1')
    n2 = NodeForTesting(name='n2')
    out_plug = OutputPlug('out', n1)
    in_plug = InputPlug('in', n2)
    out_compound_plug = OutputPlug('out_compound', n1)
    in_compound_plug = InputPlug('in_compound', n2)

    in_plug.is_dirty = False
    out_plug >> in_plug
    assert in_plug.is_dirty

    in_plug.is_dirty = False
    out_plug << in_plug
    assert in_plug.is_dirty

    in_compound_plug['0'].is_dirty = False
    out_compound_plug['0'] >> in_compound_plug['0']
    assert in_compound_plug['0'].is_dirty

    in_compound_plug['0'].is_dirty = False
    out_compound_plug['0'] << in_compound_plug['0']
    assert in_compound_plug['0'].is_dirty
Example #25
0
def test_change_connections_sets_plug_dirty(clear_default_graph):
    """Connecting and disconnecting sets the plug dirty."""
    n1 = NodeForTesting(name="n1")
    n2 = NodeForTesting(name="n2")
    out_plug = OutputPlug("out", n1)
    in_plug = InputPlug("in", n2)
    out_compound_plug = OutputPlug("out_compound", n1)
    in_compound_plug = InputPlug("in_compound", n2)

    in_plug.is_dirty = False
    out_plug >> in_plug
    assert in_plug.is_dirty

    in_plug.is_dirty = False
    out_plug << in_plug
    assert in_plug.is_dirty

    in_compound_plug["0"].is_dirty = False
    out_compound_plug["0"] >> in_compound_plug["0"]
    assert in_compound_plug["0"].is_dirty

    in_compound_plug["0"].is_dirty = False
    out_compound_plug["0"] << in_compound_plug["0"]
    assert in_compound_plug["0"].is_dirty
Example #26
0
 def __init__(self, name=None):
     """Init the node."""
     super(SimpleNode, self).__init__(name)
     InputPlug('in1', self)
     InputPlug('in2', self)
     InputPlug('in3', self)
Example #27
0
 def __init__(self, time=None, timezone=0, **kwargs):
     super(ConvertTime, self).__init__(**kwargs)
     InputPlug('time', self)
     InputPlug('timezone', self, timezone)
     OutputPlug('converted_time', self)
Example #28
0
 def __init__(self, name=None, in1=None, in2=None, **kwargs):
     super(NodeForTesting, self).__init__(name, **kwargs)
     OutputPlug('out', self)
     OutputPlug('out2', self)
     InputPlug('in1', self, in1)
     InputPlug('in2', self, in2)
Example #29
0
 def __init__(self, name=None, in1=None, in2=None, **kwargs):
     super(NodeForTesting, self).__init__(name, **kwargs)
     OutputPlug("out", self)
     OutputPlug("out2", self)
     InputPlug("in1", self, in1)
     InputPlug("in2", self, in2)
Example #30
0
 def __init__(self, amount=None, **kwargs):
     super(HireWorkers, self).__init__(**kwargs)
     InputPlug('amount', self, amount)
     OutputPlug('workers', self)