Import _ explicitly in the GUI
[zeroinstall/solver.git] / tests / testpolicy.py
blob511deb75daa02b6d8263d558b66d01693edd542c
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 model
8 from zeroinstall.injector.policy import Policy
10 import warnings
11 import logging
12 logger = logging.getLogger()
13 #logger.setLevel(logging.DEBUG)
15 class TestPolicy(BaseTest):
16 def testSource(self):
17 iface_cache = self.config.iface_cache
18 warnings.filterwarnings("ignore", category = DeprecationWarning)
20 foo = iface_cache.get_interface('http://foo/Binary.xml')
21 self.import_feed(foo.uri, 'Binary.xml')
22 foo_src = iface_cache.get_interface('http://foo/Source.xml')
23 self.import_feed(foo_src.uri, 'Source.xml')
24 compiler = iface_cache.get_interface('http://foo/Compiler.xml')
25 self.import_feed(compiler.uri, 'Compiler.xml')
27 p = Policy('http://foo/Binary.xml', config = self.config)
28 p.freshness = 0
29 p.network_use = model.network_full
30 p.recalculate() # Deprecated
31 assert p.implementation[foo].id == 'sha1=123'
33 # Now ask for source instead
34 p.requirements.source = True
35 p.requirements.command = 'compile'
36 p.recalculate()
37 assert p.solver.ready, p.solver.get_failure_reason()
38 assert p.implementation[foo].id == 'sha1=234' # The source
39 assert p.implementation[compiler].id == 'sha1=345' # A binary needed to compile it
41 if __name__ == '__main__':
42 unittest.main()