Added unit-tests for background updates
[zeroinstall/zeroinstall-rsl.git] / tests / testsolver.py
blob39fabf07c06785043a28414f027595da49976007
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 assert str(binary_arch).startswith("<Arch")
28 s.solve('http://foo/Binary.xml', binary_arch)
30 assert s.ready
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))
37 assert s.ready
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
42 assert not s.details
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))
57 assert s.ready
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)
72 assert s.ready
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__':
80 sys.argv.append('-v')
81 unittest.main()