Ejemplo n.º 1
0
 def test_invalidation(self):
     dep, scope = self.dep, self.scope
     
     _set_all_valid(dep)
     
     self.assertEqual(set(dep.nodes()), set(nodes_matching_all(dep, valid=True)))
     self.assertEqual(set(), set(nodes_matching_all(dep, valid=False)))
     
     dep.invalidate_deps(scope, ['C1.s1'])
     self.assertEqual(set(['C2.a','C2.c','C2.d','c','C2.s1','C2.s2','C2.r1','C2.r2',
                           'C1.c','C1.d','C1.s1','C1.s2','C1.r1','C1.r2','C1','C2']), 
                      set(nodes_matching_all(dep, valid=False)))
Ejemplo n.º 2
0
 def test_invalidate_input_as_output(self):
     dep, scope = _make_graph(comps=['A','B'],
                              connections=[('A.in1','B.in1')],
                              inputs=['in1','in2'],
                              outputs=['out1','out2'])
     
     _set_all_valid(dep)
     dep.invalidate_deps(scope, ['A.in1'])
     self.assertEqual(set(['A','A.out1','A.out2','B.in1','B','B.out1','B.out2']), 
                      set(nodes_matching_all(dep, valid=False)))
Ejemplo n.º 3
0
 def test_nodes_matching(self):
     g = nx.DiGraph()
     g.add_nodes_from(range(10), foo=True)
     g.node[3]['bar'] = True
     g.node[4]['bar'] = False
     g.node[5]['bar'] = True
     
     self.assertEqual(set(nodes_matching_all(g, foo=True, bar=True)),
                      set([3,5]))
     self.assertEqual(set(nodes_matching_all(g, foo=True, bar=True)),
                      set([3,5]))
     self.assertEqual(set(nodes_matching_all(g, foo=True)),
                      set(range(10)))
     self.assertEqual(set(nodes_matching_all(g, foo=False, bar=True)),
                      set())
     self.assertEqual(list(nodes_matching_all(g, bar=False)), [4])
     
     self.assertEqual(set(nodes_matching_some(g, foo=True, bar=False)),
                      set(range(10)))
     self.assertEqual(list(nodes_matching_some(g, foo=False, bar=False)), [4])
Ejemplo n.º 4
0
    def test_invalidate(self):
        dep, scope = _make_graph(comps=['A','B'],
                                 connections=[('A.out1','B.in1')],
                                 inputs=['in1','in2'],
                                 outputs=['out1','out2'])
        
        _set_all_valid(dep)
        
        self.assertEqual(set(dep.nodes()), set(nodes_matching_all(dep, valid=True)))
        self.assertEqual(set(), set(nodes_matching_all(dep, valid=False)))
        
        dep.invalidate_deps(scope, ['A.out2'])
        self.assertEqual(set(['A.out2']), set(nodes_matching_all(dep, valid=False)))
            
        _set_all_valid(dep)
        dep.invalidate_deps(scope, ['A.in1'])
        self.assertEqual(set(['A.in1','A.in2','B.in2']), 
                         set(nodes_matching_all(dep, valid=True)))
        
        _set_all_valid(dep)
            
        dep.connect(scope, 'B.out1', 'A.in1') # make a cycle
        self.assertEqual(set(['A.in2','B.in2']), set(nodes_matching_all(dep, valid=True)))
        
        _set_all_valid(dep)
        dep.invalidate_deps(scope, ['A.out1'])
        self.assertEqual(set(['A.in2','B.in2']), set(nodes_matching_all(dep, valid=True)))
         
        _set_all_valid(dep)

        dep.sever_edges([('B.out1','A.in1')]) # remove cycle
        dep.invalidate_deps(scope, ['A.out1'])
        self.assertEqual(set(['A','A.in1','A.in2','A.out2','B.in2']), 
                         set(nodes_matching_all(dep, valid=True)))

        dep.unsever_edges(self.scope) # put cycle back
        _set_all_valid(dep)

        dep.invalidate_deps(scope, ['A.out1'])
        self.assertEqual(set(['A.in2','B.in2']), set(nodes_matching_all(dep, valid=True)))
        

        dep.sever_edges([('B.out1','A.in1')]) # remove cycle
        try:
            dep.sever_edges([('A.out1','B.in1')])
        except Exception as err:
            self.assertEqual("only one set of severed edges is permitted", str(err))
        else:
            self.fail("Exception expected")