add clean make target
[zeroinstall/zeroinstall-afb.git] / tests / testsolver.py
blob477e31247d38b3b2aae748b599dec63793e1d859
1 #!/usr/bin/env python2.4
2 from basetest import BaseTest
3 import sys
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)]
77 def testMultiArch(self):
78 s = solver.DefaultSolver(model.network_full, iface_cache, Stores())
80 foo = iface_cache.get_interface('http://foo/MultiArch.xml')
81 reader.update(foo, 'MultiArch.xml')
82 lib = iface_cache.get_interface('http://foo/MultiArchLib.xml')
83 reader.update(lib, 'MultiArchLib.xml')
85 # On an i686 system we can only use the i486 implementation
87 binary_arch = arch.get_architecture('Linux', 'i686')
88 s.solve('http://foo/MultiArch.xml', binary_arch)
89 assert s.ready
90 assert s.selections[foo].machine == 'i486'
91 assert s.selections[lib].machine == 'i486'
93 # On an 64 bit system we could use either, but we prefer the 64
94 # bit implementation. The i486 version of the library is newer,
95 # but we must pick one that is compatible with the main binary.
97 binary_arch = arch.get_architecture('Linux', 'x86_64')
98 s.solve('http://foo/MultiArch.xml', binary_arch)
99 assert s.ready
100 assert s.selections[foo].machine == 'x86_64'
101 assert s.selections[lib].machine == 'x86_64'
103 def testArch(self):
104 host_arch = arch.get_host_architecture()
105 host_arch2 = arch.get_architecture(None, None)
106 self.assertEquals(host_arch.os_ranks, host_arch2.os_ranks)
107 self.assertEquals(host_arch.machine_ranks, host_arch2.machine_ranks)
109 other = arch.get_architecture('FooBar', 'i486')
110 self.assertEquals(2, len(other.os_ranks))
112 assert 'FooBar' in other.os_ranks
113 assert None in other.os_ranks
114 assert 'i486' in other.machine_ranks
115 assert 'ppc' not in other.machine_ranks
117 suite = unittest.makeSuite(TestSolver)
118 if __name__ == '__main__':
119 sys.argv.append('-v')
120 unittest.main()