After checking for updates, tell the user what happened.
[zeroinstall/zeroinstall-mseaborn.git] / tests / testsolver.py
blob0a3e8136e8fbea5335220cec33ff7fe6f49bc750
1 #!/usr/bin/env python2.4
2 from basetest import BaseTest
3 import sys, tempfile, os, shutil
4 import unittest
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
11 import logging
12 logger = logging.getLogger()
13 #logger.setLevel(logging.DEBUG)
15 class TestSolver(BaseTest):
16 def testSimple(self):
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)
29 assert s.ready
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))
36 assert s.ready
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
41 assert not s.details
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))
56 assert s.ready
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__':
65 sys.argv.append('-v')
66 unittest.main()