1 #!/usr/bin/env python2.4
2 from basetest
import BaseTest
3 import sys
, tempfile
, os
, shutil
, logging
4 from StringIO
import StringIO
6 from logging
import getLogger
, DEBUG
, INFO
8 sys
.path
.insert(0, '..')
10 from zeroinstall
import alias
12 expected_script
= """#!/bin/sh
13 if [ "$*" = "--versions" ]; then
14 exec 0launch -gd 'http://example.com/foo.xml' "$@"
16 exec 0launch 'http://example.com/foo.xml' "$@"
20 expected_script_main
= """#!/bin/sh
21 if [ "$*" = "--versions" ]; then
22 exec 0launch -gd 'http://example.com/foo.xml' "$@"
24 exec 0launch --main 'a'\\'''\\''\\test' 'http://example.com/foo.xml' "$@"
28 class TestAlias(BaseTest
):
34 alias
.write_script(buf
, 'http://example.com/foo.xml', None)
35 self
.assertEquals(expected_script
, buf
.getvalue())
38 alias
.write_script(buf
, 'http://example.com/foo.xml', 'a\'\'\\test')
39 self
.assertEquals(expected_script_main
, buf
.getvalue())
42 tmp
= tempfile
.NamedTemporaryFile()
43 tmp
.write(expected_script
)
46 uri
, main
= alias
.parse_script(tmp
.name
)
47 self
.assertEquals('http://example.com/foo.xml', uri
)
48 self
.assertEquals(None, main
)
50 tmp
= tempfile
.NamedTemporaryFile()
51 tmp
.write(expected_script_main
)
54 uri
, main
= alias
.parse_script(tmp
.name
)
55 self
.assertEquals('http://example.com/foo.xml', uri
)
56 self
.assertEquals('a\'\'\\test', main
)
58 def testParseException(self
):
59 tmp
= tempfile
.NamedTemporaryFile()
60 tmp
.write('hi' + expected_script
)
64 alias
.parse_script(tmp
.name
)
66 except alias
.NotAnAliasScript
:
69 suite
= unittest
.makeSuite(TestAlias
)
70 if __name__
== '__main__':