Пример #1
0
    def test_required_by(self):
        d = Dependencies(
            [
                ("last", "e1"),
                ("last", "mid1"),
                ("last", "mid2"),
                ("mid1", "e2"),
                ("mid1", "mid3"),
                ("mid2", "mid3"),
                ("mid3", "e3"),
            ]
        )

        self.assertEqual(0, len(list(d.required_by("last"))))

        required_by = list(d.required_by("mid3"))
        self.assertEqual(2, len(required_by))
        for n in ("mid1", "mid2"):
            self.assertTrue(n in required_by, "'%s' not found in required_by" % n)

        required_by = list(d.required_by("e2"))
        self.assertEqual(1, len(required_by))
        self.assertTrue("mid1" in required_by, "'%s' not found in required_by" % n)

        self.assertRaises(KeyError, d.required_by, "foo")
Пример #2
0
 def test_complex_circular_rev(self):
     d = Dependencies([('last', 'e1'), ('last', 'mid1'), ('last', 'mid2'),
                       ('mid1', 'e2'), ('mid1', 'mid3'),
                       ('mid2', 'mid3'),
                       ('mid3', 'e3'),
                       ('e3', 'mid1')])
     self.assertRaises(CircularDependencyException, list, reversed(d))
Пример #3
0
 def test_simple_multilevel_partial(self):
     d = Dependencies([('last', 'middle'), ('middle', 'target'),
                       ('target', 'first')])
     p = d['target']
     order = list(iter(p))
     self.assertEqual(len(order), 3)
     for n in ('last', 'middle', 'target'):
         self.assertTrue(n in order,
                         "'%s' not found in dependency order" % n)
Пример #4
0
 def test_simple_partial(self):
     d = Dependencies([('last', 'middle'), ('middle', 'first')])
     p = d['middle']
     order = list(iter(p))
     self.assertEqual(len(order), 2)
     for n in ('last', 'middle'):
         self.assertTrue(n in order,
                         "'%s' not found in dependency order" % n)
     self.assertTrue(order.index('last') > order.index('middle'))
Пример #5
0
    def test_required_by(self):
        d = Dependencies([('last', 'e1'), ('last', 'mid1'), ('last', 'mid2'),
                          ('mid1', 'e2'), ('mid1', 'mid3'), ('mid2', 'mid3'),
                          ('mid3', 'e3')])

        self.assertEqual(0, len(list(d.required_by('last'))))

        required_by = list(d.required_by('mid3'))
        self.assertEqual(len(required_by), 2)
        for n in ('mid1', 'mid2'):
            self.assertTrue(n in required_by,
                            "'%s' not found in required_by" % n)

        required_by = list(d.required_by('e2'))
        self.assertEqual(len(required_by), 1)
        self.assertTrue('mid1' in required_by,
                        "'%s' not found in required_by" % n)

        self.assertRaises(KeyError, d.required_by, 'foo')
Пример #6
0
 def test_complex_partial(self):
     d = Dependencies([('last', 'e1'), ('last', 'mid1'), ('last', 'mid2'),
                       ('mid1', 'e2'), ('mid1', 'mid3'), ('mid2', 'mid3'),
                       ('mid3', 'e3')])
     p = d['mid3']
     order = list(iter(p))
     self.assertEqual(len(order), 4)
     for n in ('last', 'mid1', 'mid2', 'mid3'):
         self.assertTrue(n in order,
                         "'%s' not found in dependency order" % n)
Пример #7
0
    def test_required_by(self):
        d = Dependencies([('last', 'e1'), ('last', 'mid1'), ('last', 'mid2'),
                          ('mid1', 'e2'), ('mid1', 'mid3'),
                          ('mid2', 'mid3'),
                          ('mid3', 'e3')])

        self.assertEqual(0, len(list(d.required_by('last'))))

        required_by = list(d.required_by('mid3'))
        self.assertEqual(2, len(required_by))
        for n in ('mid1', 'mid2'):
            self.assertTrue(n in required_by,
                            "'%s' not found in required_by" % n)

        required_by = list(d.required_by('e2'))
        self.assertEqual(1, len(required_by))
        self.assertTrue('mid1' in required_by,
                        "'%s' not found in required_by" % n)

        self.assertRaises(KeyError, d.required_by, 'foo')
Пример #8
0
    def _dep_test(self, func, checkorder, deps):
        nodes = set.union(*[set(e) for e in deps])

        d = Dependencies(deps)
        order = list(func(d))

        for n in nodes:
            self.assertTrue(n in order, '"%s" is not in the sequence' % n)
            self.assertEqual(order.count(n), 1)

        self.assertEqual(len(order), len(nodes))

        for l, f in deps:
            checkorder(order.index(f), order.index(l))
Пример #9
0
 def test_single_node(self):
     d = Dependencies([('only', None)])
     l = list(iter(d))
     self.assertEqual(len(l), 1)
     self.assertEqual(l[0], 'only')
Пример #10
0
 def test_self_ref(self):
     d = Dependencies([('node', 'node')])
     self.assertRaises(CircularDependencyException, list, iter(d))
Пример #11
0
 def test_circular_rev(self):
     d = Dependencies([('first', 'second'), ('second', 'third'),
                       ('third', 'first')])
     self.assertRaises(CircularDependencyException, list, reversed(d))
Пример #12
0
 def test_edges(self):
     input_edges = [('1', None), ('2', '3'), ('2', '4')]
     dp = Dependencies(input_edges)
     self.assertEqual(set(input_edges), set(dp.graph().edges()))
 def test_disjoint(self):
     d = Dependencies([('1', None), ('2', None)])
     l = list(iter(d))
     self.assertEqual(2, len(l))
     self.assertIn('1', l)
     self.assertIn('2', l)
Пример #14
0
 def test_edges(self):
     input_edges = [("1", None), ("2", "3"), ("2", "4")]
     dp = Dependencies(input_edges)
     self.assertEqual(set(input_edges), set(dp.graph().edges()))
Пример #15
0
 def test_edges(self):
     input_edges = [('1', None), ('2', '3'), ('2', '4')]
     dp = Dependencies(input_edges)
     self.assertEqual(set(dp.graph().edges()), set(input_edges))
Пример #16
0
 def test_repr(self):
     dp = Dependencies([('1', None), ('2', '3'), ('2', '4')])
     s = "Dependencies([('1', None), ('2', '3'), ('2', '4')])"
     self.assertEqual(repr(dp), s)
Пример #17
0
 def test_noexist_partial(self):
     d = Dependencies([('foo', 'bar')])
     get = lambda i: d[i]
     self.assertRaises(KeyError, get, 'baz')
Пример #18
0
 def test_disjoint(self):
     d = Dependencies([('1', None), ('2', None)])
     l = list(iter(d))
     self.assertEqual(len(l), 2)
     self.assertTrue('1' in l)
     self.assertTrue('2' in l)
Пример #19
0
 def test_single_partial(self):
     d = Dependencies([('last', 'first')])
     p = d['last']
     l = list(iter(p))
     self.assertEqual(len(l), 1)
     self.assertEqual(l[0], 'last')