1 #!/usr/bin/env python2.4
7 sys
.path
.insert(0, '..')
9 from basetest
import BaseTest
10 from zeroinstall
.injector
import autopolicy
11 from zeroinstall
.injector
import run
12 from zeroinstall
.injector
.iface_cache
import iface_cache
13 from zeroinstall
.zerostore
import manifest
16 def write_file(filename
, data
):
17 fh
= open(filename
, "w")
24 # Based on code in 0publish/archive.py
25 def manifest_for_dir(dir):
26 algorithm
= manifest
.get_algorithm("sha1new")
27 digest
= algorithm
.new_digest()
28 for line
in algorithm
.generate_manifest(dir):
29 digest
.update(line
+ '\n')
30 return algorithm
.getID(digest
)
33 class TestEndToEnd(BaseTest
):
34 def _make_hello(self
):
35 tar_file
= os
.path
.join(self
.make_temp_dir(), "archive.tar.gz")
36 temp_dir
= self
.make_temp_dir()
37 write_file(os
.path
.join(temp_dir
, "hello-test"), """\
41 os
.chmod(os
.path
.join(temp_dir
, "hello-test"), 0777)
42 subprocess
.check_call(["tar", "-czf", tar_file
, "-C", temp_dir
, "."])
44 <implementation id="%s" version="1">
45 <archive href="%s" size="%i"/>
47 """ % (manifest_for_dir(temp_dir
), tar_file
, os
.path
.getsize(tar_file
))
50 tempdir
= self
.make_temp_dir()
51 feed_file
= os
.path
.join(tempdir
, "foo.xml")
52 write_file(feed_file
, """
53 <interface xmlns="http://zero-install.sourceforge.net/2004/injector/interface">
55 <summary>Placeholder</summary>
56 <group main="hello-test">
60 """ % self
._make
_hello
())
61 policy
= autopolicy
.AutoPolicy(
62 feed_file
, download_only
=True, dry_run
=False)
63 policy
.download_and_execute([])
64 root_impl
= policy
.get_implementation(
65 iface_cache
.get_interface(policy
.root
))
66 cmd_path
= os
.path
.join(run
._get
_implementation
_path
(root_impl
.id),
68 proc
= subprocess
.Popen([cmd_path
], stdout
=subprocess
.PIPE
)
69 stdout
, stderr
= proc
.communicate()
70 self
.assertEquals(proc
.wait(), 0)
71 self
.assertEquals(stdout
, "Hello World\n")
74 suite
= unittest
.makeSuite(TestEndToEnd
)
75 if __name__
== '__main__':