1 #!/usr/bin/env python2.5
2 from basetest
import BaseTest
4 from StringIO
import StringIO
7 sys
.path
.insert(0, '..')
9 from zeroinstall
import alias
11 expected_script
= """#!/bin/sh
12 if [ "$*" = "--versions" ]; then
13 exec 0launch -gd 'http://example.com/foo.xml' "$@"
15 exec 0launch 'http://example.com/foo.xml' "$@"
19 expected_script_main
= """#!/bin/sh
20 if [ "$*" = "--versions" ]; then
21 exec 0launch -gd 'http://example.com/foo.xml' "$@"
23 exec 0launch --main 'a'\\'''\\''\\test' 'http://example.com/foo.xml' "$@"
27 class TestAlias(BaseTest
):
33 alias
.write_script(buf
, 'http://example.com/foo.xml', None)
34 self
.assertEquals(expected_script
, buf
.getvalue())
37 alias
.write_script(buf
, 'http://example.com/foo.xml', 'a\'\'\\test')
38 self
.assertEquals(expected_script_main
, buf
.getvalue())
41 tmp
= tempfile
.NamedTemporaryFile()
42 tmp
.write(expected_script
)
45 uri
, main
= alias
.parse_script(tmp
.name
)
46 self
.assertEquals('http://example.com/foo.xml', uri
)
47 self
.assertEquals(None, main
)
49 tmp
= tempfile
.NamedTemporaryFile()
50 tmp
.write(expected_script_main
)
53 uri
, main
= alias
.parse_script(tmp
.name
)
54 self
.assertEquals('http://example.com/foo.xml', uri
)
55 self
.assertEquals('a\'\'\\test', main
)
57 def testParseException(self
):
58 tmp
= tempfile
.NamedTemporaryFile()
59 tmp
.write('hi' + expected_script
)
63 alias
.parse_script(tmp
.name
)
65 except alias
.NotAnAliasScript
:
68 suite
= unittest
.makeSuite(TestAlias
)
69 if __name__
== '__main__':