Beispiel #1
0
def create_large_dag(nodes=1000, fail_on_cycle=False):
    dag = DepDag(fail_on_cycle=fail_on_cycle)
    for idx in range(nodes // 3):
        name = f'node-{idx}'
        dag.new_vertex(name)
        dag[name].depends_on(name + '-one')
        dag[name].depends_on(name + '-two')
Beispiel #2
0
    def test_clone__case_simple(self):
        dag = DepDag()
        dag.new_vertex('a', 'payload-a')
        dag.new_vertex('b', 'payload-b')
        dag.new_vertex('c', 'payload-c')
        dag.a.depends_on('b')
        dag.b.depends_on('c')
        new_dag = dag.clone()

        self.assertEqual('payload-a', new_dag.a.payload)
        self.assertEqual('payload-b', new_dag.b.payload)
        self.assertEqual('payload-c', new_dag.c.payload)
        self.assertEqual([new_dag.b], list(new_dag.a.direct_supporters()))
        self.assertEqual([new_dag.c], list(new_dag.b.direct_supporters()))
Beispiel #3
0
    def test_clone__case_diamond(self):
        dag = DepDag()
        dag.new_vertex('a', 'payload-a')
        dag.new_vertex('b', 'payload-b')
        dag.new_vertex('c', 'payload-c')
        dag.new_vertex('d', 'payload-d')
        dag.new_vertex('e', 'payload-e')
        dag.new_vertex('f', 'payload-f')
        dag.a.depends_on('b')
        dag.b.depends_on('c', 'd')
        dag.c.depends_on('e')
        dag.d.depends_on('e')
        dag.e.depends_on('f')
        new_dag = dag.clone()

        self.assertEqual([new_dag.b], list(new_dag.a.direct_supporters()))
        self.assertEqual([new_dag.c, new_dag.d], list(new_dag.b.direct_supporters()))
        self.assertEqual([new_dag.e], list(new_dag.c.direct_supporters()))
        self.assertEqual([new_dag.e], list(new_dag.d.direct_supporters()))
        self.assertEqual([new_dag.f], list(new_dag.e.direct_supporters()))

        self.assertEqual('payload-a', new_dag.a.payload)
        self.assertEqual('payload-b', new_dag.b.payload)
        self.assertEqual('payload-c', new_dag.c.payload)
        self.assertEqual('payload-d', new_dag.d.payload)
        self.assertEqual('payload-e', new_dag.e.payload)
        self.assertEqual('payload-f', new_dag.f.payload)
Beispiel #4
0
    def test_clone__cyclic(self):
        dag = DepDag()
        dag.new_vertex('a', 'payload-a')
        dag.new_vertex('b', 'payload-b')
        dag.new_vertex('c', 'payload-c')
        dag.new_vertex('d', 'payload-d')
        dag.a.depends_on('b')
        dag.b.depends_on('c')
        dag.c.depends_on('d')
        dag.d.depends_on('a')
        self.assertTrue(dag.is_cyclic())

        new_dag = dag.clone()
        self.assertEqual([new_dag.b], list(new_dag.a.direct_supporters()))
        self.assertEqual([new_dag.c], list(new_dag.b.direct_supporters()))
        self.assertEqual([new_dag.d], list(new_dag.c.direct_supporters()))
        self.assertEqual([new_dag.a], list(new_dag.d.direct_supporters()))
        self.assertEqual('payload-a', new_dag.a.payload)
        self.assertEqual('payload-b', new_dag.b.payload)
        self.assertEqual('payload-c', new_dag.c.payload)
        self.assertEqual('payload-d', new_dag.d.payload)
        self.assertTrue(new_dag.is_cyclic())
Beispiel #5
0
 def test_is_cyclic__negative__one_vertex(self):
     dag = DepDag()
     dag.new_vertex('a')
     self.assertEqual(1, len(dag))
     self.assertFalse(dag.is_cyclic())