Added tooltips for the action buttons in the 0desktop list.
[zeroinstall/zeroinstall-rsl.git] / tests / testalias.py
blobaf714ad079d118fec2ea6a60d531173c48f1948a
1 #!/usr/bin/env python2.4
2 from basetest import BaseTest
3 import sys, tempfile, os, shutil, logging
4 from StringIO import StringIO
5 import unittest
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' "$@"
15 else
16 exec 0launch 'http://example.com/foo.xml' "$@"
18 """
20 expected_script_main = """#!/bin/sh
21 if [ "$*" = "--versions" ]; then
22 exec 0launch -gd 'http://example.com/foo.xml' "$@"
23 else
24 exec 0launch --main 'a'\\'''\\''\\test' 'http://example.com/foo.xml' "$@"
26 """
28 class TestAlias(BaseTest):
29 def setUp(self):
30 BaseTest.setUp(self)
32 def testWrite(self):
33 buf = StringIO()
34 alias.write_script(buf, 'http://example.com/foo.xml', None)
35 self.assertEquals(expected_script, buf.getvalue())
37 buf = StringIO()
38 alias.write_script(buf, 'http://example.com/foo.xml', 'a\'\'\\test')
39 self.assertEquals(expected_script_main, buf.getvalue())
41 def testParse(self):
42 tmp = tempfile.NamedTemporaryFile()
43 tmp.write(expected_script)
44 tmp.flush()
45 tmp.seek(0)
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)
52 tmp.flush()
53 tmp.seek(0)
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)
61 tmp.flush()
62 tmp.seek(0)
63 try:
64 alias.parse_script(tmp.name)
65 assert False
66 except alias.NotAnAliasScript:
67 pass
69 suite = unittest.makeSuite(TestAlias)
70 if __name__ == '__main__':
71 sys.argv.append('-v')
72 unittest.main()