2021-07-06 18:06:54 +02:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
from spoc import depsolver
|
|
|
|
|
|
|
|
def test_circulardependencyerror():
|
|
|
|
ex = depsolver.CircularDependencyError({'dep1': {'dep2'}, 'dep2': {'dep1'}})
|
|
|
|
ex_str = str(ex)
|
|
|
|
|
|
|
|
assert ex.deps == {'dep1': {'dep2'}, 'dep2': {'dep1'}}
|
|
|
|
assert ex_str == 'Dependency resolution failed due to circular dependency.\n' \
|
|
|
|
'Unresolved dependencies:\n' \
|
|
|
|
' dep1 => {\'dep2\'}\n' \
|
|
|
|
' dep2 => {\'dep1\'}'
|
|
|
|
|
|
|
|
def test_missingdependencyerror():
|
|
|
|
ex = depsolver.MissingDependencyError({'dep1': {'dep2'}}, {'dep2'})
|
|
|
|
ex_str = str(ex)
|
|
|
|
|
|
|
|
assert ex.deps == {'dep1': {'dep2'}}
|
|
|
|
assert ex.missing == {'dep2'}
|
|
|
|
assert ex_str == 'Dependency resolution failed due to missing dependency.\n' \
|
|
|
|
'Missing dependencies:\n' \
|
|
|
|
' {\'dep2\'}\n' \
|
|
|
|
'Unresolved dependencies:\n' \
|
|
|
|
' dep1 => {\'dep2\'}'
|
|
|
|
|
|
|
|
def test_depsolver():
|
|
|
|
solver = depsolver.DepSolver()
|
|
|
|
|
|
|
|
assert solver.unresolved == {}
|
|
|
|
|
|
|
|
solver.add('dep1', ['dep2', 'dep3'])
|
|
|
|
solver.add('dep2', ['dep3', 'dep3'])
|
|
|
|
solver.add('dep3', [])
|
|
|
|
|
|
|
|
assert solver.unresolved == {
|
|
|
|
'dep1': {'dep2', 'dep3'},
|
|
|
|
'dep2': {'dep3'},
|
|
|
|
'dep3': set(),
|
|
|
|
}
|
|
|
|
|
|
|
|
resolved = solver.solve()
|
|
|
|
|
|
|
|
assert resolved == ['dep3', 'dep2', 'dep1']
|
|
|
|
|
|
|
|
def test_depsolver_complex():
|
|
|
|
solver = depsolver.DepSolver()
|
|
|
|
|
|
|
|
solver.add('dep1', ['dep8', 'dep12'])
|
|
|
|
solver.add('dep2', ['dep10'])
|
|
|
|
solver.add('dep3', [])
|
|
|
|
solver.add('dep4', ['dep9'])
|
|
|
|
solver.add('dep5', ['dep1', 'dep6', 'dep8'])
|
|
|
|
solver.add('dep6', ['dep2','dep10', 'dep13', 'dep14'])
|
|
|
|
solver.add('dep7', ['dep9'])
|
|
|
|
solver.add('dep8', ['dep2', 'dep12'])
|
|
|
|
solver.add('dep9', [])
|
|
|
|
solver.add('dep10', ['dep9'])
|
|
|
|
solver.add('dep11', ['dep2', 'dep14'])
|
|
|
|
solver.add('dep12', ['dep7'])
|
|
|
|
solver.add('dep13', ['dep9'])
|
|
|
|
solver.add('dep14', ['dep4'])
|
|
|
|
|
|
|
|
resolved = solver.solve()
|
|
|
|
|
|
|
|
# Order within the same batch (i.e. items not depending on each other) can be random
|
|
|
|
assert list(sorted(resolved[:2])) == ['dep3', 'dep9']
|
2021-07-11 00:58:28 +02:00
|
|
|
assert list(sorted(resolved[2:9])) == ['dep10', 'dep12', 'dep13', 'dep14',
|
|
|
|
'dep2', 'dep4', 'dep7']
|
2021-07-06 18:06:54 +02:00
|
|
|
assert list(sorted(resolved[9:12])) == ['dep11', 'dep6', 'dep8']
|
|
|
|
assert list(sorted(resolved[12:])) == ['dep1', 'dep5']
|
|
|
|
|
|
|
|
def test_depsolver_circular():
|
|
|
|
solver = depsolver.DepSolver()
|
|
|
|
|
|
|
|
solver.add('dep1', ['dep2', 'dep3'])
|
|
|
|
solver.add('dep2', ['dep3'])
|
|
|
|
solver.add('dep3', ['dep4'])
|
|
|
|
solver.add('dep4', ['dep1'])
|
|
|
|
|
|
|
|
with pytest.raises(depsolver.CircularDependencyError):
|
|
|
|
solver.solve()
|
|
|
|
|
|
|
|
def test_depsolver_missing():
|
|
|
|
solver = depsolver.DepSolver()
|
|
|
|
|
|
|
|
solver.add('dep1', ['dep2', 'dep3'])
|
|
|
|
solver.add('dep2', ['dep3'])
|
|
|
|
solver.add('dep4', ['dep1'])
|
|
|
|
|
|
|
|
with pytest.raises(depsolver.MissingDependencyError):
|
|
|
|
solver.solve()
|