When run with -v, log the 0launch version, arguments and Python version.
[zeroinstall.git] / tests / testpolicy.py
blobddcd8f1e07aef74186209dea4bbb32af29464f44
1 #!/usr/bin/env python2.3
2 import sys, tempfile, os, shutil
3 import unittest
5 sys.path.insert(0, '..')
6 from zeroinstall.injector import autopolicy, basedir, reader, model
7 from zeroinstall.injector.iface_cache import iface_cache
9 import logging
10 logger = logging.getLogger()
11 #logger.setLevel(logging.DEBUG)
13 class TestPolicy(unittest.TestCase):
14 def setUp(self):
15 self.config_home = tempfile.mktemp()
16 os.environ['XDG_CONFIG_HOME'] = self.config_home
17 reload(basedir)
19 assert basedir.xdg_config_home == self.config_home
20 os.mkdir(self.config_home, 0700)
22 iface_cache.__init__()
24 def tearDown(self):
25 shutil.rmtree(self.config_home)
27 def testSource(self):
28 foo = iface_cache.get_interface('http://foo/Binary.xml')
29 reader.update(foo, 'Binary.xml')
30 foo_src = iface_cache.get_interface('http://foo/Source.xml')
31 reader.update(foo_src, 'Source.xml')
32 compiler = iface_cache.get_interface('http://foo/Compiler.xml')
33 reader.update(compiler, 'Compiler.xml')
35 p = autopolicy.AutoPolicy('http://foo/Binary.xml', dry_run = True)
36 p.freshness = 0
37 p.network_use = model.network_full
38 p.recalculate()
39 assert p.implementation[foo].id == 'sha1=123'
41 # Now ask for source instead
42 p.src = True
43 p.recalculate()
44 assert p.implementation[foo].id == 'sha1=234' # The source
45 assert p.implementation[compiler].id == 'sha1=345' # A binary needed to compile it
47 suite = unittest.makeSuite(TestPolicy)
48 if __name__ == '__main__':
49 sys.argv.append('-v')
50 unittest.main()