Better diagnostics when no <runner> can be selected
[zeroinstall/zeroinstall-afb.git] / tests / testpolicy.py
blobeb247cc1c12ab87dbc77995f7423da67916622b4
1 #!/usr/bin/env python
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 warnings
11 import logging
12 logger = logging.getLogger()
13 #logger.setLevel(logging.DEBUG)
15 class TestPolicy(BaseTest):
16 def testSource(self):
17 warnings.filterwarnings("ignore", category = DeprecationWarning)
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 p = autopolicy.AutoPolicy('http://foo/Binary.xml', dry_run = True)
27 p.freshness = 0
28 p.network_use = model.network_full
29 p.recalculate() # Deprecated
30 assert p.implementation[foo].id == 'sha1=123'
32 # Now ask for source instead
33 p.src = True
34 p.command = 'compile'
35 p.recalculate()
36 assert p.implementation[foo].id == 'sha1=234' # The source
37 assert p.implementation[compiler].id == 'sha1=345' # A binary needed to compile it
39 if __name__ == '__main__':
40 unittest.main()