Only show two decimal places for download progress percentages.
[zeroinstall/zeroinstall-rsl.git] / tests / testpolicy.py
blob5e9c47e9fb578ddbf6f7d28a1b38c2c8ad11f23b
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.injector import autopolicy, reader, model
8 from zeroinstall.injector.iface_cache import iface_cache
9 from zeroinstall.support import basedir
11 import logging
12 logger = logging.getLogger()
13 #logger.setLevel(logging.DEBUG)
15 class TestPolicy(BaseTest):
16 def testSource(self):
17 foo = iface_cache.get_interface('http://foo/Binary.xml')
18 reader.update(foo, 'Binary.xml')
19 foo_src = iface_cache.get_interface('http://foo/Source.xml')
20 reader.update(foo_src, 'Source.xml')
21 compiler = iface_cache.get_interface('http://foo/Compiler.xml')
22 reader.update(compiler, 'Compiler.xml')
24 p = autopolicy.AutoPolicy('http://foo/Binary.xml', dry_run = True)
25 p.freshness = 0
26 p.network_use = model.network_full
27 p.recalculate()
28 assert p.implementation[foo].id == 'sha1=123'
30 # Now ask for source instead
31 p.src = True
32 p.recalculate()
33 assert p.implementation[foo].id == 'sha1=234' # The source
34 assert p.implementation[compiler].id == 'sha1=345' # A binary needed to compile it
36 suite = unittest.makeSuite(TestPolicy)
37 if __name__ == '__main__':
38 sys.argv.append('-v')
39 unittest.main()