Ejemplo n.º 1
0
def test_dependency_sort_does_not_mutate_input():
    dependency_tree = _test_dependency_tree

    # save the original dependency tree structure information
    expected_deps = {}
    expected_deps_ids = {}
    for x, y in iteritems(dependency_tree):
        expected_deps[x] = copy.copy(y)
        expected_deps_ids[id(x)] = id(y)

    # run the dependency sort
    dependency_sort(dependency_tree)

    # verify that the dependency tree structure is unchanged
    assert len(dependency_tree) == len(expected_deps)
    for key, deps in iteritems(dependency_tree):
        # same deps for each key
        assert id(deps) == expected_deps_ids[id(key)]
        # deps structure compare with the original copy
        assert deps == expected_deps[key]
        # explicit deps content id matching just in case the container's __eq__
        # is not precise enough
        _assert_same_content_set(deps, expected_deps[key])
Ejemplo n.º 2
0
def test_dependency_sort_does_not_mutate_input():
    dependency_tree = _test_dependency_tree

    # save the original dependency tree structure information
    expected_deps = {}
    expected_deps_ids = {}
    for x, y in iteritems(dependency_tree):
        expected_deps[x] = copy.copy(y)
        expected_deps_ids[id(x)] = id(y)

    # run the dependency sort
    dependency_sort(dependency_tree)

    # verify that the dependency tree structure is unchanged
    assert len(dependency_tree) == len(expected_deps)
    for key, deps in iteritems(dependency_tree):
        # same deps for each key
        assert id(deps) == expected_deps_ids[id(key)]
        # deps structure compare with the original copy
        assert deps == expected_deps[key]
        # explicit deps content id matching just in case the container's __eq__
        # is not precise enough
        _assert_same_content_set(deps, expected_deps[key])
Ejemplo n.º 3
0
 def dereference(self):
     """Instruct all children to perform dereferencing."""
     all = []
     indexes = {}
     for child in self.children:
         child.content(all)
     dependencies = {}
     for x in all:
         x.qualify()
         midx, deps = x.dependencies()
         dependencies[x] = deps
         indexes[x] = midx
     for x, deps in dependency_sort(dependencies):
         midx = indexes.get(x)
         if midx is None:
             continue
         d = deps[midx]
         log.debug("(%s) merging %s <== %s", self.tns[1], Repr(x), Repr(d))
         x.merge(d)
Ejemplo n.º 4
0
 def dereference(self):
     """Instruct all children to perform dereferencing."""
     all = []
     indexes = {}
     for child in self.children:
         child.content(all)
     dependencies = {}
     for x in all:
         x.qualify()
         midx, deps = x.dependencies()
         dependencies[x] = deps
         indexes[x] = midx
     for x, deps in dependency_sort(dependencies):
         midx = indexes.get(x)
         if midx is None:
             continue
         d = deps[midx]
         log.debug("(%s) merging %s <== %s", self.tns[1], Repr(x), Repr(d))
         x.merge(d)
Ejemplo n.º 5
0
def test_dependency_sort():
    dependency_tree = _test_dependency_tree
    result = dependency_sort(dependency_tree)
    assert sorted(result) == sorted(iteritems(dependency_tree))
    _assert_dependency_order((x[0] for x in result), dependency_tree)
Ejemplo n.º 6
0
def test_dependency_sort():
    dependency_tree = _test_dependency_tree
    result = dependency_sort(dependency_tree)
    assert sorted(result) == sorted(iteritems(dependency_tree))
    _assert_dependency_order((x[0] for x in result), dependency_tree)