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 s
.solve('http://foo/Binary.xml', binary_arch
)
30 assert s
.feeds_used
== set([foo
.uri
]), s
.feeds_used
31 assert s
.selections
[foo
].id == 'sha1=123'
33 # Now ask for source instead
34 s
.solve('http://foo/Binary.xml',
35 arch
.SourceArchitecture(binary_arch
))
37 assert s
.feeds_used
== set([foo
.uri
, foo_src
.uri
, compiler
.uri
]), s
.feeds_used
38 assert s
.selections
[foo
].id == 'sha1=234' # The source
39 assert s
.selections
[compiler
].id == 'sha1=345' # A binary needed to compile it
43 def testDetails(self
):
44 s
= solver
.DefaultSolver(model
.network_full
, iface_cache
, Stores())
46 foo
= iface_cache
.get_interface('http://foo/Binary.xml')
47 reader
.update(foo
, 'Binary.xml')
48 foo_src
= iface_cache
.get_interface('http://foo/Source.xml')
49 reader
.update(foo_src
, 'Source.xml')
50 compiler
= iface_cache
.get_interface('http://foo/Compiler.xml')
51 reader
.update(compiler
, 'Compiler.xml')
53 binary_arch
= arch
.Architecture({None: 1}, {None: 1})
54 s
.record_details
= True
55 s
.solve('http://foo/Binary.xml', arch
.SourceArchitecture(binary_arch
))
58 assert len(s
.details
) == 2
59 assert s
.details
[foo
] == [(foo_src
._main
_feed
.implementations
['sha1=234'], None), (foo
._main
_feed
.implementations
['sha1=123'], 'Unsupported machine type')]
60 assert s
.details
[compiler
] == [(compiler
._main
_feed
.implementations
['sha1=345'], None)]
63 suite
= unittest
.makeSuite(TestSolver
)
64 if __name__
== '__main__':