def test_addition_of_different_deptypes_in_multiple_calls(mock_packages, config): # Construct the following spec: # # [email protected] # | build,link,run # [email protected] # # with three calls and check we always have a single edge root = Spec('[email protected]').concretized() bootstrap = Spec('[email protected]').concretized() for current_deptype in ('build', 'link', 'run'): root.add_dependency_edge(bootstrap, deptype=current_deptype) # Check edges in dependencies assert len(root.edges_to_dependencies()) == 1 forward_edge = root.edges_to_dependencies(deptype=current_deptype)[0] assert current_deptype in forward_edge.deptypes assert id(forward_edge.parent) == id(root) assert id(forward_edge.spec) == id(bootstrap) # Check edges from dependents assert len(bootstrap.edges_from_dependents()) == 1 backward_edge = bootstrap.edges_from_dependents(deptype=current_deptype)[0] assert current_deptype in backward_edge.deptypes assert id(backward_edge.parent) == id(root) assert id(backward_edge.spec) == id(bootstrap)
def test_adding_same_deptype_with_the_same_name_raises( mock_packages, config, c1_deptypes, c2_deptypes ): p = Spec('[email protected]').concretized() c1 = Spec('[email protected]').concretized() c2 = Spec('[email protected]').concretized() p.add_dependency_edge(c1, deptype=c1_deptypes) with pytest.raises(spack.error.SpackError): p.add_dependency_edge(c2, deptype=c2_deptypes)
def test_synthetic_construction_bootstrapping(mock_packages, config): # Construct the following spec: # # [email protected] # | build # [email protected] # root = Spec('[email protected]').concretized() bootstrap = Spec('[email protected]').concretized() root.add_dependency_edge(bootstrap, deptype='build') assert len(root.dependencies()) == 1 assert root.dependencies()[0].name == 'b' assert root.name == 'b'
def test_synthetic_construction_of_split_dependencies_from_same_package( mock_packages, config ): # Construct in a synthetic way (i.e. without using the solver) # the following spec: # # b # build / \ link,run # [email protected] [email protected] # # To demonstrate that a spec can now hold two direct # dependencies from the same package root = Spec('b').concretized() link_run_spec = Spec('[email protected]').concretized() build_spec = Spec('[email protected]').concretized() root.add_dependency_edge(link_run_spec, deptype='link') root.add_dependency_edge(link_run_spec, deptype='run') root.add_dependency_edge(build_spec, deptype='build') # Check dependencies from the perspective of root assert len(root.dependencies()) == 2 assert all(x.name == 'c' for x in root.dependencies()) assert '@2.0' in root.dependencies(name='c', deptype='build')[0] assert '@1.0' in root.dependencies(name='c', deptype=('link', 'run'))[0] # Check parent from the perspective of the dependencies assert len(build_spec.dependents()) == 1 assert len(link_run_spec.dependents()) == 1 assert build_spec.dependents() == link_run_spec.dependents() assert build_spec != link_run_spec
def test_concretize_partial_old_dag_hash_spec(mock_packages, config): # create an "old" spec with no package hash bottom = Spec("dt-diamond-bottom").concretized() delattr(bottom, "_package_hash") dummy_hash = "zd4m26eis2wwbvtyfiliar27wkcv3ehk" bottom._hash = dummy_hash # add it to an abstract spec as a dependency top = Spec("dt-diamond") top.add_dependency_edge(bottom, ()) # concretize with the already-concrete dependency top.concretize() for spec in top.traverse(): assert spec.concrete # make sure dag_hash is untouched assert spec["dt-diamond-bottom"].dag_hash() == dummy_hash assert spec["dt-diamond-bottom"]._hash == dummy_hash # make sure package hash is NOT recomputed assert not getattr(spec["dt-diamond-bottom"], '_package_hash', None)