1 #!/usr/bin/env python2.4
2 from basetest
import BaseTest
3 import sys
, tempfile
, os
, shutil
6 sys
.path
.insert(0, '..')
7 from zeroinstall
.zerostore
import Stores
8 from zeroinstall
.injector
import solver
, reader
, arch
, model
9 from zeroinstall
.injector
.iface_cache
import iface_cache
12 logger
= logging
.getLogger()
13 #logger.setLevel(logging.DEBUG)
15 class TestSolver(BaseTest
):
17 s
= solver
.DefaultSolver(model
.network_full
, iface_cache
, Stores())
19 foo
= iface_cache
.get_interface('http://foo/Binary.xml')
20 reader
.update(foo
, 'Binary.xml')
21 foo_src
= iface_cache
.get_interface('http://foo/Source.xml')
22 reader
.update(foo_src
, 'Source.xml')
23 compiler
= iface_cache
.get_interface('http://foo/Compiler.xml')
24 reader
.update(compiler
, 'Compiler.xml')
26 binary_arch
= arch
.Architecture({None: 1}, {None: 1})
27 assert str(binary_arch
).startswith("<Arch")
28 s
.solve('http://foo/Binary.xml', binary_arch
)
31 assert s
.feeds_used
== set([foo
.uri
]), s
.feeds_used
32 assert s
.selections
[foo
].id == 'sha1=123'
34 # Now ask for source instead
35 s
.solve('http://foo/Binary.xml',
36 arch
.SourceArchitecture(binary_arch
))
38 assert s
.feeds_used
== set([foo
.uri
, foo_src
.uri
, compiler
.uri
]), s
.feeds_used
39 assert s
.selections
[foo
].id == 'sha1=234' # The source
40 assert s
.selections
[compiler
].id == 'sha1=345' # A binary needed to compile it
44 def testDetails(self
):
45 s
= solver
.DefaultSolver(model
.network_full
, iface_cache
, Stores())
47 foo
= iface_cache
.get_interface('http://foo/Binary.xml')
48 reader
.update(foo
, 'Binary.xml')
49 foo_src
= iface_cache
.get_interface('http://foo/Source.xml')
50 reader
.update(foo_src
, 'Source.xml')
51 compiler
= iface_cache
.get_interface('http://foo/Compiler.xml')
52 reader
.update(compiler
, 'Compiler.xml')
54 binary_arch
= arch
.Architecture({None: 1}, {None: 1})
55 s
.record_details
= True
56 s
.solve('http://foo/Binary.xml', arch
.SourceArchitecture(binary_arch
))
59 assert len(s
.details
) == 2
60 assert s
.details
[foo
] == [(foo_src
._main
_feed
.implementations
['sha1=234'], None), (foo
._main
_feed
.implementations
['sha1=123'], 'Unsupported machine type')]
61 assert s
.details
[compiler
] == [(compiler
._main
_feed
.implementations
['sha1=345'], None)]
63 def testRecursive(self
):
64 s
= solver
.DefaultSolver(model
.network_full
, iface_cache
, Stores())
66 foo
= iface_cache
.get_interface('http://foo/Recursive.xml')
67 reader
.update(foo
, 'Recursive.xml')
69 binary_arch
= arch
.Architecture({None: 1}, {None: 1})
70 s
.record_details
= True
71 s
.solve('http://foo/Recursive.xml', binary_arch
)
74 assert len(s
.details
) == 1
75 assert s
.details
[foo
] == [(foo
._main
_feed
.implementations
['sha1=abc'], None)]
78 suite
= unittest
.makeSuite(TestSolver
)
79 if __name__
== '__main__':