1 #!/usr/bin/env python2.3
2 import sys
, tempfile
, os
, shutil
5 sys
.path
.insert(0, '..')
6 from zeroinstall
.injector
import autopolicy
, basedir
, reader
, model
7 from zeroinstall
.injector
.iface_cache
import iface_cache
10 logger
= logging
.getLogger()
11 #logger.setLevel(logging.DEBUG)
13 class TestPolicy(unittest
.TestCase
):
15 self
.config_home
= tempfile
.mktemp()
16 os
.environ
['XDG_CONFIG_HOME'] = self
.config_home
19 assert basedir
.xdg_config_home
== self
.config_home
20 os
.mkdir(self
.config_home
, 0700)
22 iface_cache
.__init
__()
25 shutil
.rmtree(self
.config_home
)
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)
37 p
.network_use
= model
.network_full
39 assert p
.implementation
[foo
].id == 'sha1=123'
41 # Now ask for source instead
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__':