Fix zero-install.ui duplicate object
[zeroinstall/solver.git] / tests / testpolicy.py
blob0667bf5ad92992a137634d3558ffe58fd2ab994e
1 #!/usr/bin/env python2.5
2 from basetest import BaseTest
3 import sys
4 import unittest
6 sys.path.insert(0, '..')
7 from zeroinstall.injector import autopolicy, reader, model
8 from zeroinstall.injector.iface_cache import iface_cache
10 import logging
11 logger = logging.getLogger()
12 #logger.setLevel(logging.DEBUG)
14 class TestPolicy(BaseTest):
15 def testSource(self):
16 foo = iface_cache.get_interface('http://foo/Binary.xml')
17 reader.update(foo, 'Binary.xml')
18 foo_src = iface_cache.get_interface('http://foo/Source.xml')
19 reader.update(foo_src, 'Source.xml')
20 compiler = iface_cache.get_interface('http://foo/Compiler.xml')
21 reader.update(compiler, 'Compiler.xml')
23 p = autopolicy.AutoPolicy('http://foo/Binary.xml', dry_run = True)
24 p.freshness = 0
25 p.network_use = model.network_full
26 p.recalculate()
27 assert p.implementation[foo].id == 'sha1=123'
29 # Now ask for source instead
30 p.src = True
31 p.recalculate()
32 assert p.implementation[foo].id == 'sha1=234' # The source
33 assert p.implementation[compiler].id == 'sha1=345' # A binary needed to compile it
35 suite = unittest.makeSuite(TestPolicy)
36 if __name__ == '__main__':
37 sys.argv.append('-v')
38 unittest.main()