~cbehrens/nova/lp844160-build-works-with-zones

1 by Jesse Andrews
initial commit
1
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
2
# See LICENSE for details.
3
4
#
5
from twisted.application import strports
6
from twisted.trial import unittest
7
8
class ParserTestCase(unittest.TestCase):
9
10
    f = "Factory"
11
12
    def testSimpleNumeric(self):
13
        self.assertEqual(strports.parse('80', self.f),
14
                         ('TCP', (80, self.f), {'interface':'', 'backlog':50}))
15
16
    def testSimpleTCP(self):
17
        self.assertEqual(strports.parse('tcp:80', self.f),
18
                         ('TCP', (80, self.f), {'interface':'', 'backlog':50}))
19
20
    def testInterfaceTCP(self):
21
        self.assertEqual(strports.parse('tcp:80:interface=127.0.0.1', self.f),
22
                         ('TCP', (80, self.f),
23
                                 {'interface':'127.0.0.1', 'backlog':50}))
24
25
    def testBacklogTCP(self):
26
        self.assertEqual(strports.parse('tcp:80:backlog=6', self.f),
27
                         ('TCP', (80, self.f),
28
                                 {'interface':'', 'backlog':6}))
29
30
31
    def test_simpleUNIX(self):
32
        """
33
        L{strports.parse} returns a C{'UNIX'} port description with defaults
34
        for C{'mode'}, C{'backlog'}, and C{'wantPID'} when passed a string with
35
        the C{'unix:'} prefix and no other parameter values.
36
        """
37
        self.assertEqual(
38
            strports.parse('unix:/var/run/finger', self.f),
39
            ('UNIX', ('/var/run/finger', self.f),
40
             {'mode': 0666, 'backlog': 50, 'wantPID': True}))
41
42
43
    def test_modeUNIX(self):
44
        """
45
        C{mode} can be set by including C{"mode=<some integer>"}.
46
        """
47
        self.assertEqual(
48
            strports.parse('unix:/var/run/finger:mode=0660', self.f),
49
            ('UNIX', ('/var/run/finger', self.f),
50
             {'mode': 0660, 'backlog': 50, 'wantPID': True}))
51
52
53
    def test_wantPIDUNIX(self):
54
        """
55
        C{wantPID} can be set to false by included C{"lockfile=0"}.
56
        """
57
        self.assertEqual(
58
            strports.parse('unix:/var/run/finger:lockfile=0', self.f),
59
            ('UNIX', ('/var/run/finger', self.f),
60
             {'mode': 0666, 'backlog': 50, 'wantPID': False}))
61
62
63
    def testAllKeywords(self):
64
        self.assertEqual(strports.parse('port=80', self.f),
65
                         ('TCP', (80, self.f), {'interface':'', 'backlog':50}))
66
67
    def testEscape(self):
68
        self.assertEqual(
69
            strports.parse(r'unix:foo\:bar\=baz\:qux\\', self.f),
70
            ('UNIX', ('foo:bar=baz:qux\\', self.f),
71
             {'mode': 0666, 'backlog': 50, 'wantPID': True}))
72
73
74
    def testImpliedEscape(self):
75
        self.assertEqual(
76
            strports.parse(r'unix:address=foo=bar', self.f),
77
            ('UNIX', ('foo=bar', self.f),
78
             {'mode': 0666, 'backlog': 50, 'wantPID': True}))
79
80
    def testNonstandardDefault(self):
81
        self.assertEqual(
82
            strports.parse('filename', self.f, 'unix'),
83
            ('UNIX', ('filename', self.f),
84
             {'mode': 0666, 'backlog': 50, 'wantPID': True}))