Added support for arguments in a <command>
[zeroinstall/zeroinstall-limyreth.git] / tests / testrun.py
blob65bc9799ec931d26da4d942991490fcf0265173a
1 #!/usr/bin/env python
2 from basetest import BaseTest
3 import os, sys, subprocess
4 import unittest
5 from StringIO import StringIO
7 sys.path.insert(0, '..')
9 from zeroinstall.injector import policy, run, handler, model
11 mydir = os.path.abspath(os.path.dirname(__file__))
12 local_0launch = os.path.join(os.path.dirname(mydir), '0launch')
13 runnable = os.path.join(mydir, 'runnable', 'Runnable.xml')
15 class TestRun(BaseTest):
16 def testRunnable(self):
17 child = subprocess.Popen([local_0launch, '--', runnable, 'user-arg'], stdout = subprocess.PIPE)
18 stdout, _ = child.communicate()
19 assert 'Args: command-arg -- user-arg' in stdout, stdout
21 def testCommandBindings(self):
22 command_feed = os.path.join(mydir, 'Command.xml')
23 h = handler.Handler()
24 p = policy.Policy(command_feed, handler = h)
25 h.wait_for_blocker(p.solve_with_downloads())
26 old_stdout = sys.stdout
27 try:
28 sys.stdout = StringIO()
29 run.execute_selections(p.solver.selections, [], main = '.', dry_run = True)
30 finally:
31 sys.stdout = old_stdout
32 assert 'local' in os.environ['LOCAL'], os.environ['LOCAL']
34 if __name__ == '__main__':
35 unittest.main()