aboutsummaryrefslogtreecommitdiffstats
path: root/lib/python2.7/site-packages/buildbot-0.8.8-py2.7.egg/buildbot/test/unit/test_scripts_start.py
blob: ddf04d9a8bc4756c74499e0e8f3f0a890630f165 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# This file is part of Buildbot.  Buildbot is free software: you can
# redistribute it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright Buildbot Team Members

from __future__ import with_statement

import os, sys
import twisted
from twisted.python import versions
from twisted.internet.utils import getProcessOutputAndValue
from twisted.trial import unittest
from buildbot.scripts import start
from buildbot.test.util import dirs, misc, compat

def mkconfig(**kwargs):
    config = {
            'quiet': False,
            'basedir': os.path.abspath('basedir'),
            'nodaemon': False,
            }
    config.update(kwargs)
    return config

fake_master_tac = """\
from twisted.application import service
from twisted.python import log
from twisted.internet import reactor
application = service.Application('highscore')
class App(service.Service):
    def startService(self):
        service.Service.startService(self)
        log.msg("BuildMaster is running") # heh heh heh
        reactor.callLater(0, reactor.stop)
app = App()
app.setServiceParent(application)
# isBuildmasterDir wants to see this -> Application('buildmaster')
"""

class TestStart(misc.StdoutAssertionsMixin, dirs.DirsMixin, unittest.TestCase):

    def setUp(self):
        self.setUpDirs('basedir')
        with open(os.path.join('basedir', 'buildbot.tac'), 'wt') as f:
            f.write(fake_master_tac)
        self.setUpStdoutAssertions()

    def tearDown(self):
        self.tearDownDirs()

    # tests

    def test_start_not_basedir(self):
        self.assertEqual(start.start(mkconfig(basedir='doesntexist')), 1)
        self.assertInStdout('invalid buildmaster directory')

    def runStart(self, **config):
        args=[
                '-c',
                'from buildbot.scripts.start import start; start(%r)' % (mkconfig(**config),),
                ]
        env = os.environ.copy()
        env['PYTHONPATH'] = os.pathsep.join(sys.path)
        return getProcessOutputAndValue(sys.executable, args=args, env=env)

    def test_start_no_daemon(self):
        d = self.runStart(nodaemon=True)
        @d.addCallback
        def cb(res):
            self.assertEquals(res, ('', '', 0))
            print res
        return d

    def test_start_quiet(self):
        d = self.runStart(quiet=True)
        @d.addCallback
        def cb(res):
            self.assertEquals(res, ('', '', 0))
            print res
        return d

    @compat.skipUnlessPlatformIs('posix')
    def test_start(self):
        d = self.runStart()
        @d.addCallback
        def cb((out, err, rc)):
            self.assertEqual((rc, err), (0, ''))
            self.assertSubstring('BuildMaster is running', out)
        return d

    if twisted.version <= versions.Version('twisted', 9, 0, 0):
        test_start.skip = test_start_quiet.skip = "Skipping due to suprious PotentialZombieWarning."

    # the remainder of this script does obscene things:
    #  - forks
    #  - shells out to tail
    #  - starts and stops the reactor
    # so testing it will be *far* more pain than is worthwhile