Ejemplo n.º 1
0
 def test_filter_inputs_dynamic_keys(self):
     mapping = {'node1': {'out11': 'inp11',
                          'out12': 'inp12'},
                'node2': {'out22': 'inp22',
                          'out21': '_'}}
     nucleotide = Nucleotide(
         inbound_nodes=['node1', 'node2', 'node3'],
         incoming_keys_mapping=mapping)
     nucleotide.incoming_keys = ['inp11']
     nucleotide.dynamic_incoming_keys = True
     data = {'node1': {'out11': 'value11',
                       'out12': 'value12'},
             'node2': {'out21': 'value21',
                       'out22': 'value22',
                       'out': 'value23'},
             'node3': {'out31': 'value31',
                       'out32': 'value32',
                       'out': 'value33'},
             'node4': {'out41': 'value41'}}
     data_remapped_must = {'inp11': 'value11',
                           'inp12': 'value12',
                           'inp22': 'value22',
                           'out31': 'value31',
                           'out32': 'value32',
                           'out': ['value23', 'value33']}
     data_remapped = nucleotide.filter_inputs(data)
     self.assertDictEqual(data_remapped_must, data_remapped)
Ejemplo n.º 2
0
def _get_dna():
    nucleotide1 = Nucleotide(name="nucleotide1")
    nucleotide1.generated_keys = ["y"]

    nucleotide2 = Nucleotide(name="nucleotide2", inbound_nodes=["nucleotide1"])
    nucleotide2.incoming_keys = ["y"]
    nucleotide2.generated_keys = ["z"]

    nucleotide3 = Nucleotide(name="nucleotide3",
                             inbound_nodes=["nucleotide1", "nucleotide2"])
    nucleotide3.dynamic_incoming_keys = True
    nucleotide3.generated_keys = ["w"]
    nucleotide3.dynamic_generated_keys = True

    nucleotide4 = Nucleotide(name="nucleotide4", inbound_nodes=["nucleotide3"])
    nucleotide4.incoming_keys = ["y", "z", "w"]

    nucleotides_list = [nucleotide2, nucleotide3, nucleotide4]
    incoming_nucleotides_list = [nucleotide1]

    dna_must = {
        'nucleotide2':
        DNAConnection(incoming={'nucleotide1'}, outgoing={'nucleotide3'}),
        'nucleotide3':
        DNAConnection(incoming={'nucleotide1', 'nucleotide2'},
                      outgoing={'nucleotide4'}),
        'nucleotide4':
        DNAConnection(incoming={'nucleotide3'}, outgoing=set()),
    }
    topological_sort_must = ["nucleotide2", "nucleotide3", "nucleotide4"]

    raise_build_error = False
    yield (nucleotides_list, incoming_nucleotides_list, dna_must,
           topological_sort_must, raise_build_error)

    nucleotide3 = Nucleotide(name="nucleotide3",
                             inbound_nodes=["nucleotide1", "nucleotide2"])
    nucleotide3.incoming_keys = []
    nucleotide3.generated_keys = ["w"]

    nucleotides_list = [nucleotide2, nucleotide3, nucleotide4]
    raise_build_error = True
    yield (nucleotides_list, incoming_nucleotides_list, dna_must,
           topological_sort_must, raise_build_error)

    nucleotides_list = [
        Nucleotide(name='first', inbound_nodes=['input_node1']),
        Nucleotide(name='second', inbound_nodes=['first', 'input_node2']),
        Nucleotide(name='fourth', inbound_nodes=['first', 'third']),
        Nucleotide(name='fifth', inbound_nodes=['fourth']),
        Nucleotide(name='third', inbound_nodes=['first', 'second'])
    ]
    incoming_nucleotides_list = [
        Nucleotide(name='input_node1'),
        Nucleotide(name='input_node2')
    ]
    dna_must = {
        'first':
        DNAConnection(incoming={'input_node1'},
                      outgoing={'second', 'fourth', 'third'}),
        'second':
        DNAConnection(incoming={'first', 'input_node2'}, outgoing={'third'}),
        'third':
        DNAConnection(incoming={'first', 'second'}, outgoing={'fourth'}),
        'fourth':
        DNAConnection(incoming={'first', 'third'}, outgoing={'fifth'}),
        'fifth':
        DNAConnection(incoming={'fourth'}, outgoing=set())
    }
    topological_sort_must = ["first", "second", "third", "fourth", "fifth"]
    raise_build_error = False
    yield (nucleotides_list, incoming_nucleotides_list, dna_must,
           topological_sort_must, raise_build_error)

    nucleotides_list = [
        Nucleotide(name='first', inbound_nodes=['input_node1']),
        Nucleotide(name='second', inbound_nodes=[]),
        Nucleotide(name='fourth', inbound_nodes=['first', 'third']),
        Nucleotide(name='fifth', inbound_nodes=['fourth']),
        Nucleotide(name='third', inbound_nodes=['first', 'second'])
    ]

    incoming_nucleotides_list = [Nucleotide(name='input_node1')]
    dna_must = {
        'first':
        DNAConnection(incoming={'input_node1'}, outgoing={'fourth', 'third'}),
        'second':
        DNAConnection(incoming=set(), outgoing={'third'}),
        'third':
        DNAConnection(incoming={'first', 'second'}, outgoing={'fourth'}),
        'fourth':
        DNAConnection(incoming={'first', 'third'}, outgoing={'fifth'}),
        'fifth':
        DNAConnection(incoming={'fourth'}, outgoing=set())
    }
    topological_sort_must = ["second", "first", "third", "fourth", "fifth"]
    raise_build_error = False
    yield (nucleotides_list, incoming_nucleotides_list, dna_must,
           topological_sort_must, raise_build_error)

    nucleotides_list = [
        Nucleotide(name='first', inbound_nodes=[]),
        Nucleotide(name='second', inbound_nodes=[]),
        Nucleotide(name='fourth', inbound_nodes=['first', 'third']),
        Nucleotide(name='fifth', inbound_nodes=['fourth']),
        Nucleotide(name='third', inbound_nodes=['first', 'second'])
    ]

    incoming_nucleotides_list = []
    dna_must = {
        'first': DNAConnection(incoming=set(), outgoing={'fourth', 'third'}),
        'second': DNAConnection(incoming=set(), outgoing={'third'}),
        'third': DNAConnection(incoming={'first', 'second'},
                               outgoing={'fourth'}),
        'fourth': DNAConnection(incoming={'first', 'third'},
                                outgoing={'fifth'}),
        'fifth': DNAConnection(incoming={'fourth'}, outgoing=set())
    }
    topological_sort_must = ["first", "second", "third", "fourth", "fifth"]
    raise_build_error = False
    yield (nucleotides_list, incoming_nucleotides_list, dna_must,
           topological_sort_must, raise_build_error)