diff options
Diffstat (limited to 'lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit')
23 files changed, 0 insertions, 5173 deletions
diff --git a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/__init__.py b/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/__init__.py +++ /dev/null diff --git a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/runprocess-scripts.py b/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/runprocess-scripts.py deleted file mode 100644 index 05715cb4..00000000 --- a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/runprocess-scripts.py +++ /dev/null @@ -1,108 +0,0 @@ -# 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 - -# This file contains scripts run by the test_runprocess tests. Note that since -# this code runs in a different Python interpreter, it does not necessarily -# have access to any of the Buildbot source. Functions here should be kept -# very simple! - -import sys -import os -import time -import select -import signal - -# utils - -def write_pidfile(pidfile): - pidfile_tmp = pidfile + "~" - f = open(pidfile_tmp, "w") - f.write(str(os.getpid())) - f.close() - os.rename(pidfile_tmp, pidfile) - -def sleep_forever(): - signal.alarm(110) # die after 110 seconds - while True: - time.sleep(10) - -def wait_for_parent_death(): - while True: - ppid = os.getppid() - if ppid == 1: - return - # on some systems, getppid will keep returning - # a dead pid, so check it for liveness - try: - os.kill(ppid, 0) - except OSError: # Probably ENOSUCH - return - -script_fns = {} -def script(fn): - script_fns[fn.func_name] = fn - return fn - -# scripts - -@script -def write_pidfile_and_sleep(): - pidfile = sys.argv[2] - write_pidfile(pidfile) - sleep_forever() - -@script -def spawn_child(): - parent_pidfile, child_pidfile = sys.argv[2:] - if os.fork() == 0: - write_pidfile(child_pidfile) - else: - write_pidfile(parent_pidfile) - sleep_forever() - -@script -def double_fork(): - # when using a PTY, the child process will get SIGHUP when the - # parent process exits, so ignore that. - signal.signal(signal.SIGHUP, signal.SIG_IGN) - parent_pidfile, child_pidfile = sys.argv[2:] - if os.fork() == 0: - wait_for_parent_death() - write_pidfile(child_pidfile) - sleep_forever() - else: - write_pidfile(parent_pidfile) - sys.exit(0) - -@script -def assert_stdin_closed(): - # EOF counts as readable data, so we should see stdin in the readable list, - # although it may not appear immediately, and select may return early - bail_at = time.time() + 10 - while True: - r, w, x = select.select([0], [], [], 0.01) - if r == [0]: return # succcess! - if time.time() > bail_at: - assert False # failure :( - -# make sure this process dies if necessary - -if not hasattr(signal, 'alarm'): - signal.alarm = lambda t : None -signal.alarm(110) # die after 110 seconds - -# dispatcher - -script_fns[sys.argv[1]]() diff --git a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_bot.py b/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_bot.py deleted file mode 100644 index 24a97ea7..00000000 --- a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_bot.py +++ /dev/null @@ -1,379 +0,0 @@ -# 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 - -import os -import shutil -import mock - -from twisted.trial import unittest -from twisted.internet import defer, reactor, task -from twisted.python import failure, log - -from buildslave.test.util import command, compat -from buildslave.test.fake.remote import FakeRemote -from buildslave.test.fake.runprocess import Expect -import buildslave -from buildslave import bot - -class TestBot(unittest.TestCase): - - def setUp(self): - self.basedir = os.path.abspath("basedir") - if os.path.exists(self.basedir): - shutil.rmtree(self.basedir) - os.makedirs(self.basedir) - - self.real_bot = bot.Bot(self.basedir, False) - self.real_bot.startService() - - self.bot = FakeRemote(self.real_bot) - - def tearDown(self): - d = defer.succeed(None) - if self.real_bot and self.real_bot.running: - d.addCallback(lambda _ : self.real_bot.stopService()) - if os.path.exists(self.basedir): - shutil.rmtree(self.basedir) - return d - - def test_getCommands(self): - d = self.bot.callRemote("getCommands") - def check(cmds): - # just check that 'shell' is present.. - self.assertTrue('shell' in cmds) - d.addCallback(check) - return d - - def test_getVersion(self): - d = self.bot.callRemote("getVersion") - def check(vers): - self.assertEqual(vers, buildslave.version) - d.addCallback(check) - return d - - def test_getSlaveInfo(self): - infodir = os.path.join(self.basedir, "info") - os.makedirs(infodir) - open(os.path.join(infodir, "admin"), "w").write("testy!") - open(os.path.join(infodir, "foo"), "w").write("bar") - open(os.path.join(infodir, "environ"), "w").write("something else") - - d = self.bot.callRemote("getSlaveInfo") - def check(info): - self.assertEqual(info, dict(admin='testy!', foo='bar', environ=os.environ, system=os.name, basedir=self.basedir)) - d.addCallback(check) - return d - - def test_getSlaveInfo_nodir(self): - d = self.bot.callRemote("getSlaveInfo") - def check(info): - self.assertEqual(set(info.keys()), set(['environ','system','basedir'])) - d.addCallback(check) - return d - - def test_setBuilderList_empty(self): - d = self.bot.callRemote("setBuilderList", []) - def check(builders): - self.assertEqual(builders, {}) - d.addCallback(check) - return d - - def test_setBuilderList_single(self): - d = self.bot.callRemote("setBuilderList", [ ('mybld', 'myblddir') ]) - def check(builders): - self.assertEqual(builders.keys(), ['mybld']) - self.assertTrue(os.path.exists(os.path.join(self.basedir, 'myblddir'))) - # note that we test the SlaveBuilder instance below - d.addCallback(check) - return d - - def test_setBuilderList_updates(self): - d = defer.succeed(None) - - slavebuilders = {} - - def add_my(_): - d = self.bot.callRemote("setBuilderList", [ - ('mybld', 'myblddir') ]) - def check(builders): - self.assertEqual(builders.keys(), ['mybld']) - self.assertTrue(os.path.exists(os.path.join(self.basedir, 'myblddir'))) - slavebuilders['my'] = builders['mybld'] - d.addCallback(check) - return d - d.addCallback(add_my) - - def add_your(_): - d = self.bot.callRemote("setBuilderList", [ - ('mybld', 'myblddir'), ('yourbld', 'yourblddir') ]) - def check(builders): - self.assertEqual(sorted(builders.keys()), sorted(['mybld', 'yourbld'])) - self.assertTrue(os.path.exists(os.path.join(self.basedir, 'myblddir'))) - self.assertTrue(os.path.exists(os.path.join(self.basedir, 'yourblddir'))) - # 'my' should still be the same slavebuilder object - self.assertEqual(id(slavebuilders['my']), id(builders['mybld'])) - slavebuilders['your'] = builders['yourbld'] - d.addCallback(check) - return d - d.addCallback(add_your) - - def remove_my(_): - d = self.bot.callRemote("setBuilderList", [ - ('yourbld', 'yourblddir2') ]) # note new builddir - def check(builders): - self.assertEqual(sorted(builders.keys()), sorted(['yourbld'])) - # note that build dirs are not deleted.. - self.assertTrue(os.path.exists(os.path.join(self.basedir, 'myblddir'))) - self.assertTrue(os.path.exists(os.path.join(self.basedir, 'yourblddir'))) - self.assertTrue(os.path.exists(os.path.join(self.basedir, 'yourblddir2'))) - # 'your' should still be the same slavebuilder object - self.assertEqual(id(slavebuilders['your']), id(builders['yourbld'])) - d.addCallback(check) - return d - d.addCallback(remove_my) - - def add_and_remove(_): - d = self.bot.callRemote("setBuilderList", [ - ('theirbld', 'theirblddir') ]) - def check(builders): - self.assertEqual(sorted(builders.keys()), sorted(['theirbld'])) - self.assertTrue(os.path.exists(os.path.join(self.basedir, 'myblddir'))) - self.assertTrue(os.path.exists(os.path.join(self.basedir, 'yourblddir'))) - self.assertTrue(os.path.exists(os.path.join(self.basedir, 'theirblddir'))) - d.addCallback(check) - return d - d.addCallback(add_and_remove) - - return d - - def test_shutdown(self): - d1 = defer.Deferred() - self.patch(reactor, "stop", lambda : d1.callback(None)) - d2 = self.bot.callRemote("shutdown") - # don't return until both the shutdown method has returned, and - # reactor.stop has been called - return defer.gatherResults([d1, d2]) - -class FakeStep(object): - "A fake master-side BuildStep that records its activities." - def __init__(self): - self.finished_d = defer.Deferred() - self.actions = [] - - def wait_for_finish(self): - return self.finished_d - - def remote_update(self, updates): - for update in updates: - if 'elapsed' in update[0]: - update[0]['elapsed'] = 1 - self.actions.append(["update", updates]) - - def remote_complete(self, f): - self.actions.append(["complete", f]) - self.finished_d.callback(None) - -class TestSlaveBuilder(command.CommandTestMixin, unittest.TestCase): - - @defer.deferredGenerator - def setUp(self): - self.basedir = os.path.abspath("basedir") - if os.path.exists(self.basedir): - shutil.rmtree(self.basedir) - os.makedirs(self.basedir) - - self.bot = bot.Bot(self.basedir, False) - self.bot.startService() - - # get a SlaveBuilder object from the bot and wrap it as a fake remote - wfd = defer.waitForDeferred( - self.bot.remote_setBuilderList([('sb', 'sb')])) - yield wfd - builders = wfd.getResult() - self.sb = FakeRemote(builders['sb']) - - self.setUpCommand() - - def tearDown(self): - self.tearDownCommand() - - d = defer.succeed(None) - if self.bot and self.bot.running: - d.addCallback(lambda _ : self.bot.stopService()) - if os.path.exists(self.basedir): - shutil.rmtree(self.basedir) - return d - - def test_print(self): - return self.sb.callRemote("print", "Hello, SlaveBuilder.") - - def test_setMaster(self): - # not much to check here - what the SlaveBuilder does with the - # master is not part of the interface (and, in fact, it does very little) - return self.sb.callRemote("setMaster", mock.Mock()) - - def test_shutdown(self): - # don't *actually* shut down the reactor - that would be silly - stop = mock.Mock() - self.patch(reactor, "stop", stop) - d = self.sb.callRemote("shutdown") - def check(_): - self.assertTrue(stop.called) - d.addCallback(check) - return d - - def test_startBuild(self): - return self.sb.callRemote("startBuild") - - def test_startCommand(self): - # set up a fake step to receive updates - st = FakeStep() - - # patch runprocess to handle the 'echo', below - self.patch_runprocess( - Expect([ 'echo', 'hello' ], os.path.join(self.basedir, 'sb', 'workdir')) - + { 'hdr' : 'headers' } + { 'stdout' : 'hello\n' } + { 'rc' : 0 } - + 0, - ) - - d = defer.succeed(None) - def do_start(_): - return self.sb.callRemote("startCommand", FakeRemote(st), - "13", "shell", dict( - command=[ 'echo', 'hello' ], - workdir='workdir', - )) - d.addCallback(do_start) - d.addCallback(lambda _ : st.wait_for_finish()) - def check(_): - self.assertEqual(st.actions, [ - ['update', [[{'hdr': 'headers'}, 0]]], - ['update', [[{'stdout': 'hello\n'}, 0]]], - ['update', [[{'rc': 0}, 0]]], - ['update', [[{'elapsed': 1}, 0]]], - ['complete', None], - ]) - d.addCallback(check) - return d - - def test_startCommand_interruptCommand(self): - # set up a fake step to receive updates - st = FakeStep() - - # patch runprocess to pretend to sleep (it will really just hang forever, - # except that we interrupt it) - self.patch_runprocess( - Expect([ 'sleep', '10' ], os.path.join(self.basedir, 'sb', 'workdir')) - + { 'hdr' : 'headers' } - + { 'wait' : True } - ) - - d = defer.succeed(None) - def do_start(_): - return self.sb.callRemote("startCommand", FakeRemote(st), - "13", "shell", dict( - command=[ 'sleep', '10' ], - workdir='workdir', - )) - d.addCallback(do_start) - - # wait a jiffy.. - def do_wait(_): - d = defer.Deferred() - reactor.callLater(0.01, d.callback, None) - return d - d.addCallback(do_wait) - - # and then interrupt the step - def do_interrupt(_): - return self.sb.callRemote("interruptCommand", "13", "tl/dr") - d.addCallback(do_interrupt) - - d.addCallback(lambda _ : st.wait_for_finish()) - def check(_): - self.assertEqual(st.actions, [ - ['update', [[{'hdr': 'headers'}, 0]]], - ['update', [[{'hdr': 'killing'}, 0]]], - ['update', [[{'rc': -1}, 0]]], - ['complete', None], - ]) - d.addCallback(check) - return d - - def test_startCommand_failure(self): - # similar to test_startCommand, but leave out some args so the slave - # generates a failure - - # set up a fake step to receive updates - st = FakeStep() - - # patch the log.err, otherwise trial will think something *actually* failed - self.patch(log, "err", lambda f : None) - - d = defer.succeed(None) - def do_start(_): - return self.sb.callRemote("startCommand", FakeRemote(st), - "13", "shell", dict( - workdir='workdir', - )) - d.addCallback(do_start) - d.addCallback(lambda _ : st.wait_for_finish()) - def check(_): - self.assertEqual(st.actions[1][0], 'complete') - self.assertTrue(isinstance(st.actions[1][1], failure.Failure)) - d.addCallback(check) - return d - -class TestBotFactory(unittest.TestCase): - - def setUp(self): - self.bf = bot.BotFactory('mstr', 9010, 35, 200) - - # tests - - def test_timers(self): - clock = self.bf._reactor = task.Clock() - - calls = [] - def callRemote(method): - calls.append(clock.seconds()) - self.assertEqual(method, 'keepalive') - # simulate the response taking a few seconds - d = defer.Deferred() - clock.callLater(5, d.callback, None) - return d - self.bf.perspective = mock.Mock() - self.bf.perspective.callRemote = callRemote - - self.bf.startTimers() - clock.callLater(100, self.bf.stopTimers) - - clock.pump(( 1 for _ in xrange(150))) - self.assertEqual(calls, [ 35, 70 ]) - - @compat.usesFlushLoggedErrors - def test_timers_exception(self): - clock = self.bf._reactor = task.Clock() - - self.bf.perspective = mock.Mock() - def callRemote(method): - return defer.fail(RuntimeError("oh noes")) - self.bf.perspective.callRemote = callRemote - - self.bf.startTimers() - clock.advance(35) - self.assertEqual(len(self.flushLoggedErrors(RuntimeError)), 1) - -# note that the BuildSlave class is tested in test_bot_BuildSlave diff --git a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_bot_BuildSlave.py b/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_bot_BuildSlave.py deleted file mode 100644 index 80d46cc7..00000000 --- a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_bot_BuildSlave.py +++ /dev/null @@ -1,234 +0,0 @@ -# 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 - -import os -import shutil -import socket - -from twisted.trial import unittest -from twisted.spread import pb -from twisted.internet import reactor, defer -from twisted.cred import checkers, portal -from zope.interface import implements - -from buildslave import bot -from buildslave.test.util import misc - -from mock import Mock - -# I don't see any simple way to test the PB equipment without actually setting -# up a TCP connection. This just tests that the PB code will connect and can -# execute a basic ping. The rest is done without TCP (or PB) in other test modules. - -class MasterPerspective(pb.Avatar): - def __init__(self, on_keepalive=None): - self.on_keepalive = on_keepalive - - def perspective_keepalive(self): - if self.on_keepalive: - on_keepalive, self.on_keepalive = self.on_keepalive, None - on_keepalive() - -class MasterRealm: - def __init__(self, perspective, on_attachment): - self.perspective = perspective - self.on_attachment = on_attachment - - implements(portal.IRealm) - def requestAvatar(self, avatarId, mind, *interfaces): - assert pb.IPerspective in interfaces - self.mind = mind - self.perspective.mind = mind - d = defer.succeed(None) - if self.on_attachment: - d.addCallback(lambda _: self.on_attachment(mind)) - def returnAvatar(_): - return pb.IPerspective, self.perspective, lambda: None - d.addCallback(returnAvatar) - return d - - def shutdown(self): - return self.mind.broker.transport.loseConnection() - -class TestBuildSlave(misc.PatcherMixin, unittest.TestCase): - - def setUp(self): - self.realm = None - self.buildslave = None - self.listeningport = None - - self.basedir = os.path.abspath("basedir") - if os.path.exists(self.basedir): - shutil.rmtree(self.basedir) - os.makedirs(self.basedir) - - def tearDown(self): - d = defer.succeed(None) - if self.realm: - d.addCallback(lambda _ : self.realm.shutdown()) - if self.buildslave and self.buildslave.running: - d.addCallback(lambda _ : self.buildslave.stopService()) - if self.listeningport: - d.addCallback(lambda _ : self.listeningport.stopListening()) - if os.path.exists(self.basedir): - shutil.rmtree(self.basedir) - return d - - def start_master(self, perspective, on_attachment=None): - self.realm = MasterRealm(perspective, on_attachment) - p = portal.Portal(self.realm) - p.registerChecker( - checkers.InMemoryUsernamePasswordDatabaseDontUse(testy="westy")) - self.listeningport = reactor.listenTCP(0, pb.PBServerFactory(p), interface='127.0.0.1') - # return the dynamically allocated port number - return self.listeningport.getHost().port - - def test_constructor_minimal(self): - # only required arguments - bot.BuildSlave('mstr', 9010, 'me', 'pwd', '/s', 10, False) - - def test_constructor_083_tac(self): - # invocation as made from default 083 tac files - bot.BuildSlave('mstr', 9010, 'me', 'pwd', '/s', 10, False, - umask=0123, maxdelay=10) - - def test_constructor_full(self): - # invocation with all args - bot.BuildSlave('mstr', 9010, 'me', 'pwd', '/s', 10, False, - umask=0123, maxdelay=10, keepaliveTimeout=10, - unicode_encoding='utf8', allow_shutdown=True) - - def test_buildslave_print(self): - d = defer.Deferred() - - # set up to call print when we are attached, and chain the results onto - # the deferred for the whole test - def call_print(mind): - print_d = mind.callRemote("print", "Hi, slave.") - print_d.addCallbacks(d.callback, d.errback) - - # start up the master and slave - persp = MasterPerspective() - port = self.start_master(persp, on_attachment=call_print) - self.buildslave = bot.BuildSlave("127.0.0.1", port, - "testy", "westy", self.basedir, - keepalive=0, usePTY=False, umask=022) - self.buildslave.startService() - - # and wait for the result of the print - return d - - def test_recordHostname_uname(self): - self.patch_os_uname(lambda : [ 0, 'test-hostname.domain.com' ]) - - self.buildslave = bot.BuildSlave("127.0.0.1", 9999, - "testy", "westy", self.basedir, - keepalive=0, usePTY=False, umask=022) - self.buildslave.recordHostname(self.basedir) - self.assertEqual(open(os.path.join(self.basedir, "twistd.hostname")).read().strip(), - 'test-hostname.domain.com') - - def test_recordHostname_getfqdn(self): - def missing(): - raise AttributeError - self.patch_os_uname(missing) - self.patch(socket, "getfqdn", lambda : 'test-hostname.domain.com') - - self.buildslave = bot.BuildSlave("127.0.0.1", 9999, - "testy", "westy", self.basedir, - keepalive=0, usePTY=False, umask=022) - self.buildslave.recordHostname(self.basedir) - self.assertEqual(open(os.path.join(self.basedir, "twistd.hostname")).read().strip(), - 'test-hostname.domain.com') - - def test_buildslave_graceful_shutdown(self): - """Test that running the build slave's gracefulShutdown method results - in a call to the master's shutdown method""" - d = defer.Deferred() - - fakepersp = Mock() - called = [] - def fakeCallRemote(*args): - called.append(args) - d1 = defer.succeed(None) - return d1 - fakepersp.callRemote = fakeCallRemote - - # set up to call shutdown when we are attached, and chain the results onto - # the deferred for the whole test - def call_shutdown(mind): - self.buildslave.bf.perspective = fakepersp - shutdown_d = self.buildslave.gracefulShutdown() - shutdown_d.addCallbacks(d.callback, d.errback) - - persp = MasterPerspective() - port = self.start_master(persp, on_attachment=call_shutdown) - - self.buildslave = bot.BuildSlave("127.0.0.1", port, - "testy", "westy", self.basedir, - keepalive=0, usePTY=False, umask=022) - - self.buildslave.startService() - - def check(ign): - self.assertEquals(called, [('shutdown',)]) - d.addCallback(check) - - return d - - def test_buildslave_shutdown(self): - """Test watching an existing shutdown_file results in gracefulShutdown - being called.""" - - buildslave = bot.BuildSlave("127.0.0.1", 1234, - "testy", "westy", self.basedir, - keepalive=0, usePTY=False, umask=022, - allow_shutdown='file') - - # Mock out gracefulShutdown - buildslave.gracefulShutdown = Mock() - - # Mock out os.path methods - exists = Mock() - mtime = Mock() - - self.patch(os.path, 'exists', exists) - self.patch(os.path, 'getmtime', mtime) - - # Pretend that the shutdown file doesn't exist - mtime.return_value = 0 - exists.return_value = False - - buildslave._checkShutdownFile() - - # We shouldn't have called gracefulShutdown - self.assertEquals(buildslave.gracefulShutdown.call_count, 0) - - # Pretend that the file exists now, with an mtime of 2 - exists.return_value = True - mtime.return_value = 2 - buildslave._checkShutdownFile() - - # Now we should have changed gracefulShutdown - self.assertEquals(buildslave.gracefulShutdown.call_count, 1) - - # Bump the mtime again, and make sure we call shutdown again - mtime.return_value = 3 - buildslave._checkShutdownFile() - self.assertEquals(buildslave.gracefulShutdown.call_count, 2) - - # Try again, we shouldn't call shutdown another time - buildslave._checkShutdownFile() - self.assertEquals(buildslave.gracefulShutdown.call_count, 2) diff --git a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_base.py b/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_base.py deleted file mode 100644 index 0385cc3a..00000000 --- a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_base.py +++ /dev/null @@ -1,127 +0,0 @@ -# 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 twisted.trial import unittest -from twisted.internet import defer - -from buildslave.test.util.command import CommandTestMixin -from buildslave.commands.base import Command - -# set up a fake Command subclass to test the handling in Command. Think of -# this as testing Command's subclassability. - -class DummyCommand(Command): - - def setup(self, args): - self.setup_done = True - self.interrupted = False - self.started = False - - def start(self): - self.started = True - self.sendStatus(self.args) - self.cmd_deferred = defer.Deferred() - return self.cmd_deferred - - def interrupt(self): - self.interrupted = True - self.finishCommand() - - def finishCommand(self): - d = self.cmd_deferred - self.cmd_deferred = None - d.callback(None) - - def failCommand(self): - d = self.cmd_deferred - self.cmd_deferred = None - d.errback(RuntimeError("forced failure")) - -class TestDummyCommand(CommandTestMixin, unittest.TestCase): - - def setUp(self): - self.setUpCommand() - - def tearDown(self): - self.tearDownCommand() - - def assertState(self, setup_done, running, started, interrupted, msg=None): - self.assertEqual( - { - 'setup_done' : self.cmd.setup_done, - 'running' : self.cmd.running, - 'started' : self.cmd.started, - 'interrupted' : self.cmd.interrupted, - }, { - 'setup_done' : setup_done, - 'running' : running, - 'started' : started, - 'interrupted' : interrupted, - }, msg) - - def test_run(self): - cmd = self.make_command(DummyCommand, { 'stdout' : 'yay' }) - self.assertState(True, False, False, False, "setup called by constructor") - - # start the command - d = self.run_command() - self.assertState(True, True, True, False, "started and running both set") - - # allow the command to finish and check the result - cmd.finishCommand() - def check(_): - self.assertState(True, False, True, False, "started and not running when done") - d.addCallback(check) - - def checkresult(_): - self.assertUpdates([ { 'stdout' : 'yay' } ], "updates processed") - d.addCallback(checkresult) - return d - - def test_run_failure(self): - cmd = self.make_command(DummyCommand, {}) - self.assertState(True, False, False, False, "setup called by constructor") - - # start the command - d = self.run_command() - self.assertState(True, True, True, False, "started and running both set") - - # fail the command with an exception, and check the result - cmd.failCommand() - def check(_): - self.assertState(True, False, True, False, "started and not running when done") - d.addErrback(check) - - def checkresult(_): - self.assertUpdates([ {} ], "updates processed") - d.addCallback(checkresult) - return d - - def test_run_interrupt(self): - cmd = self.make_command(DummyCommand, {}) - self.assertState(True, False, False, False, "setup called by constructor") - - # start the command - d = self.run_command() - self.assertState(True, True, True, False, "started and running both set") - - # interrupt the command - cmd.doInterrupt() - self.assertTrue(cmd.interrupted) - - def check(_): - self.assertState(True, False, True, True, "finishes with interrupted set") - d.addCallback(check) - return d diff --git a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_bk.py b/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_bk.py deleted file mode 100644 index da3cc352..00000000 --- a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_bk.py +++ /dev/null @@ -1,68 +0,0 @@ -# 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 twisted.trial import unittest - -from buildslave.test.fake.runprocess import Expect -from buildslave.test.util.sourcecommand import SourceCommandTestMixin -from buildslave.commands import bk - -class TestBK(SourceCommandTestMixin, unittest.TestCase): - - def setUp(self): - self.setUpCommand() - - def tearDown(self): - self.tearDownCommand() - - def test_simple(self): - self.patch_getCommand('bk', 'path/to/bk') - self.clean_environ() - self.make_command(bk.BK, dict( - workdir='workdir', - mode='copy', - revision='1.114', - bkurl='http://bkdemo.bkbits.net/bk_demo1', - )) - - exp_environ = dict(PWD='.', LC_MESSAGES='C') - expects = [ - Expect([ 'clobber', 'workdir' ], - self.basedir) - + 0, - Expect([ 'clobber', 'source' ], - self.basedir) - + 0, - Expect(['path/to/bk', 'clone', '-r1.114', - 'http://bkdemo.bkbits.net/bk_demo1', 'source'], - self.basedir, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect(['path/to/bk', 'changes', '-r+', '-d:REV:'], - self.basedir_source, - sendRC=False, usePTY=False, timeout=120, sendStderr=False, - sendStdout=False, keepStdout=True, environ=exp_environ) - + { 'stdout' : '1.114\n' } # TODO: is this what BK outputs? - + 0, - Expect([ 'copy', 'source', 'workdir'], - self.basedir) - + 0, - ] - self.patch_runprocess(*expects) - - d = self.run_command() - # TODO: why the extra quotes? - d.addCallback(self.check_sourcedata, '"http://bkdemo.bkbits.net/bk_demo1\n"') - return d diff --git a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_bzr.py b/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_bzr.py deleted file mode 100644 index d8663acc..00000000 --- a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_bzr.py +++ /dev/null @@ -1,77 +0,0 @@ -# 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 - -import textwrap - -from twisted.trial import unittest - -from buildslave.test.fake.runprocess import Expect -from buildslave.test.util.sourcecommand import SourceCommandTestMixin -from buildslave.commands import bzr - -class TestBzr(SourceCommandTestMixin, unittest.TestCase): - - def setUp(self): - self.setUpCommand() - - def tearDown(self): - self.tearDownCommand() - - def test_simple(self): - self.patch_getCommand('bzr', 'path/to/bzr') - self.clean_environ() - self.make_command(bzr.Bzr, dict( - workdir='workdir', - mode='copy', - revision='12', - repourl='http://bazaar.launchpad.net/~bzr/bzr-gtk/trunk', - )) - - exp_environ = dict(PWD='.', LC_MESSAGES='C') - verinfo = textwrap.dedent("""\ - revision-id: pqm@pqm.ubuntu.com-20071211175118-s94sizduj201hrs5 - date: 2007-12-11 17:51:18 +0000 - build-date: 2007-12-13 13:14:51 +1000 - revno: 3104 - branch-nick: bzr.dev - """) - expects = [ - Expect([ 'clobber', 'workdir' ], - self.basedir) - + 0, - Expect([ 'clobber', 'source' ], - self.basedir) - + 0, - Expect([ 'path/to/bzr', 'checkout', '--revision', '12', - 'http://bazaar.launchpad.net/~bzr/bzr-gtk/trunk', 'source' ], - self.basedir, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect(['path/to/bzr', 'version-info'], - self.basedir_source, - sendRC=False, usePTY=False, keepStdout=True, - environ=exp_environ, sendStderr=False, sendStdout=False) - + { 'stdout' : verinfo } - + 0, - Expect([ 'copy', 'source', 'workdir'], - self.basedir) - + 0, - ] - self.patch_runprocess(*expects) - - d = self.run_command() - d.addCallback(self.check_sourcedata, "http://bazaar.launchpad.net/~bzr/bzr-gtk/trunk\n") - return d - diff --git a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_cvs.py b/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_cvs.py deleted file mode 100644 index c7d040c9..00000000 --- a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_cvs.py +++ /dev/null @@ -1,63 +0,0 @@ -# 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 twisted.trial import unittest - -from buildslave.test.fake.runprocess import Expect -from buildslave.test.util.sourcecommand import SourceCommandTestMixin -from buildslave.commands import cvs - -class TestCVS(SourceCommandTestMixin, unittest.TestCase): - - def setUp(self): - self.setUpCommand() - - def tearDown(self): - self.tearDownCommand() - - def test_simple(self): - self.patch_getCommand('cvs', 'path/to/cvs') - self.clean_environ() - self.make_command(cvs.CVS, dict( - workdir='workdir', - mode='copy', - revision=None, - cvsroot=':pserver:anoncvs@anoncvs.NetBSD.org:/cvsroot', - cvsmodule='htdocs', - )) - - expects = [ - Expect([ 'clobber', 'workdir' ], - self.basedir) - + 0, - Expect([ 'clobber', 'source' ], - self.basedir) - + 0, - Expect([ 'path/to/cvs', '-d', ':pserver:anoncvs@anoncvs.NetBSD.org:/cvsroot', - '-z3', 'checkout', '-d', 'source', 'htdocs' ], - self.basedir, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect([ 'copy', 'source', 'workdir'], - self.basedir) - + 0, - ] - self.patch_runprocess(*expects) - - d = self.run_command() - d.addCallback(self.check_sourcedata, - ":pserver:anoncvs@anoncvs.NetBSD.org:/cvsroot\nhtdocs\nNone\n") - return d - diff --git a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_darcs.py b/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_darcs.py deleted file mode 100644 index e6953e31..00000000 --- a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_darcs.py +++ /dev/null @@ -1,137 +0,0 @@ -# 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 twisted.trial import unittest - -from buildslave.test.fake.runprocess import Expect -from buildslave.test.util.sourcecommand import SourceCommandTestMixin -from buildslave.commands import darcs - -class TestDarcs(SourceCommandTestMixin, unittest.TestCase): - - def setUp(self): - self.setUpCommand() - - def tearDown(self): - self.tearDownCommand() - - def test_simple(self): - self.patch_getCommand('darcs', 'path/to/darcs') - self.clean_environ() - self.make_command(darcs.Darcs, dict( - workdir='workdir', - mode='copy', - revision=None, - repourl='http://darcs.net', - )) - - exp_environ = dict(PWD='.', LC_MESSAGES='C') - expects = [ - Expect([ 'clobber', 'workdir' ], - self.basedir) - + 0, - Expect([ 'clobber', 'source' ], - self.basedir) - + 0, - Expect([ 'path/to/darcs', 'get', '--verbose', '--lazy', - '--repo-name', 'source', 'http://darcs.net'], - self.basedir, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect([ 'path/to/darcs', 'changes', '--context' ], - self.basedir_source, - sendRC=False, timeout=120, usePTY=False, keepStdout=True, - environ=exp_environ, sendStderr=False, sendStdout=False) - + { 'stdout' : example_changes } - + 0, - Expect([ 'copy', 'source', 'workdir'], - self.basedir) - + 0, - ] - self.patch_runprocess(*expects) - - d = self.run_command() - d.addCallback(self.check_sourcedata, "http://darcs.net\n") - return d - -example_changes = """\ - -Context: - -[Resolve issue1874: recognise network tests on cabal test command line. -Eric Kow <kowey@darcs.net>**20100611102251 - Ignore-this: 59a455ef26b5df9a3bdd356e1e37854e -] - -[haddocks for SelectChanges -Florent Becker <florent.becker@ens-lyon.org>**20100610140023 - Ignore-this: c4203f746fc6278dc5290332e3625283 -] - -[better message when skipping already decided patches -Florent Becker <florent.becker@ens-lyon.org>**20100531065630 - Ignore-this: 426675973555e75086781f0c54fbf925 -] - -[Accept issue1871: darcs record . failure for changes in subdir. -Eric Kow <kowey@darcs.net>**20100609145047 - Ignore-this: dd942b980dd3006bfa5d176ec5cfdf99 -] - -[Extend the issue1014 test to check that named patches are not duplicated. -Petr Rockai <me@mornfall.net>**20100607185041 - Ignore-this: 383ff17461076a798193b6c0c2427bba -] - -[Haddock merge2FL and fastRemoveFL in Patch.Depends. -Petr Rockai <me@mornfall.net>**20100607184849 - Ignore-this: cd6e79c4e404820d4f0ae94a53aed8c1 -] - -[Limit index updates to relevant subtree in a few cases. -Petr Rockai <me@mornfall.net>**20100509102248 - Ignore-this: fea041133d039cecead73935f0cd6762 -] - -[Fix a bunch of "unused" warnings. -Petr Rockai <me@mornfall.net>**20100607194111 - Ignore-this: 1fec82080eca9c3f10b690ee0ef81e34 -] - -[Shorten issue1210 test name. -Eric Kow <kowey@darcs.net>**20100608090708 - Ignore-this: 57ff2a1cbb9795f80ae3d81e19717a9e -] - -[Add test for issue1210: global cache gets recorded in _darcs/prefs/sources -builes.adolfo@googlemail.com**20100608010902 - Ignore-this: bc02ada910927be93dd4a5cc9826d20d -] - -[Fix typo in the BSD version of date arithmetic (testsuite). -Petr Rockai <me@mornfall.net>**20100608062802 - Ignore-this: fdfb7aef46966a18edc2f7e93c0118f0 -] - -[Let's try to work with BSD date as well. -Petr Rockai <me@mornfall.net>**20100608061631 - Ignore-this: 628e6f15e8f8d6801a3f1dd6c8605e17 -] - -[Fix a race condition in the match-date test. -Petr Rockai <me@mornfall.net>**20100607223257 - Ignore-this: 4c6452bfdee6c03eb95abcd646add90f -] -""" diff --git a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_fs.py b/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_fs.py deleted file mode 100644 index 393d0029..00000000 --- a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_fs.py +++ /dev/null @@ -1,219 +0,0 @@ -# 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 - -import os -import shutil -from twisted.trial import unittest - -from buildslave.test.util.command import CommandTestMixin -from buildslave.commands import fs -from twisted.python import runtime -from buildslave.commands import utils - -class TestRemoveDirectory(CommandTestMixin, unittest.TestCase): - - def setUp(self): - self.setUpCommand() - - def tearDown(self): - self.tearDownCommand() - - def test_simple(self): - self.make_command(fs.RemoveDirectory, dict( - dir='workdir', - ), True) - d = self.run_command() - - def check(_): - self.assertFalse(os.path.exists(os.path.abspath(os.path.join(self.basedir,'workdir')))) - self.assertIn({'rc': 0}, - self.get_updates(), - self.builder.show()) - d.addCallback(check) - return d - - def test_simple_exception(self): - if runtime.platformType == "posix": - return # we only use rmdirRecursive on windows - def fail(dir): - raise RuntimeError("oh noes") - self.patch(utils, 'rmdirRecursive', fail) - self.make_command(fs.RemoveDirectory, dict( - dir='workdir', - ), True) - d = self.run_command() - - def check(_): - self.assertIn({'rc': -1}, self.get_updates(), - self.builder.show()) - d.addCallback(check) - return d - - def test_multiple_dirs(self): - self.make_command(fs.RemoveDirectory, dict( - dir=['workdir', 'sourcedir'], - ), True) - d = self.run_command() - - def check(_): - for dirname in ['workdir', 'sourcedir']: - self.assertFalse(os.path.exists(os.path.abspath(os.path.join(self.basedir, dirname)))) - self.assertIn({'rc': 0}, - self.get_updates(), - self.builder.show()) - d.addCallback(check) - return d - -class TestCopyDirectory(CommandTestMixin, unittest.TestCase): - - def setUp(self): - self.setUpCommand() - - def tearDown(self): - self.tearDownCommand() - - def test_simple(self): - self.make_command(fs.CopyDirectory, dict( - fromdir='workdir', - todir='copy', - ), True) - d = self.run_command() - - def check(_): - self.assertTrue(os.path.exists(os.path.abspath(os.path.join(self.basedir,'copy')))) - self.assertIn({'rc': 0}, # this may ignore a 'header' : '..', which is OK - self.get_updates(), - self.builder.show()) - d.addCallback(check) - return d - - def test_simple_exception(self): - if runtime.platformType == "posix": - return # we only use rmdirRecursive on windows - def fail(src, dest): - raise RuntimeError("oh noes") - self.patch(shutil, 'copytree', fail) - self.make_command(fs.CopyDirectory, dict( - fromdir='workdir', - todir='copy', - ), True) - d = self.run_command() - - def check(_): - self.assertIn({'rc': -1}, - self.get_updates(), - self.builder.show()) - d.addCallback(check) - return d - -class TestMakeDirectory(CommandTestMixin, unittest.TestCase): - - def setUp(self): - self.setUpCommand() - - def tearDown(self): - self.tearDownCommand() - - def test_simple(self): - self.make_command(fs.MakeDirectory, dict( - dir='test-dir', - ), True) - d = self.run_command() - - def check(_): - self.assertTrue(os.path.exists(os.path.abspath(os.path.join(self.basedir,'test-dir')))) - self.assertUpdates( - [{'rc': 0}], - self.builder.show()) - d.addCallback(check) - return d - - def test_already_exists(self): - self.make_command(fs.MakeDirectory, dict( - dir='workdir', - ), True) - d = self.run_command() - - def check(_): - self.assertUpdates( - [{'rc': 0}], - self.builder.show()) - d.addCallback(check) - return d - - def test_existing_file(self): - self.make_command(fs.MakeDirectory, dict( - dir='test-file', - ), True) - open(os.path.join(self.basedir, 'test-file'), "w") - d = self.run_command() - - def check(_): - self.assertUpdates([{'rc': 1}], self.builder.show()) - d.addErrback(check) - return d - -class TestStatFile(CommandTestMixin, unittest.TestCase): - - def setUp(self): - self.setUpCommand() - - def tearDown(self): - self.tearDownCommand() - - def test_non_existant(self): - self.make_command(fs.StatFile, dict( - file='no-such-file', - ), True) - d = self.run_command() - - def check(_): - self.assertUpdates( - [{'rc': 1}], - self.builder.show()) - d.addCallback(check) - return d - - def test_directory(self): - self.make_command(fs.StatFile, dict( - file='workdir', - ), True) - d = self.run_command() - - def check(_): - import stat - self.assertTrue(stat.S_ISDIR(self.get_updates()[0]['stat'][stat.ST_MODE])) - self.assertIn({'rc': 0}, - self.get_updates(), - self.builder.show()) - d.addCallback(check) - return d - - def test_file(self): - self.make_command(fs.StatFile, dict( - file='test-file', - ), True) - open(os.path.join(self.basedir, 'test-file'), "w") - - d = self.run_command() - - def check(_): - import stat - self.assertTrue(stat.S_ISREG(self.get_updates()[0]['stat'][stat.ST_MODE])) - self.assertIn({'rc': 0}, - self.get_updates(), - self.builder.show()) - d.addCallback(check) - return d diff --git a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_git.py b/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_git.py deleted file mode 100644 index e22c733c..00000000 --- a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_git.py +++ /dev/null @@ -1,701 +0,0 @@ -# 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 - -import os -import mock - -from twisted.trial import unittest -from twisted.internet import defer - -from buildslave.test.fake.runprocess import Expect -from buildslave.test.util.sourcecommand import SourceCommandTestMixin -from buildslave.commands import git - -class TestGit(SourceCommandTestMixin, unittest.TestCase): - - def setUp(self): - self.setUpCommand() - - def tearDown(self): - self.tearDownCommand() - - def patch_sourcedirIsUpdateable(self, result): - self.cmd.sourcedirIsUpdateable = lambda : result - - # tests - - def test_run_mode_copy_fresh_sourcedir(self): - "Test a basic invocation with mode=copy and no existing sourcedir" - self.patch_getCommand('git', 'path/to/git') - self.clean_environ() - self.make_command(git.Git, dict( - workdir='workdir', - mode='copy', - revision=None, - repourl='git://github.com/djmitche/buildbot.git', - ), - # no sourcedata -> will do fresh checkout - initial_sourcedata = None, - ) - - expects = [ - Expect([ 'clobber', 'workdir' ], - self.basedir) - + 0, - Expect([ 'clobber', 'source' ], - self.basedir) - + 0, - # TODO: capture makedirs invocation here - Expect([ 'path/to/git', 'init'], - self.basedir_source, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect([ 'path/to/git', 'fetch', '-t', - 'git://github.com/djmitche/buildbot.git', '+master' ], - self.basedir_source, - sendRC=False, timeout=120, usePTY=False, keepStderr=True) - + { 'stderr' : '' } - + 0, - Expect(['path/to/git', 'reset', '--hard', 'FETCH_HEAD'], - self.basedir_source, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect(['path/to/git', 'branch', '-M', 'master'], - self.basedir_source, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect([ 'path/to/git', 'rev-parse', 'HEAD' ], - self.basedir_source, - sendRC=False, timeout=120, usePTY=False, keepStdout=True) - + { 'stdout' : '4026d33b0532b11f36b0875f63699adfa8ee8662\n' } - + 0, - Expect([ 'copy', 'source', 'workdir'], - self.basedir) - + 0, - ] - self.patch_runprocess(*expects) - - d = self.run_command() - d.addCallback(self.check_sourcedata, "git://github.com/djmitche/buildbot.git master\n") - return d - - - def test_run_mode_copy_update_sourcedir(self): - """test a copy where the sourcedata indicates that the source directory - can be updated""" - self.patch_getCommand('git', 'path/to/git') - self.clean_environ() - self.make_command(git.Git, dict( - workdir='workdir', - mode='copy', - revision=None, - repourl='git://github.com/djmitche/buildbot.git', - progress=True, # added here for better coverage - ), - initial_sourcedata = "git://github.com/djmitche/buildbot.git master\n", - ) - self.patch_sourcedirIsUpdateable(True) - - expects = [ - Expect([ 'clobber', 'workdir' ], - self.basedir) - + 0, - Expect([ 'path/to/git', 'fetch', '-t', - 'git://github.com/djmitche/buildbot.git', '+master', - '--progress' ], - self.basedir_source, - sendRC=False, timeout=120, usePTY=False, keepStderr=True) - + { 'stderr' : '' } - + 0, - Expect(['path/to/git', 'reset', '--hard', 'FETCH_HEAD'], - self.basedir_source, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect(['path/to/git', 'branch', '-M', 'master'], - self.basedir_source, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect([ 'path/to/git', 'rev-parse', 'HEAD' ], - self.basedir_source, - sendRC=False, timeout=120, usePTY=False, keepStdout=True) - + { 'stdout' : '4026d33b0532b11f36b0875f63699adfa8ee8662\n' } - + 0, - Expect([ 'copy', 'source', 'workdir'], - self.basedir) - + 0, - ] - self.patch_runprocess(*expects) - - d = self.run_command() - d.addCallback(self.check_sourcedata, "git://github.com/djmitche/buildbot.git master\n") - return d - - def test_run_mode_copy_nonexistant_ref(self): - self.patch_getCommand('git', 'path/to/git') - self.clean_environ() - self.make_command(git.Git, dict( - workdir='workdir', - mode='copy', - revision=None, - branch='bogusref', - repourl='git://github.com/djmitche/buildbot.git', - )) - self.patch_sourcedirIsUpdateable(True) - - expects = [ - Expect([ 'clobber', 'workdir' ], - self.basedir) - + 0, - Expect([ 'path/to/git', 'clean', '-f', '-d', '-x'], - self.basedir_source, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect([ 'path/to/git', 'fetch', '-t', - 'git://github.com/djmitche/buildbot.git', '+bogusref' ], - self.basedir_source, - sendRC=False, timeout=120, usePTY=False, keepStderr=True) - + { 'stderr' : "fatal: Couldn't find remote ref bogusref\n" } - + { 'rc': 128 } - + 128, - ] - self.patch_runprocess(*expects) - - d = self.run_command() - return d - - def test_run_mode_copy_gerrit_branch(self): - self.patch_getCommand('git', 'path/to/git') - self.clean_environ() - self.make_command(git.Git, dict( - workdir='workdir', - mode='copy', - revision=None, - branch='local-branch', - gerrit_branch='real-branch', - repourl='git://github.com/djmitche/buildbot.git', - )) - self.patch_sourcedirIsUpdateable(True) - - expects = [ - Expect([ 'clobber', 'workdir' ], - self.basedir) - + 0, - Expect([ 'path/to/git', 'clean', '-f', '-d', '-x'], - self.basedir_source, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect([ 'path/to/git', 'fetch', '-t', - 'git://github.com/djmitche/buildbot.git', '+real-branch' ], - self.basedir_source, - sendRC=False, timeout=120, usePTY=False, keepStderr=True) - + { 'stderr' : '' } - + 0, - Expect(['path/to/git', 'reset', '--hard', 'FETCH_HEAD'], - self.basedir_source, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect(['path/to/git', 'branch', '-M', 'local-branch'], # note, not the same branch - self.basedir_source, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect([ 'path/to/git', 'rev-parse', 'HEAD' ], - self.basedir_source, - sendRC=False, timeout=120, usePTY=False, keepStdout=True) - + { 'stdout' : '4026d33b0532b11f36b0875f63699adfa8ee8662\n' } - + 0, - Expect([ 'copy', 'source', 'workdir'], - self.basedir) - + 0, - ] - self.patch_runprocess(*expects) - - d = self.run_command() - return d - - def test_run_mode_update_fresh(self): - self.patch_getCommand('git', 'path/to/git') - self.clean_environ() - self.make_command(git.Git, dict( - workdir='workdir', - mode='update', - revision=None, - repourl='git://github.com/djmitche/buildbot.git', - ), - initial_sourcedata = "git://github.com/djmitche/buildbot.git master\n", - ) - self.patch_sourcedirIsUpdateable(False) - - expects = [ - Expect([ 'clobber', 'workdir' ], - self.basedir) - + 0, - Expect([ 'path/to/git', 'init'], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect([ 'path/to/git', 'fetch', '-t', - 'git://github.com/djmitche/buildbot.git', '+master' ], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False, keepStderr=True) - + { 'stderr' : '' } - + 0, - Expect(['path/to/git', 'reset', '--hard', 'FETCH_HEAD'], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect(['path/to/git', 'branch', '-M', 'master'], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect([ 'path/to/git', 'rev-parse', 'HEAD' ], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False, keepStdout=True) - + { 'stdout' : '4026d33b0532b11f36b0875f63699adfa8ee8662\n' } - + 0, - ] - self.patch_runprocess(*expects) - - d = self.run_command() - d.addCallback(self.check_sourcedata, "git://github.com/djmitche/buildbot.git master\n") - return d - - def test_run_mode_update_existing(self): - self.patch_getCommand('git', 'path/to/git') - self.clean_environ() - self.make_command(git.Git, dict( - workdir='workdir', - mode='update', - revision=None, - repourl='git://github.com/djmitche/buildbot.git', - ), - initial_sourcedata = "git://github.com/djmitche/buildbot.git master\n", - ) - self.patch_sourcedirIsUpdateable(True) - - expects = [ - Expect([ 'path/to/git', 'fetch', '-t', - 'git://github.com/djmitche/buildbot.git', '+master' ], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False, keepStderr=True) - + { 'stderr' : '' } - + 0, - Expect(['path/to/git', 'reset', '--hard', 'FETCH_HEAD'], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect(['path/to/git', 'branch', '-M', 'master'], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect([ 'path/to/git', 'rev-parse', 'HEAD' ], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False, keepStdout=True) - + { 'stdout' : '4026d33b0532b11f36b0875f63699adfa8ee8662\n' } - + 0, - ] - self.patch_runprocess(*expects) - - d = self.run_command() - d.addCallback(self.check_sourcedata, "git://github.com/djmitche/buildbot.git master\n") - return d - - def test_run_mode_update_existing_known_rev(self): - self.patch_getCommand('git', 'path/to/git') - self.clean_environ() - self.make_command(git.Git, dict( - workdir='workdir', - mode='update', - revision='abcdef01', - repourl='git://github.com/djmitche/buildbot.git', - ), - initial_sourcedata = "git://github.com/djmitche/buildbot.git master\n", - ) - self.patch_sourcedirIsUpdateable(True) - - expects = [ - Expect(['path/to/git', 'reset', '--hard', 'abcdef01'], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect([ 'path/to/git', 'rev-parse', 'HEAD' ], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False, keepStdout=True) - + { 'stdout' : '4026d33b0532b11f36b0875f63699adfa8ee8662\n' } - + 0, - ] - self.patch_runprocess(*expects) - - d = self.run_command() - d.addCallback(self.check_sourcedata, "git://github.com/djmitche/buildbot.git master\n") - return d - - def test_run_mode_update_existing_unknown_rev(self): - self.patch_getCommand('git', 'path/to/git') - self.clean_environ() - self.make_command(git.Git, dict( - workdir='workdir', - mode='update', - revision='abcdef01', - repourl='git://github.com/djmitche/buildbot.git', - ), - initial_sourcedata = "git://github.com/djmitche/buildbot.git master\n", - ) - self.patch_sourcedirIsUpdateable(True) - - expects = [ - Expect(['path/to/git', 'reset', '--hard', 'abcdef01'], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False) - + 1, - Expect([ 'path/to/git', 'fetch', '-t', - 'git://github.com/djmitche/buildbot.git', '+master' ], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False, keepStderr=True) - + { 'stderr' : '' } - + 0, - Expect(['path/to/git', 'reset', '--hard', 'abcdef01'], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect(['path/to/git', 'branch', '-M', 'master'], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect([ 'path/to/git', 'rev-parse', 'HEAD' ], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False, keepStdout=True) - + { 'stdout' : '4026d33b0532b11f36b0875f63699adfa8ee8662\n' } - + 0, - ] - self.patch_runprocess(*expects) - - d = self.run_command() - d.addCallback(self.check_sourcedata, "git://github.com/djmitche/buildbot.git master\n") - return d - - def test_run_with_reference(self): - self.patch_getCommand('git', 'path/to/git') - self.clean_environ() - self.make_command(git.Git, dict( - workdir='workdir', - mode='update', - revision=None, - reference='/other/repo', - repourl='git://github.com/djmitche/buildbot.git', - ), - initial_sourcedata = "git://github.com/djmitche/buildbot.git master\n", - ) - self.patch_sourcedirIsUpdateable(False) - - expects = [ - Expect([ 'clobber', 'workdir' ], - self.basedir) - + 0, - Expect([ 'path/to/git', 'init'], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect([ 'setFileContents', - os.path.join(self.basedir_workdir, - *'.git/objects/info/alternates'.split('/')), - os.path.join('/other/repo', 'objects'), ], - self.basedir) - + 0, - Expect([ 'path/to/git', 'fetch', '-t', - 'git://github.com/djmitche/buildbot.git', '+master' ], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False, keepStderr=True) - + { 'stderr' : '' } - + 0, - Expect(['path/to/git', 'reset', '--hard', 'FETCH_HEAD'], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect(['path/to/git', 'branch', '-M', 'master'], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect([ 'path/to/git', 'rev-parse', 'HEAD' ], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False, keepStdout=True) - + { 'stdout' : '4026d33b0532b11f36b0875f63699adfa8ee8662\n' } - + 0, - ] - self.patch_runprocess(*expects) - - d = self.run_command() - d.addCallback(self.check_sourcedata, "git://github.com/djmitche/buildbot.git master\n") - return d - - def test_run_with_shallow_and_rev(self): - self.patch_getCommand('git', 'path/to/git') - self.clean_environ() - self.make_command(git.Git, dict( - workdir='workdir', - mode='update', - revision='deadbeef', - shallow=True, - repourl='git://github.com/djmitche/buildbot.git', - ), - initial_sourcedata = "git://github.com/djmitche/buildbot.git master\n", - ) - self.patch_sourcedirIsUpdateable(False) - - expects = [ - Expect([ 'clobber', 'workdir' ], - self.basedir) - + 0, - Expect([ 'path/to/git', 'init'], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect(['path/to/git', 'reset', '--hard', 'deadbeef'], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect([ 'path/to/git', 'rev-parse', 'HEAD' ], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False, keepStdout=True) - + { 'stdout' : '4026d33b0532b11f36b0875f63699adfa8ee8662\n' } - + 0, - ] - self.patch_runprocess(*expects) - - d = self.run_command() - d.addCallback(self.check_sourcedata, "git://github.com/djmitche/buildbot.git master\n") - return d - - def test_run_with_shallow(self): - self.patch_getCommand('git', 'path/to/git') - self.clean_environ() - self.make_command(git.Git, dict( - workdir='workdir', - mode='update', - revision=None, - shallow=True, - repourl='git://github.com/djmitche/buildbot.git', - ), - initial_sourcedata = "git://github.com/djmitche/buildbot.git master\n", - ) - self.patch_sourcedirIsUpdateable(False) - - expects = [ - Expect([ 'clobber', 'workdir' ], - self.basedir) - + 0, - Expect(['path/to/git', 'clone', '--depth', '1', - 'git://github.com/djmitche/buildbot.git', - self.basedir_workdir], - self.basedir, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect([ 'path/to/git', 'fetch', '-t', - 'git://github.com/djmitche/buildbot.git', '+master' ], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False, keepStderr=True) - + { 'stderr' : '' } - + 0, - Expect(['path/to/git', 'reset', '--hard', 'FETCH_HEAD'], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect(['path/to/git', 'branch', '-M', 'master'], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect([ 'path/to/git', 'rev-parse', 'HEAD' ], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False, keepStdout=True) - + { 'stdout' : '4026d33b0532b11f36b0875f63699adfa8ee8662\n' } - + 0, - ] - self.patch_runprocess(*expects) - - d = self.run_command() - d.addCallback(self.check_sourcedata, "git://github.com/djmitche/buildbot.git master\n") - return d - - def test_run_with_shallow_and_reference(self): - self.patch_getCommand('git', 'path/to/git') - self.clean_environ() - self.make_command(git.Git, dict( - workdir='workdir', - mode='update', - revision=None, - shallow=True, - reference="/some/repo", - repourl='git://github.com/djmitche/buildbot.git', - ), - initial_sourcedata = "git://github.com/djmitche/buildbot.git master\n", - ) - self.patch_sourcedirIsUpdateable(False) - - expects = [ - Expect([ 'clobber', 'workdir' ], - self.basedir) - + 0, - Expect(['path/to/git', 'clone', '--depth', '1', - '--reference', '/some/repo', # note: no ../objects - 'git://github.com/djmitche/buildbot.git', - self.basedir_workdir], - self.basedir, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect([ 'setFileContents', - os.path.join(self.basedir_workdir, - *'.git/objects/info/alternates'.split('/')), - os.path.join('/some/repo', 'objects'), ], - self.basedir) - + 0, - Expect([ 'path/to/git', 'fetch', '-t', - 'git://github.com/djmitche/buildbot.git', '+master' ], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False, keepStderr=True) - + { 'stderr' : '' } - + 0, - Expect(['path/to/git', 'reset', '--hard', 'FETCH_HEAD'], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect(['path/to/git', 'branch', '-M', 'master'], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect([ 'path/to/git', 'rev-parse', 'HEAD' ], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False, keepStdout=True) - + { 'stdout' : '4026d33b0532b11f36b0875f63699adfa8ee8662\n' } - + 0, - ] - self.patch_runprocess(*expects) - - d = self.run_command() - d.addCallback(self.check_sourcedata, "git://github.com/djmitche/buildbot.git master\n") - return d - - def test_run_with_submodules(self): - self.patch_getCommand('git', 'path/to/git') - self.clean_environ() - self.make_command(git.Git, dict( - workdir='workdir', - mode='update', - revision=None, - submodules=True, - repourl='git://github.com/djmitche/buildbot.git', - ), - initial_sourcedata = "git://github.com/djmitche/buildbot.git master\n", - ) - self.patch_sourcedirIsUpdateable(False) - - expects = [ - Expect([ 'clobber', 'workdir' ], - self.basedir) - + 0, - Expect([ 'path/to/git', 'init'], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect([ 'path/to/git', 'fetch', '-t', - 'git://github.com/djmitche/buildbot.git', '+master' ], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False, keepStderr=True) - + { 'stderr' : '' } - + 0, - Expect(['path/to/git', 'reset', '--hard', 'FETCH_HEAD'], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect(['path/to/git', 'branch', '-M', 'master'], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect([ 'path/to/git', 'submodule', 'init' ], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect([ 'path/to/git', 'submodule', 'update' ], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect([ 'path/to/git', 'submodule', 'foreach', - 'git', 'clean', '-f', '-d', '-x'], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect([ 'path/to/git', 'rev-parse', 'HEAD' ], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False, keepStdout=True) - + { 'stdout' : '4026d33b0532b11f36b0875f63699adfa8ee8662\n' } - + 0, - ] - self.patch_runprocess(*expects) - - d = self.run_command() - d.addCallback(self.check_sourcedata, "git://github.com/djmitche/buildbot.git master\n") - return d - - def test_sourcedataMatches_no_file(self): - self.make_command(git.Git, dict( - workdir='workdir', - mode='copy', - revision=None, - repourl='git://github.com/djmitche/buildbot.git', - ), initial_sourcedata=None) - self.assertFalse(self.cmd.sourcedataMatches()) - - def test_sourcedataMatches_ok(self): - self.make_command(git.Git, dict( - workdir='workdir', - mode='copy', - revision=None, - repourl='git://github.com/djmitche/buildbot.git', - # git command doesn't care what the contents of the sourcedata file is - ), initial_sourcedata='xyz') - self.assertTrue(self.cmd.sourcedataMatches()) - - def do_test_parseGotRevision(self, stdout, exp): - self.make_command(git.Git, dict( - workdir='workdir', - repourl='git://github.com/djmitche/buildbot.git', - )) - def _dovccmd(cmd, callback, keepStdout=False): - self.assertTrue(keepStdout) - self.cmd.command = mock.Mock() - self.cmd.command.stdout = stdout - d = defer.succeed(None) - d.addCallback(callback) - return d - self.cmd._dovccmd = _dovccmd - - d = self.cmd.parseGotRevision() - def check(res): - self.assertEqual(res, exp) - d.addCallback(check) - return d - - def test_parseGotRevision_bogus(self): - return self.do_test_parseGotRevision("fatal: Couldn't find revision 1234\n", None) - - def test_parseGotRevision_wrong_length(self): - return self.do_test_parseGotRevision("\n1234abcd\n", None) - - def test_parseGotRevision_ok(self): - return self.do_test_parseGotRevision( - "\n4026d33b0532b11f36b0875f63699adfa8ee8662\n", - "4026d33b0532b11f36b0875f63699adfa8ee8662") - - # TODO: gerrit_branch - # TODO: consolidate Expect objects - # TODO: ignore_ignores (w/ submodules) diff --git a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_hg.py b/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_hg.py deleted file mode 100644 index ed90cf42..00000000 --- a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_hg.py +++ /dev/null @@ -1,327 +0,0 @@ -# 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 twisted.trial import unittest - -from buildslave.test.fake.runprocess import Expect -from buildslave.test.util.sourcecommand import SourceCommandTestMixin -from buildslave.commands import hg - -class TestMercurial(SourceCommandTestMixin, unittest.TestCase): - - def setUp(self): - self.setUpCommand() - - def tearDown(self): - self.tearDownCommand() - - def patch_sourcedirIsUpdateable(self, result): - self.cmd.sourcedirIsUpdateable = lambda : result - - def test_simple(self): - self.patch_getCommand('hg', 'path/to/hg') - self.clean_environ() - self.make_command(hg.Mercurial, dict( - workdir='workdir', - mode='copy', - revision=None, - repourl='http://bitbucket.org/nicolas17/pyboinc', - )) - - exp_environ = dict(PWD='.', LC_MESSAGES='C') - expects = [ - Expect([ 'clobber', 'workdir' ], - self.basedir) - + 0, - Expect([ 'clobber', 'source' ], - self.basedir) - + 0, - Expect(['path/to/hg', 'clone', '--verbose', '--noupdate', - 'http://bitbucket.org/nicolas17/pyboinc', 'source'], - self.basedir, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect(['path/to/hg', 'identify', '--num', '--branch'], - self.basedir_source, - sendRC=False, timeout=120, usePTY=False, keepStdout=True, - keepStderr=True) - + { 'stdout' : '-1 default\n' } - + 0, - Expect(['path/to/hg', 'paths', 'default'], - self.basedir_source, - sendRC=False, timeout=120, usePTY=False, keepStdout=True, - keepStderr=True) - + { 'stdout' : 'http://bitbucket.org/nicolas17/pyboinc\n' } - + 0, - Expect(['path/to/hg', 'update', '--clean', '--repository', - 'source', '--rev', 'default'], - self.basedir, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect(['path/to/hg', 'parents', '--template', '{node}\\n'], - self.basedir_source, - sendRC=False, timeout=120, usePTY=False, environ=exp_environ, - keepStdout=True) - + { 'stdout' : 'b7ddc0b638fa11cdac7c0345c40c6f76d8a7166d' } - + 0, - Expect([ 'copy', 'source', 'workdir'], - self.basedir) - + 0, - ] - self.patch_runprocess(*expects) - - d = self.run_command() - d.addCallback(self.check_sourcedata, "http://bitbucket.org/nicolas17/pyboinc\n") - return d - - def test_update_existing(self): - self.patch_getCommand('hg', 'path/to/hg') - self.clean_environ() - self.make_command(hg.Mercurial, dict( - workdir='workdir', - mode='update', - revision=None, - repourl='http://bitbucket.org/nicolas17/pyboinc', - ), - initial_sourcedata = "http://bitbucket.org/nicolas17/pyboinc\n", - ) - self.patch_sourcedirIsUpdateable(True) - - exp_environ = dict(PWD='.', LC_MESSAGES='C') - expects = [ - Expect(['path/to/hg', 'pull', '--verbose', 'http://bitbucket.org/nicolas17/pyboinc'], - self.basedir_workdir, - sendRC=False, timeout=120, keepStdout=True, usePTY=False) - + 0, - Expect(['path/to/hg', 'identify', '--num', '--branch'], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False, keepStdout=True, - keepStderr=True) - + { 'stdout' : '-1 default\n' } - + 0, - Expect(['path/to/hg', 'paths', 'default'], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False, keepStdout=True, - keepStderr=True) - + { 'stdout' : 'http://bitbucket.org/nicolas17/pyboinc\n' } - + 0, - Expect(['path/to/hg', 'update', '--clean', '--repository', - 'workdir', '--rev', 'default'], - self.basedir, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect(['path/to/hg', 'parents', '--template', '{node}\\n'], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False, environ=exp_environ, - keepStdout=True) - + { 'stdout' : 'b7ddc0b638fa11cdac7c0345c40c6f76d8a7166d' } - + 0, - ] - self.patch_runprocess(*expects) - d = self.run_command() - d.addCallback(self.check_sourcedata, "http://bitbucket.org/nicolas17/pyboinc\n") - return d - - - def test_update_existing_change_branch(self): - self.patch_getCommand('hg', 'path/to/hg') - self.clean_environ() - self.make_command(hg.Mercurial, dict( - workdir='workdir', - mode='update', - revision=None, - branch='stable', - repourl='http://bitbucket.org/nicolas17/pyboinc', - clobberOnBranchChange=True, - ), - initial_sourcedata = "http://bitbucket.org/nicolas17/pyboinc\n", - ) - self.patch_sourcedirIsUpdateable(True) - - exp_environ = dict(PWD='.', LC_MESSAGES='C') - expects = [ - Expect(['path/to/hg', 'pull', '--verbose', 'http://bitbucket.org/nicolas17/pyboinc'], - self.basedir_workdir, - sendRC=False, timeout=120, keepStdout=True, usePTY=False) - + 0, - Expect(['path/to/hg', 'identify', '--num', '--branch'], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False, keepStdout=True, - keepStderr=True) - + { 'stdout' : '1 default\n' } - + 0, - Expect(['path/to/hg', 'paths', 'default'], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False, keepStdout=True, - keepStderr=True) - + { 'stdout' : 'http://bitbucket.org/nicolas17/pyboinc\n' } - + 0, - Expect(['path/to/hg', 'purge', '--all'], - self.basedir_workdir, - keepStdout=True, keepStderr=True, usePTY=False) - + 0, - Expect(['path/to/hg', 'update', '--clean', '--repository', - 'workdir', '--rev', 'stable'], - self.basedir, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect(['path/to/hg', 'parents', '--template', '{node}\\n'], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False, environ=exp_environ, - keepStdout=True) - + { 'stdout' : 'b7ddc0b638fa11cdac7c0345c40c6f76d8a7166d' } - + 0, - - ] - self.patch_runprocess(*expects) - d = self.run_command() - d.addCallback(self.check_sourcedata, "http://bitbucket.org/nicolas17/pyboinc\n") - return d - - def test_update_handle_emptyupdate(self): - self.patch_getCommand('hg', 'path/to/hg') - self.clean_environ() - self.make_command(hg.Mercurial, dict( - workdir='workdir', - mode='update', - revision=None, - repourl='http://bitbucket.org/nicolas17/pyboinc', - ), - initial_sourcedata = "http://bitbucket.org/nicolas17/pyboinc\n", - ) - self.patch_sourcedirIsUpdateable(True) - - exp_environ = dict(PWD='.', LC_MESSAGES='C') - expects = [ - Expect(['path/to/hg', 'pull', '--verbose', 'http://bitbucket.org/nicolas17/pyboinc'], - self.basedir_workdir, - sendRC=False, timeout=120, keepStdout=True, usePTY=False) - + 1, - Expect([ 'clobber', 'workdir' ], - self.basedir) - + 0, - Expect(['path/to/hg', 'clone', '--verbose', '--noupdate', - 'http://bitbucket.org/nicolas17/pyboinc', 'workdir'], - self.basedir, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect(['path/to/hg', 'identify', '--num', '--branch'], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False, keepStdout=True, - keepStderr=True) - + { 'stdout' : '-1 default\n' } - + 0, - Expect(['path/to/hg', 'paths', 'default'], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False, keepStdout=True, - keepStderr=True) - + { 'stdout' : 'http://bitbucket.org/nicolas17/pyboinc\n' } - + 0, - Expect(['path/to/hg', 'update', '--clean', '--repository', - 'workdir', '--rev', 'default'], - self.basedir, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect(['path/to/hg', 'parents', '--template', '{node}\\n'], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False, environ=exp_environ, - keepStdout=True) - + { 'stdout' : 'b7ddc0b638fa11cdac7c0345c40c6f76d8a7166d' } - + 0, - ] - self.patch_runprocess(*expects) - d = self.run_command() - d.addCallback(self.check_sourcedata, "http://bitbucket.org/nicolas17/pyboinc\n") - return d - - def test_update_existing_change_branch_purge_fail(self): - self.patch_getCommand('hg', 'path/to/hg') - self.clean_environ() - self.make_command(hg.Mercurial, dict( - workdir='workdir', - mode='update', - revision="abcdef01", - branch='stable', - repourl='http://bitbucket.org/nicolas17/pyboinc', - clobberOnBranchChange=True, - ), - initial_sourcedata = "http://bitbucket.org/nicolas17/pyboinc\n", - ) - self.patch_sourcedirIsUpdateable(True) - - exp_environ = dict(PWD='.', LC_MESSAGES='C') - expects = [ - Expect(['path/to/hg', 'pull', '--verbose', 'http://bitbucket.org/nicolas17/pyboinc'], - self.basedir_workdir, - sendRC=False, timeout=120, keepStdout=True, usePTY=False) - + 0, - Expect(['path/to/hg', 'identify', '--num', '--branch'], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False, keepStdout=True, - keepStderr=True) - + { 'stdout' : '1 default\n' } - + 0, - Expect(['path/to/hg', 'paths', 'default'], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False, keepStdout=True, - keepStderr=True) - + { 'stdout' : 'http://bitbucket.org/nicolas17/pyboinc\n' } - + 0, - Expect(['path/to/hg', 'purge', '--all'], - self.basedir_workdir, - keepStdout=True, keepStderr=True, usePTY=False) - + 1, - Expect([ 'clobber', 'workdir' ], - self.basedir) - + 0, - Expect(['path/to/hg', 'clone', '--verbose', '--noupdate', - 'http://bitbucket.org/nicolas17/pyboinc', 'workdir'], - self.basedir, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect(['path/to/hg', 'identify', '--num', '--branch'], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False, keepStdout=True, - keepStderr=True) - + { 'stdout' : '-1 default\n' } - + 0, - Expect(['path/to/hg', 'paths', 'default'], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False, keepStdout=True, - keepStderr=True) - + { 'stdout' : 'http://bitbucket.org/nicolas17/pyboinc\n' } - + 0, - Expect(['path/to/hg', 'update', '--clean', '--repository', - 'workdir', '--rev', 'abcdef01'], - self.basedir, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect(['path/to/hg', 'update', '--clean', '--repository', - 'workdir', '--rev', 'abcdef01'], - self.basedir, - sendRC=False, timeout=120, usePTY=False) - + 0, - Expect(['path/to/hg', 'parents', '--template', '{node}\\n'], - self.basedir_workdir, - sendRC=False, timeout=120, usePTY=False, environ=exp_environ, - keepStdout=True) - + { 'stdout' : 'b7ddc0b638fa11cdac7c0345c40c6f76d8a7166d' } - + 0, - - ] - self.patch_runprocess(*expects) - d = self.run_command() - d.addCallback(self.check_sourcedata, "http://bitbucket.org/nicolas17/pyboinc\n") - return d diff --git a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_mtn.py b/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_mtn.py deleted file mode 100644 index 0987ad47..00000000 --- a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_mtn.py +++ /dev/null @@ -1,527 +0,0 @@ -# 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 - -import os -import mock - -from twisted.trial import unittest -from twisted.internet import defer - -from buildslave.test.fake.runprocess import Expect -from buildslave.test.util.sourcecommand import SourceCommandTestMixin -from buildslave.commands import mtn - -class TestMonotone(SourceCommandTestMixin, unittest.TestCase): - repourl='mtn://code.monotone.ca/sandbox' - branch='ca.monotone.sandbox.buildbot' - - def setUp(self): - self.setUpCommand() - - def tearDown(self): - self.tearDownCommand() - - def patch_sourcedirIsUpdateable(self, result): - self.cmd.sourcedirIsUpdateable = lambda : result - - - def test_no_db(self): - "Test a basic invocation with mode=copy and no existing sourcedir" - self.patch_getCommand('mtn', 'path/to/mtn') - self.clean_environ() - self.make_command(mtn.Monotone, dict( - workdir='workdir', - mode='copy', - revision=None, - repourl=self.repourl, - branch=self.branch - ), - # no sourcedata -> will do fresh checkout - initial_sourcedata = None, - ) - exp_environ = dict(PWD='.', LC_MESSAGES='C') - expects = [ - Expect(['path/to/mtn', 'db', 'info', - '--db', os.path.join(self.basedir, 'db.mtn')], - self.basedir, - keepStdout=True, sendRC=False, sendStderr=False, - usePTY=False, environ=exp_environ) + 1, - Expect(['path/to/mtn', 'db', 'init', - '--db', os.path.join(self.basedir, 'db.mtn')], - self.basedir, - sendRC=False, usePTY=False, - environ=exp_environ) + 1, - Expect([ 'clobber', 'workdir' ], - self.basedir) + 0, - Expect([ 'clobber', 'source' ], - self.basedir) + 0, - Expect(['path/to/mtn', 'pull', self.repourl+"?"+self.branch, - '--db', os.path.join(self.basedir, 'db.mtn'), - '--ticker=none'], - self.basedir, - keepStdout=True, sendRC=False, timeout=120, usePTY=False, - environ=exp_environ) + 0, - Expect(['path/to/mtn', 'checkout', self.basedir_source, - '--db', os.path.join(self.basedir, 'db.mtn'), - '--branch', 'ca.monotone.sandbox.buildbot'], - self.basedir, - keepStdout=True, sendRC=False, timeout=120, usePTY=False, - environ=exp_environ) + 0, - Expect(['path/to/mtn', 'automate', 'select', 'w:'], - self.basedir_source, - keepStdout=True, sendRC=False, timeout=120, usePTY=False) - + 0, - Expect([ 'copy', 'source', 'workdir'], - self.basedir) - + 0, - ] - - self.patch_runprocess(*expects) - - d = self.run_command() - d.addCallback(self.check_sourcedata, self.repourl+"?"+self.branch) - return d - - def test_db_needs_migrating(self): - "Test a basic invocation with mode=copy and no existing sourcedir" - self.patch_getCommand('mtn', 'path/to/mtn') - self.clean_environ() - self.make_command(mtn.Monotone, dict( - workdir='workdir', - mode='copy', - revision=None, - repourl=self.repourl, - branch=self.branch - ), - # no sourcedata -> will do fresh checkout - initial_sourcedata = None, - ) - exp_environ = dict(PWD='.', LC_MESSAGES='C') - expects = [ - Expect([ 'path/to/mtn', 'db', 'info', - '--db', os.path.join(self.basedir, 'db.mtn') ], - self.basedir, - keepStdout=True, sendRC=False, sendStderr=False, - usePTY=False, environ=exp_environ) - + { 'stdout' : 'blah blah (migration needed)\n' } - + 0, - Expect([ 'path/to/mtn', 'db', 'migrate', - '--db', os.path.join(self.basedir, 'db.mtn') ], - self.basedir, - sendRC=False, usePTY=False, - environ=exp_environ) + 0, - Expect([ 'clobber', 'workdir' ], - self.basedir) + 0, - Expect([ 'clobber', 'source' ], - self.basedir) + 0, - Expect(['path/to/mtn', 'pull', self.repourl+"?"+self.branch, - '--db', os.path.join(self.basedir, 'db.mtn'), - '--ticker=none'], - self.basedir, - keepStdout=True, sendRC=False, timeout=120, usePTY=False, - environ=exp_environ) + 0, - Expect(['path/to/mtn', 'checkout', self.basedir_source, - '--db', os.path.join(self.basedir, 'db.mtn'), - '--branch', 'ca.monotone.sandbox.buildbot'], - self.basedir, - keepStdout=True, sendRC=False, timeout=120, usePTY=False, - environ=exp_environ) + 0, - Expect(['path/to/mtn', 'automate', 'select', 'w:'], - self.basedir_source, - keepStdout=True, sendRC=False, timeout=120, usePTY=False) - + 0, - Expect([ 'copy', 'source', 'workdir'], - self.basedir) - + 0, - ] - - self.patch_runprocess(*expects) - - d = self.run_command() - d.addCallback(self.check_sourcedata, self.repourl+"?"+self.branch) - return d - - def test_db_too_new(self): - "Test a basic invocation with mode=copy and no existing sourcedir" - self.patch_getCommand('mtn', 'path/to/mtn') - self.clean_environ() - self.make_command(mtn.Monotone, dict( - workdir='workdir', - mode='copy', - revision=None, - repourl=self.repourl, - branch=self.branch - ), - # no sourcedata -> will do fresh checkout - initial_sourcedata = None, - ) - - exp_environ = dict(PWD='.', LC_MESSAGES='C') - expects = [ - Expect([ 'path/to/mtn', 'db', 'info', - '--db', os.path.join(self.basedir, 'db.mtn') ], - self.basedir, - keepStdout=True, sendRC=False, sendStderr=False, - usePTY=False, environ=exp_environ) - + { 'stdout' : 'blah blah (too new, cannot use)\n' } - + 0 - ] - - self.patch_runprocess(*expects) - - d = self.run_command() - return self.assertFailure(d, mtn.MonotoneError) - - def test_run_mode_copy_fresh_sourcedir(self): - "Test a basic invocation with mode=copy and no existing sourcedir" - self.patch_getCommand('mtn', 'path/to/mtn') - self.clean_environ() - self.make_command(mtn.Monotone, dict( - workdir='workdir', - mode='copy', - revision=None, - repourl=self.repourl, - branch=self.branch - ), - # no sourcedata -> will do fresh checkout - initial_sourcedata = None, - ) - - exp_environ = dict(PWD='.', LC_MESSAGES='C') - expects = [ - Expect(['path/to/mtn', 'db', 'info', - '--db', os.path.join(self.basedir, 'db.mtn')], - self.basedir, - keepStdout=True, sendRC=False, sendStderr=False, - usePTY=False, environ=exp_environ) + 0, - Expect([ 'clobber', 'workdir' ], - self.basedir) + 0, - Expect([ 'clobber', 'source' ], - self.basedir) + 0, - Expect(['path/to/mtn', 'pull', self.repourl+"?"+self.branch, - '--db', os.path.join(self.basedir, 'db.mtn'), - '--ticker=none'], - self.basedir, - keepStdout=True, sendRC=False, timeout=120, usePTY=False, - environ=exp_environ) + 0, - Expect(['path/to/mtn', 'checkout', self.basedir_source, - '--db', os.path.join(self.basedir, 'db.mtn'), - '--branch', 'ca.monotone.sandbox.buildbot'], - self.basedir, - keepStdout=True, sendRC=False, timeout=120, usePTY=False, - environ=exp_environ) + 0, - Expect(['path/to/mtn', 'automate', 'select', 'w:'], - self.basedir_source, - keepStdout=True, sendRC=False, timeout=120, usePTY=False) - + 0, - Expect([ 'copy', 'source', 'workdir'], - self.basedir) - + 0, - ] - - self.patch_runprocess(*expects) - - d = self.run_command() - d.addCallback(self.check_sourcedata, self.repourl+"?"+self.branch) - return d - - def test_run_mode_copy_update_sourcedir(self): - """test a copy where the sourcedata indicates that the source directory - can be updated""" - self.patch_getCommand('mtn', 'path/to/mtn') - self.clean_environ() - self.make_command(mtn.Monotone, dict( - workdir='workdir', - mode='copy', - revision=None, - repourl=self.repourl, - branch=self.branch, - progress=True, # added here for better coverage - ), - initial_sourcedata = self.repourl+"?"+self.branch - ) - self.patch_sourcedirIsUpdateable(True) - - exp_environ = dict(PWD='.', LC_MESSAGES='C') - expects = [ - Expect([ 'path/to/mtn', 'db', 'info', - '--db', os.path.join(self.basedir, 'db.mtn')], - self.basedir, - keepStdout=True, sendRC=False, sendStderr=False, - usePTY=False, environ=exp_environ) + 0, - Expect([ 'clobber', 'workdir' ], - self.basedir) + 0, - Expect([ 'path/to/mtn', 'pull', self.repourl+"?"+self.branch, - '--db', os.path.join(self.basedir, 'db.mtn'), - '--ticker=dot'], - self.basedir, - keepStdout=True, sendRC=False, timeout=120, usePTY=False, - environ=exp_environ) + 0, - Expect([ 'path/to/mtn', 'update', - '--db', os.path.join(self.basedir, 'db.mtn'), - '-r', 'h:ca.monotone.sandbox.buildbot', - '-b', 'ca.monotone.sandbox.buildbot'], - self.basedir_source, - keepStdout=True, sendRC=False, timeout=120, usePTY=False, - environ=exp_environ) + 0, - Expect(['path/to/mtn', 'automate', 'select', 'w:'], - self.basedir_source, - keepStdout=True, sendRC=False, timeout=120, usePTY=False) - + 0, - Expect([ 'copy', 'source', 'workdir'], - self.basedir) - + 0, - ] - self.patch_runprocess(*expects) - - d = self.run_command() - d.addCallback(self.check_sourcedata, self.repourl+"?"+self.branch) - return d - - def test_run_mode_update_fresh(self): - self.patch_getCommand('mtn', 'path/to/mtn') - self.clean_environ() - self.make_command(mtn.Monotone, dict( - workdir='workdir', - mode='update', - revision=None, - repourl=self.repourl, - branch=self.branch, - progress=True, # added here for better coverage - ), - initial_sourcedata = self.repourl+"?"+self.branch - ) - self.patch_sourcedirIsUpdateable(False) - - exp_environ = dict(PWD='.', LC_MESSAGES='C') - expects = [ - Expect([ 'path/to/mtn', 'db', 'info', - '--db', os.path.join(self.basedir, 'db.mtn')], - self.basedir, - keepStdout=True, sendRC=False, sendStderr=False, - usePTY=False, environ=exp_environ) + 0, - Expect([ 'clobber', 'workdir' ], - self.basedir) + 0, - Expect([ 'path/to/mtn', 'pull', self.repourl+"?"+self.branch, - '--db', os.path.join(self.basedir, 'db.mtn'), - '--ticker=dot'], - self.basedir, - keepStdout=True, sendRC=False, timeout=120, usePTY=False, - environ=exp_environ) + 0, - Expect(['path/to/mtn', 'checkout', self.basedir_workdir, - '--db', os.path.join(self.basedir, 'db.mtn'), - '--branch', 'ca.monotone.sandbox.buildbot'], - self.basedir, - keepStdout=True, sendRC=False, timeout=120, usePTY=False, - environ=exp_environ) + 0, - Expect(['path/to/mtn', 'automate', 'select', 'w:'], - self.basedir_workdir, - keepStdout=True, sendRC=False, timeout=120, usePTY=False) - + 0, - ] - self.patch_runprocess(*expects) - - d = self.run_command() - d.addCallback(self.check_sourcedata, self.repourl+"?"+self.branch) - return d - - def test_run_mode_update_existing(self): - self.patch_getCommand('mtn', 'path/to/mtn') - self.clean_environ() - self.make_command(mtn.Monotone, dict( - workdir='workdir', - mode='update', - revision=None, - repourl=self.repourl, - branch=self.branch, - progress=True, # added here for better coverage - ), - initial_sourcedata = self.repourl+"?"+self.branch - ) - self.patch_sourcedirIsUpdateable(True) - - exp_environ = dict(PWD='.', LC_MESSAGES='C') - expects = [ - Expect([ 'path/to/mtn', 'db', 'info', - '--db', os.path.join(self.basedir, 'db.mtn')], - self.basedir, - keepStdout=True, sendRC=False, sendStderr=False, - usePTY=False, environ=exp_environ) + 0, - Expect([ 'path/to/mtn', 'pull', self.repourl+"?"+self.branch, - '--db', os.path.join(self.basedir, 'db.mtn'), - '--ticker=dot'], - self.basedir, - keepStdout=True, sendRC=False, timeout=120, usePTY=False, - environ=exp_environ) + 0, - Expect([ 'path/to/mtn', 'update', - '--db', os.path.join(self.basedir, 'db.mtn'), - '-r', 'h:ca.monotone.sandbox.buildbot', - '-b', 'ca.monotone.sandbox.buildbot'], - self.basedir_workdir, - keepStdout=True, sendRC=False, timeout=120, usePTY=False, - environ=exp_environ) + 0, - Expect(['path/to/mtn', 'automate', 'select', 'w:'], - self.basedir_workdir, - keepStdout=True, sendRC=False, timeout=120, usePTY=False) - + 0, - ] - self.patch_runprocess(*expects) - - d = self.run_command() - d.addCallback(self.check_sourcedata, self.repourl+"?"+self.branch) - return d - - def test_run_mode_update_existing_known_rev(self): - self.patch_getCommand('mtn', 'path/to/mtn') - self.clean_environ() - self.make_command(mtn.Monotone, dict( - workdir='workdir', - mode='update', - revision='abcdef01', - repourl=self.repourl, - branch=self.branch, - progress=True, # added here for better coverage - ), - initial_sourcedata = self.repourl+"?"+self.branch - ) - self.patch_sourcedirIsUpdateable(True) - - exp_environ = dict(PWD='.', LC_MESSAGES='C') - expects = [ - Expect([ 'path/to/mtn', 'db', 'info', - '--db', os.path.join(self.basedir, 'db.mtn')], - self.basedir, - keepStdout=True, sendRC=False, sendStderr=False, - usePTY=False, environ=exp_environ) + 0, - Expect([ 'path/to/mtn', 'pull', self.repourl+"?"+self.branch, - '--db', os.path.join(self.basedir, 'db.mtn'), - '--ticker=dot'], - self.basedir, - keepStdout=True, sendRC=False, timeout=120, usePTY=False, - environ=exp_environ) + 0, - Expect([ 'path/to/mtn', 'update', - '--db', os.path.join(self.basedir, 'db.mtn'), - '--revision', 'abcdef01', - '-b', 'ca.monotone.sandbox.buildbot'], - self.basedir_workdir, - keepStdout=True, sendRC=False, timeout=120, usePTY=False, - environ=exp_environ) + 0, - Expect(['path/to/mtn', 'automate', 'select', 'w:'], - self.basedir_workdir, - keepStdout=True, sendRC=False, timeout=120, usePTY=False) - + 0, - ] - self.patch_runprocess(*expects) - - d = self.run_command() - d.addCallback(self.check_sourcedata, self.repourl+"?"+self.branch) - return d - - def test_run_mode_update_existing_unknown_rev(self): - self.patch_getCommand('mtn', 'path/to/mtn') - self.clean_environ() - self.make_command(mtn.Monotone, dict( - workdir='workdir', - mode='update', - revision='abcdef01', - repourl=self.repourl, - branch=self.branch, - progress=True, # added here for better coverage - ), - initial_sourcedata = self.repourl+"?"+self.branch - ) - self.patch_sourcedirIsUpdateable(True) - - exp_environ = dict(PWD='.', LC_MESSAGES='C') - expects = [ - Expect([ 'path/to/mtn', 'db', 'info', - '--db', os.path.join(self.basedir, 'db.mtn')], - self.basedir, - keepStdout=True, sendRC=False, sendStderr=False, - usePTY=False, environ=exp_environ) + 0, - Expect([ 'path/to/mtn', 'pull', self.repourl+"?"+self.branch, - '--db', os.path.join(self.basedir, 'db.mtn'), - '--ticker=dot'], - self.basedir, - keepStdout=True, sendRC=False, timeout=120, usePTY=False, - environ=exp_environ) + 0, - Expect([ 'path/to/mtn', 'update', - '--db', os.path.join(self.basedir, 'db.mtn'), - '--revision', 'abcdef01', - '-b', 'ca.monotone.sandbox.buildbot'], - self.basedir_workdir, - keepStdout=True, sendRC=False, timeout=120, usePTY=False, - environ=exp_environ) + 1, - Expect([ 'clobber', 'workdir' ], - self.basedir) + 0, - Expect([ 'path/to/mtn', 'pull', self.repourl+"?"+self.branch, - '--db', os.path.join(self.basedir, 'db.mtn'), - '--ticker=dot'], - self.basedir, - keepStdout=True, sendRC=False, timeout=120, usePTY=False, - environ=exp_environ) + 0, - Expect(['path/to/mtn', 'checkout', self.basedir_workdir, - '--db', os.path.join(self.basedir, 'db.mtn'), - '--revision', 'abcdef01', - '--branch', 'ca.monotone.sandbox.buildbot'], - self.basedir, - keepStdout=True, sendRC=False, timeout=120, usePTY=False, - environ=exp_environ) + 0, - Expect(['path/to/mtn', 'automate', 'select', 'w:'], - self.basedir_workdir, - keepStdout=True, sendRC=False, timeout=120, usePTY=False) - + 0, - ] - self.patch_runprocess(*expects) - - d = self.run_command() - d.addCallback(self.check_sourcedata, self.repourl+"?"+self.branch) - return d - -# Testing parseGotRevision - def do_test_parseGotRevision(self, stdout, exp): - self.patch_getCommand('mtn', 'path/to/mtn') - self.make_command(mtn.Monotone, dict( - workdir='workdir', - repourl=self.repourl, - branch=self.branch - )) - def _dovccmd(fn, dopull, callback=None, keepStdout=False): - #self.assertTrue(keepStdout) - self.cmd.command = mock.Mock() - self.cmd.command.stdout = stdout - d = defer.succeed(None) - d.addCallback(callback) - return d - self.cmd._dovccmd = _dovccmd - self.cmd.srcdir = self.cmd.workdir - - d = self.cmd.parseGotRevision() - def check(res): - self.assertEqual(res, exp) - d.addCallback(check) - return d - - def test_parseGotRevision_bogus(self): - return self.do_test_parseGotRevision("mtn: misuse: no match for selection '1234'\n", None) - - def test_parseGotRevision_wrong_length(self): - return self.do_test_parseGotRevision("\n1234abcd\n", None) - - def test_parseGotRevision_ok(self): - return self.do_test_parseGotRevision( - "\n4026d33b0532b11f36b0875f63699adfa8ee8662\n", - "4026d33b0532b11f36b0875f63699adfa8ee8662") - diff --git a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_p4.py b/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_p4.py deleted file mode 100644 index efceb74d..00000000 --- a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_p4.py +++ /dev/null @@ -1,186 +0,0 @@ -# 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 twisted.trial import unittest - -from buildslave.test.fake.runprocess import Expect -from buildslave.test.util.sourcecommand import SourceCommandTestMixin -from buildslave.commands import p4 -from buildslave.util import Obfuscated - -class TestP4(SourceCommandTestMixin, unittest.TestCase): - - def setUp(self): - self.setUpCommand() - - def tearDown(self): - self.tearDownCommand() - - def test_simple(self): - self.patch_getCommand('p4', 'path/to/p4') - self.clean_environ() - self.make_command(p4.P4, dict( - workdir='workdir', - mode='copy', - revision=None, - p4port='p4dserv:1666', - p4client='buildbot_test_10', - p4user='jimmy', - p4passwd='hushnow', - p4base='//mydepot/myproj/', - branch='mytrunk', - p4extra_views=[], - )) - - exp_environ = dict(PWD='.', LC_MESSAGES='C') - # can't use textwrap.dedent here, because in 2.4 it converts \t to 8x' ' - client_spec = """\ -Client: buildbot_test_10 - -Owner: jimmy - -Description: -\tCreated by jimmy - -Root:\t%s - -Options:\tallwrite rmdir - -LineEnd:\tlocal - -View: -\t//mydepot/myproj/mytrunk/... //buildbot_test_10/source/... -""" % self.basedir - expects = [ - Expect([ 'clobber', 'workdir' ], - self.basedir) - + 0, - Expect([ 'clobber', 'source' ], - self.basedir) - + 0, - Expect(['p4', '-p', 'p4dserv:1666', '-u', 'jimmy', '-P', - Obfuscated('hushnow', 'XXXXXXXX'), 'client', '-i'], - self.basedir, - # TODO: empty env? - sendRC=False, timeout=120, usePTY=False, environ={}, - initialStdin=client_spec) - + 0, - Expect(['p4', '-p', 'p4dserv:1666', '-u', 'jimmy', '-P', - Obfuscated('hushnow', 'XXXXXXXX'), '-c', 'buildbot_test_10', 'sync', '-f'], - self.basedir, - # TODO: empty env? - sendRC=False, timeout=120, usePTY=False, environ={}) - + 0, - Expect(['p4', '-p', 'p4dserv:1666', '-u', 'jimmy', '-P', - Obfuscated('hushnow', 'XXXXXXXX'), '-c', 'buildbot_test_10', 'changes', - '-s', 'submitted', '-m', '1', '#have'], - self.basedir, - sendRC=False, timeout=120, usePTY=False, environ=exp_environ, - keepStdout=True) - + { 'stdout' : 'Change 28147 on 2008/04/07 by p4user@hostname\n' } - + 0, - Expect([ 'copy', 'source', 'workdir'], - self.basedir) - + 0, - ] - self.patch_runprocess(*expects) - - d = self.run_command() - d.addCallback(self.check_sourcedata, "['p4dserv:1666', 'buildbot_test_10', " + - "'//mydepot/myproj/', 'mytrunk', [], None, %s, 'copy', 'workdir']" - % `self.basedir`) - return d - - def test_simple_unicode_args(self): - self.patch_getCommand('p4', 'path/to/p4') - self.clean_environ() - self.make_command(p4.P4, dict( - workdir='workdir', - mode='copy', - revision=None, - p4port=u'p4dserv:1666\N{SNOWMAN}', - p4client=u'buildbot_test_10\N{SNOWMAN}', - p4user='jimmy', - p4passwd='hushnow', - p4base=u'//mydepot/myproj/\N{SNOWMAN}', - branch=u'mytrunk\N{SNOWMAN}', - p4extra_views=[], - )) - - exp_environ = dict(PWD='.', LC_MESSAGES='C') - # can't use textwrap.dedent here, because in 2.4 it converts \t to 8x' ' - client_spec = """\ -Client: buildbot_test_10 - -Owner: jimmy - -Description: -\tCreated by jimmy - -Root:\t%s - -Options:\tallwrite rmdir - -LineEnd:\tlocal - -View: -\t//mydepot/myproj/mytrunk/... //buildbot_test_10/source/... -""" % self.basedir - expects = [ - Expect([ 'clobber', 'workdir' ], - self.basedir) - + 0, - Expect([ 'clobber', 'source' ], - self.basedir) - + 0, - Expect(['p4', '-p', u'p4dserv:1666\N{SNOWMAN}', '-u', 'jimmy', '-P', - Obfuscated('hushnow', 'XXXXXXXX'), 'client', '-i'], - self.basedir, - # TODO: empty env? - sendRC=False, timeout=120, usePTY=False, environ={}, - initialStdin=client_spec) - + 0, - Expect(['p4', '-p', u'p4dserv:1666\N{SNOWMAN}', '-u', 'jimmy', '-P', - Obfuscated('hushnow', 'XXXXXXXX'), '-c', - u'buildbot_test_10\N{SNOWMAN}', 'sync', '-f'], - self.basedir, - # TODO: empty env? - sendRC=False, timeout=120, usePTY=False, environ={}) - + 0, - Expect(['p4', '-p', u'p4dserv:1666\N{SNOWMAN}', '-u', 'jimmy', '-P', - Obfuscated('hushnow', 'XXXXXXXX'), '-c', - u'buildbot_test_10\N{SNOWMAN}', 'changes', - '-s', 'submitted', '-m', '1', '#have'], - self.basedir, - sendRC=False, timeout=120, usePTY=False, environ=exp_environ, - keepStdout=True) - + { 'stdout' : 'Change 28147 on 2008/04/07 by p4user@hostname\n' } - + 0, - Expect([ 'copy', 'source', 'workdir'], - self.basedir) - + 0, - ] - self.patch_runprocess(*expects) - - d = self.run_command() - d.addCallback(self.check_sourcedata, - "['p4dserv:1666\\xe2\\x98\\x83', " - "'buildbot_test_10\\xe2\\x98\\x83', " - "'//mydepot/myproj/\\xe2\\x98\\x83', " - "'mytrunk\\xe2\\x98\\x83', [], None, %s, 'copy', " - "'workdir']" - % `self.basedir`) - return d - diff --git a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_registry.py b/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_registry.py deleted file mode 100644 index c451246e..00000000 --- a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_registry.py +++ /dev/null @@ -1,36 +0,0 @@ -# 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 twisted.trial import unittest - -from buildslave.commands import registry -from buildslave.commands import shell - -class Registry(unittest.TestCase): - - def test_getFactory(self): - factory = registry.getFactory('shell') - self.assertEqual(factory, shell.SlaveShellCommand) - - def test_getFactory_KeyError(self): - self.assertRaises(KeyError, lambda : registry.getFactory('nosuchcommand')) - - def test_getAllCommandNames(self): - self.failUnless('shell' in registry.getAllCommandNames()) - - def test_all_commands_exist(self): - # if this doesn't raise a KeyError, then we're good - for n in registry.getAllCommandNames(): - registry.getFactory(n) diff --git a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_shell.py b/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_shell.py deleted file mode 100644 index e5dcac4a..00000000 --- a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_shell.py +++ /dev/null @@ -1,52 +0,0 @@ -# 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 twisted.trial import unittest - -from buildslave.test.fake.runprocess import Expect -from buildslave.test.util.command import CommandTestMixin -from buildslave.commands import shell - -class TestSlaveShellCommand(CommandTestMixin, unittest.TestCase): - - def setUp(self): - self.setUpCommand() - - def tearDown(self): - self.tearDownCommand() - - def test_simple(self): - self.make_command(shell.SlaveShellCommand, dict( - command=[ 'echo', 'hello' ], - workdir='workdir', - )) - - self.patch_runprocess( - Expect([ 'echo', 'hello' ], self.basedir_workdir) - + { 'hdr' : 'headers' } + { 'stdout' : 'hello\n' } + { 'rc' : 0 } - + 0, - ) - - d = self.run_command() - - # note that SlaveShellCommand does not add any extra updates of it own - def check(_): - self.assertUpdates( - [{'hdr': 'headers'}, {'stdout': 'hello\n'}, {'rc': 0}], - self.builder.show()) - d.addCallback(check) - return d - - # TODO: test all functionality that SlaveShellCommand adds atop RunProcess diff --git a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_svn.py b/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_svn.py deleted file mode 100644 index fae28588..00000000 --- a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_svn.py +++ /dev/null @@ -1,102 +0,0 @@ -# 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 twisted.trial import unittest - -from buildslave.test.fake.runprocess import Expect -from buildslave.test.util.sourcecommand import SourceCommandTestMixin -from buildslave.commands import svn - -class TestSVN(SourceCommandTestMixin, unittest.TestCase): - - def setUp(self): - self.setUpCommand() - - def tearDown(self): - self.tearDownCommand() - - def test_simple(self): - self.patch_getCommand('svn', 'path/to/svn') - self.patch_getCommand('svnversion', 'path/to/svnversion') - self.clean_environ() - self.make_command(svn.SVN, dict( - workdir='workdir', - mode='copy', - revision=None, - svnurl='http://svn.local/app/trunk', - )) - - exp_environ = dict(PWD='.', LC_MESSAGES='C') - expects = [ - Expect([ 'clobber', 'workdir' ], - self.basedir) - + 0, - Expect([ 'clobber', 'source' ], - self.basedir) - + 0, - Expect([ 'path/to/svn', 'checkout', '--non-interactive', '--no-auth-cache', - '--revision', 'HEAD', 'http://svn.local/app/trunk@HEAD', 'source' ], - self.basedir, - sendRC=False, timeout=120, usePTY=False, environ=exp_environ) - + 0, - Expect([ 'path/to/svnversion', '.' ], - self.basedir_source, - sendRC=False, timeout=120, usePTY=False, keepStdout=True, - environ=exp_environ, sendStderr=False, sendStdout=False) - + { 'stdout' : '9753\n' } - + 0, - Expect([ 'copy', 'source', 'workdir'], - self.basedir) - + 0, - ] - self.patch_runprocess(*expects) - - d = self.run_command() - d.addCallback(self.check_sourcedata, "http://svn.local/app/trunk\n") - return d - - -class TestGetUnversionedFiles(unittest.TestCase): - def test_getUnversionedFiles_does_not_list_externals(self): - svn_st_xml = """<?xml version="1.0"?> - <status> - <target path="."> - <entry path="svn_external_path"> - <wc-status props="none" item="external"> - </wc-status> - </entry> - <entry path="svn_external_path/unversioned_file"> - <wc-status props="none" item="unversioned"> - </wc-status> - </entry> - </target> - </status> - """ - unversioned_files = list(svn.SVN.getUnversionedFiles(svn_st_xml, [])) - self.assertEquals(["svn_external_path/unversioned_file"], unversioned_files) - - def test_getUnversionedFiles_does_not_list_missing(self): - svn_st_xml = """<?xml version="1.0"?> - <status> - <target path="."> - <entry path="missing_file"> - <wc-status props="none" item="missing"></wc-status> - </entry> - </target> - </status> - """ - unversioned_files = list(svn.SVN.getUnversionedFiles(svn_st_xml, [])) - self.assertEquals([], unversioned_files) - diff --git a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_transfer.py b/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_transfer.py deleted file mode 100644 index 45dc7779..00000000 --- a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_transfer.py +++ /dev/null @@ -1,527 +0,0 @@ -# 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 - -import os -import sys -import shutil -import tarfile -import StringIO - -from twisted.trial import unittest -from twisted.internet import defer, reactor -from twisted.python import runtime, failure - -from buildslave.test.fake.remote import FakeRemote -from buildslave.test.util.command import CommandTestMixin -from buildslave.commands import transfer - -class FakeMasterMethods(object): - # a fake to represent any of: - # - FileWriter - # - FileDirectoryWriter - # - FileReader - def __init__(self, add_update): - self.add_update = add_update - - self.delay_write = False - self.count_writes = False - self.keep_data = False - self.write_out_of_space_at = None - - self.delay_read = False - self.count_reads = False - - self.unpack_fail = False - - self.written = False - self.read = False - self.data = '' - - def remote_write(self, data): - if self.write_out_of_space_at is not None: - self.write_out_of_space_at -= len(data) - if self.write_out_of_space_at <= 0: - f = failure.Failure(RuntimeError("out of space")) - return defer.fail(f) - if self.count_writes: - self.add_update('write %d' % len(data)) - elif not self.written: - self.add_update('write(s)') - self.written = True - - if self.keep_data: - self.data += data - - if self.delay_write: - d = defer.Deferred() - reactor.callLater(0.01, d.callback, None) - return d - - def remote_read(self, length): - if self.count_reads: - self.add_update('read %d' % length) - elif not self.read: - self.add_update('read(s)') - self.read = True - - if not self.data: - return '' - - slice, self.data = self.data[:length], self.data[length:] - if self.delay_read: - d = defer.Deferred() - reactor.callLater(0.01, d.callback, slice) - return d - else: - return slice - - def remote_unpack(self): - self.add_update('unpack') - if self.unpack_fail: - return defer.fail(failure.Failure(RuntimeError("out of space"))) - - def remote_utime(self,accessed_modified): - self.add_update('utime - %s' % accessed_modified[0]) - - def remote_close(self): - self.add_update('close') - -class TestUploadFile(CommandTestMixin, unittest.TestCase): - - def setUp(self): - self.setUpCommand() - - self.fakemaster = FakeMasterMethods(self.add_update) - - # write 180 bytes of data to upload - self.datadir = os.path.join(self.basedir, 'workdir') - if os.path.exists(self.datadir): - shutil.rmtree(self.datadir) - os.makedirs(self.datadir) - - self.datafile = os.path.join(self.datadir, 'data') - # note: use of 'wb' here ensures newlines aren't translated on the upload - open(self.datafile, "wb").write("this is some data\n" * 10) - - def tearDown(self): - self.tearDownCommand() - - if os.path.exists(self.datadir): - shutil.rmtree(self.datadir) - - def test_simple(self): - self.fakemaster.count_writes = True # get actual byte counts - - self.make_command(transfer.SlaveFileUploadCommand, dict( - workdir='workdir', - slavesrc='data', - writer=FakeRemote(self.fakemaster), - maxsize=1000, - blocksize=64, - keepstamp=False, - )) - - d = self.run_command() - - def check(_): - self.assertUpdates([ - {'header': 'sending %s' % self.datafile}, - 'write 64', 'write 64', 'write 52', 'close', - {'rc': 0} - ]) - d.addCallback(check) - return d - - def test_truncated(self): - self.fakemaster.count_writes = True # get actual byte counts - - self.make_command(transfer.SlaveFileUploadCommand, dict( - workdir='workdir', - slavesrc='data', - writer=FakeRemote(self.fakemaster), - maxsize=100, - blocksize=64, - keepstamp=False, - )) - - d = self.run_command() - - def check(_): - self.assertUpdates([ - {'header': 'sending %s' % self.datafile}, - 'write 64', 'write 36', 'close', - {'rc': 1, - 'stderr': "Maximum filesize reached, truncating file '%s'" % self.datafile} - ]) - d.addCallback(check) - return d - - def test_missing(self): - self.make_command(transfer.SlaveFileUploadCommand, dict( - workdir='workdir', - slavesrc='data-nosuch', - writer=FakeRemote(self.fakemaster), - maxsize=100, - blocksize=64, - keepstamp=False, - )) - - d = self.run_command() - - def check(_): - df = self.datafile + "-nosuch" - self.assertUpdates([ - {'header': 'sending %s' % df}, - 'close', - {'rc': 1, - 'stderr': "Cannot open file '%s' for upload" % df} - ]) - d.addCallback(check) - return d - - def test_out_of_space(self): - self.fakemaster.write_out_of_space_at = 70 - self.fakemaster.count_writes = True # get actual byte counts - - self.make_command(transfer.SlaveFileUploadCommand, dict( - workdir='workdir', - slavesrc='data', - writer=FakeRemote(self.fakemaster), - maxsize=1000, - blocksize=64, - keepstamp=False, - )) - - d = self.run_command() - self.assertFailure(d, RuntimeError) - def check(_): - self.assertUpdates([ - {'header': 'sending %s' % self.datafile}, - 'write 64', 'close', - {'rc': 1} - ]) - d.addCallback(check) - return d - - def test_interrupted(self): - self.fakemaster.delay_write = True # write veery slowly - - self.make_command(transfer.SlaveFileUploadCommand, dict( - workdir='workdir', - slavesrc='data', - writer=FakeRemote(self.fakemaster), - maxsize=100, - blocksize=2, - keepstamp=False, - )) - - d = self.run_command() - - # wait a jiffy.. - interrupt_d = defer.Deferred() - reactor.callLater(0.01, interrupt_d.callback, None) - - # and then interrupt the step - def do_interrupt(_): - return self.cmd.interrupt() - interrupt_d.addCallback(do_interrupt) - - dl = defer.DeferredList([d, interrupt_d]) - def check(_): - self.assertUpdates([ - {'header': 'sending %s' % self.datafile}, - 'write(s)', 'close', {'rc': 1} - ]) - dl.addCallback(check) - return dl - - def test_timestamp(self): - self.fakemaster.count_writes = True # get actual byte counts - timestamp = ( os.path.getatime(self.datafile), - os.path.getmtime(self.datafile) ) - - self.make_command(transfer.SlaveFileUploadCommand, dict( - workdir='workdir', - slavesrc='data', - writer=FakeRemote(self.fakemaster), - maxsize=1000, - blocksize=64, - keepstamp=True, - )) - - d = self.run_command() - - def check(_): - self.assertUpdates([ - {'header': 'sending %s' % self.datafile}, - 'write 64', 'write 64', 'write 52', - 'close','utime - %s' % timestamp[0], - {'rc': 0} - ]) - d.addCallback(check) - return d - -class TestSlaveDirectoryUpload(CommandTestMixin, unittest.TestCase): - - def setUp(self): - self.setUpCommand() - - self.fakemaster = FakeMasterMethods(self.add_update) - - # write a directory to upload - self.datadir = os.path.join(self.basedir, 'workdir', 'data') - if os.path.exists(self.datadir): - shutil.rmtree(self.datadir) - os.makedirs(self.datadir) - open(os.path.join(self.datadir, "aa"), "wb").write("lots of a" * 100) - open(os.path.join(self.datadir, "bb"), "wb").write("and a little b" * 17) - - def tearDown(self): - self.tearDownCommand() - - if os.path.exists(self.datadir): - shutil.rmtree(self.datadir) - - def test_simple(self, compress=None): - self.fakemaster.keep_data = True - - self.make_command(transfer.SlaveDirectoryUploadCommand, dict( - workdir='workdir', - slavesrc='data', - writer=FakeRemote(self.fakemaster), - maxsize=None, - blocksize=512, - compress=compress, - )) - - d = self.run_command() - - def check(_): - self.assertUpdates([ - {'header': 'sending %s' % self.datadir}, - 'write(s)', 'unpack', # note no 'close" - {'rc': 0} - ]) - d.addCallback(check) - - def check_tarfile(_): - f = StringIO.StringIO(self.fakemaster.data) - a = tarfile.open(fileobj=f, name='check.tar') - exp_names = [ '.', 'aa', 'bb' ] - got_names = [ n.rstrip('/') for n in a.getnames() ] - got_names = sorted([ n or '.' for n in got_names ]) # py27 uses '' instead of '.' - self.assertEqual(got_names, exp_names, "expected archive contents") - a.close() - f.close() - d.addCallback(check_tarfile) - - return d - - # try it again with bz2 and gzip - def test_simple_bz2(self): - return self.test_simple('bz2') - def test_simple_gz(self): - return self.test_simple('gz') - - # except bz2 can't operate in stream mode on py24 - if sys.version_info[:2] <= (2,4): - test_simple_bz2.skip = "bz2 stream decompression not supported on Python-2.4" - - def test_out_of_space_unpack(self): - self.fakemaster.keep_data = True - self.fakemaster.unpack_fail = True - - self.make_command(transfer.SlaveDirectoryUploadCommand, dict( - workdir='workdir', - slavesrc='data', - writer=FakeRemote(self.fakemaster), - maxsize=None, - blocksize=512, - compress=None - )) - - d = self.run_command() - self.assertFailure(d, RuntimeError) - - def check(_): - self.assertUpdates([ - {'header': 'sending %s' % self.datadir}, - 'write(s)', 'unpack', - {'rc': 1} - ]) - d.addCallback(check) - - return d - - # this is just a subclass of SlaveUpload, so the remaining permutations - # are already tested - -class TestDownloadFile(CommandTestMixin, unittest.TestCase): - - def setUp(self): - self.setUpCommand() - - self.fakemaster = FakeMasterMethods(self.add_update) - - # the command will write to the basedir, so make sure it exists - if os.path.exists(self.basedir): - shutil.rmtree(self.basedir) - os.makedirs(self.basedir) - - def tearDown(self): - self.tearDownCommand() - - if os.path.exists(self.basedir): - shutil.rmtree(self.basedir) - - def test_simple(self): - self.fakemaster.count_reads = True # get actual byte counts - self.fakemaster.data = test_data = '1234' * 13 - assert(len(self.fakemaster.data) == 52) - - self.make_command(transfer.SlaveFileDownloadCommand, dict( - workdir='.', - slavedest='data', - reader=FakeRemote(self.fakemaster), - maxsize=None, - blocksize=32, - mode=0777, - )) - - d = self.run_command() - - def check(_): - self.assertUpdates([ - 'read 32', 'read 32', 'read 32', 'close', - {'rc': 0} - ]) - datafile = os.path.join(self.basedir, 'data') - self.assertTrue(os.path.exists(datafile)) - self.assertEqual(open(datafile).read(), test_data) - if runtime.platformType != 'win32': - self.assertEqual(os.stat(datafile).st_mode & 0777, 0777) - d.addCallback(check) - return d - - def test_mkdir(self): - self.fakemaster.data = test_data = 'hi' - - self.make_command(transfer.SlaveFileDownloadCommand, dict( - workdir='workdir', - slavedest=os.path.join('subdir', 'data'), - reader=FakeRemote(self.fakemaster), - maxsize=None, - blocksize=32, - mode=0777, - )) - - d = self.run_command() - - def check(_): - self.assertUpdates([ - 'read(s)', 'close', - {'rc': 0} - ]) - datafile = os.path.join(self.basedir, 'workdir', 'subdir', 'data') - self.assertTrue(os.path.exists(datafile)) - self.assertEqual(open(datafile).read(), test_data) - d.addCallback(check) - return d - - def test_failure(self): - self.fakemaster.data = 'hi' - - os.makedirs(os.path.join(self.basedir, 'dir')) - self.make_command(transfer.SlaveFileDownloadCommand, dict( - workdir='.', - slavedest='dir', ## but that's a directory! - reader=FakeRemote(self.fakemaster), - maxsize=None, - blocksize=32, - mode=0777, - )) - - d = self.run_command() - - def check(_): - self.assertUpdates([ - 'close', - {'rc': 1, - 'stderr': "Cannot open file '%s' for download" - % os.path.join(self.basedir, '.', 'dir')} - ]) - d.addCallback(check) - return d - - - def test_truncated(self): - self.fakemaster.data = test_data = 'tenchars--' * 10 - - self.make_command(transfer.SlaveFileDownloadCommand, dict( - workdir='.', - slavedest='data', - reader=FakeRemote(self.fakemaster), - maxsize=50, - blocksize=32, - mode=0777, - )) - - d = self.run_command() - - def check(_): - self.assertUpdates([ - 'read(s)', 'close', - {'rc': 1, - 'stderr': "Maximum filesize reached, truncating file '%s'" - % os.path.join(self.basedir, '.', 'data')} - ]) - datafile = os.path.join(self.basedir, 'data') - self.assertTrue(os.path.exists(datafile)) - self.assertEqual(open(datafile).read(), test_data[:50]) - d.addCallback(check) - return d - - def test_interrupted(self): - self.fakemaster.data = 'tenchars--' * 100 # 1k - self.fakemaster.delay_read = True # read veery slowly - - self.make_command(transfer.SlaveFileDownloadCommand, dict( - workdir='.', - slavedest='data', - reader=FakeRemote(self.fakemaster), - maxsize=100, - blocksize=2, - mode=0777, - )) - - d = self.run_command() - - # wait a jiffy.. - interrupt_d = defer.Deferred() - reactor.callLater(0.01, interrupt_d.callback, None) - - # and then interrupt the step - def do_interrupt(_): - return self.cmd.interrupt() - interrupt_d.addCallback(do_interrupt) - - dl = defer.DeferredList([d, interrupt_d]) - def check(_): - self.assertUpdates([ - 'read(s)', 'close', {'rc': 1} - ]) - dl.addCallback(check) - return dl - diff --git a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_utils.py b/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_utils.py deleted file mode 100644 index 2dae394d..00000000 --- a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_commands_utils.py +++ /dev/null @@ -1,133 +0,0 @@ -# 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 - -import os, sys -import shutil - -from twisted.trial import unittest -from twisted.python import runtime -import twisted.python.procutils - -from buildslave.commands import utils - -class GetCommand(unittest.TestCase): - - def setUp(self): - # monkey-patch 'which' to return something appropriate - self.which_results = {} - def which(arg): - return self.which_results.get(arg, []) - self.patch(twisted.python.procutils, 'which', which) - # note that utils.py currently imports which by name, so we - # patch it there, too - self.patch(utils, 'which', which) - - def set_which_results(self, results): - self.which_results = results - - def test_getCommand_empty(self): - self.set_which_results({ - 'xeyes' : [], - }) - self.assertRaises(RuntimeError, lambda : utils.getCommand('xeyes')) - - def test_getCommand_single(self): - self.set_which_results({ - 'xeyes' : [ '/usr/bin/xeyes' ], - }) - self.assertEqual(utils.getCommand('xeyes'), '/usr/bin/xeyes') - - def test_getCommand_multi(self): - self.set_which_results({ - 'xeyes' : [ '/usr/bin/xeyes', '/usr/X11/bin/xeyes' ], - }) - self.assertEqual(utils.getCommand('xeyes'), '/usr/bin/xeyes') - - def test_getCommand_single_exe(self): - self.set_which_results({ - 'xeyes' : [ '/usr/bin/xeyes' ], - # it should not select this option, since only one matched - # to begin with - 'xeyes.exe' : [ r'c:\program files\xeyes.exe' ], - }) - self.assertEqual(utils.getCommand('xeyes'), '/usr/bin/xeyes') - - def test_getCommand_multi_exe(self): - self.set_which_results({ - 'xeyes' : [ r'c:\program files\xeyes.com', r'c:\program files\xeyes.exe' ], - 'xeyes.exe' : [ r'c:\program files\xeyes.exe' ], - }) - # this one will work out differently depending on platform.. - if runtime.platformType == 'win32': - self.assertEqual(utils.getCommand('xeyes'), r'c:\program files\xeyes.exe') - else: - self.assertEqual(utils.getCommand('xeyes'), r'c:\program files\xeyes.com') - -class RmdirRecursive(unittest.TestCase): - - # this is more complicated than you'd think because Twisted doesn't - # rmdir its test directory very well, either.. - - def setUp(self): - self.target = 'testdir' - try: - if os.path.exists(self.target): - shutil.rmtree(self.target) - except: - # this test will probably fail anyway - e = sys.exc_info()[0] - raise unittest.SkipTest("could not clean before test: %s" % (e,)) - - # fill it with some files - os.mkdir(os.path.join(self.target)) - open( os.path.join(self.target, "a"), "w") - os.mkdir(os.path.join(self.target, "d")) - open( os.path.join(self.target, "d", "a"), "w") - os.mkdir(os.path.join(self.target, "d", "d")) - open( os.path.join(self.target, "d", "d", "a"), "w") - - def tearDown(self): - try: - if os.path.exists(self.target): - shutil.rmtree(self.target) - except: - print "\n(target directory was not removed by test, and cleanup failed too)\n" - raise - - def test_rmdirRecursive_easy(self): - utils.rmdirRecursive(self.target) - self.assertFalse(os.path.exists(self.target)) - - def test_rmdirRecursive_symlink(self): - # this was intended as a regression test for #792, but doesn't seem - # to trigger it. It can't hurt to check it, all the same. - if runtime.platformType == 'win32': - raise unittest.SkipTest("no symlinks on this platform") - os.mkdir("noperms") - open("noperms/x", "w") - os.chmod("noperms/x", 0) - try: - os.symlink("../noperms", os.path.join(self.target, "link")) - utils.rmdirRecursive(self.target) - # that shouldn't delete the target of the symlink - self.assertTrue(os.path.exists("noperms")) - finally: - # even Twisted can't clean this up very well, so try hard to - # clean it up ourselves.. - os.chmod("noperms/x", 0777) - os.unlink("noperms/x") - os.rmdir("noperms") - - self.assertFalse(os.path.exists(self.target)) diff --git a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_runprocess.py b/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_runprocess.py deleted file mode 100644 index 17226fa4..00000000 --- a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_runprocess.py +++ /dev/null @@ -1,700 +0,0 @@ -# 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 - -import sys -import re -import os -import time -import signal - -from twisted.trial import unittest -from twisted.internet import task, defer, reactor -from twisted.python import runtime, util, log - -from buildslave.test.util.misc import nl, BasedirMixin -from buildslave.test.util import compat -from buildslave.test.fake.slavebuilder import FakeSlaveBuilder -from buildslave.exceptions import AbandonChain -from buildslave import runprocess, util as bsutil - -def stdoutCommand(output): - return [sys.executable, '-c', 'import sys; sys.stdout.write("%s\\n")' % output] - -def stderrCommand(output): - return [sys.executable, '-c', 'import sys; sys.stderr.write("%s\\n")' % output] - -def sleepCommand(dur): - return [sys.executable, '-c', 'import time; time.sleep(%d)' % dur] - -def scriptCommand(function, *args): - runprocess_scripts = util.sibpath(__file__, 'runprocess-scripts.py') - return [sys.executable, runprocess_scripts, function] + list(args) - -# windows returns rc 1, because exit status cannot indicate "signalled"; -# posix returns rc -1 for "signalled" -FATAL_RC = -1 -if runtime.platformType == 'win32': - FATAL_RC = 1 - -# We would like to see debugging output in the test.log -runprocess.RunProcessPP.debug = True - -class TestRunProcess(BasedirMixin, unittest.TestCase): - def setUp(self): - self.setUpBasedir() - - def tearDown(self): - self.tearDownBasedir() - - def testCommandEncoding(self): - b = FakeSlaveBuilder(False, self.basedir) - s = runprocess.RunProcess(b, u'abcd', self.basedir) - self.assertIsInstance(s.command, str) - self.assertIsInstance(s.fake_command, str) - - def testCommandEncodingList(self): - b = FakeSlaveBuilder(False, self.basedir) - s = runprocess.RunProcess(b, [ u'abcd', 'efg' ], self.basedir) - self.assertIsInstance(s.command[0], str) - self.assertIsInstance(s.fake_command[0], str) - - def testCommandEncodingObfuscated(self): - b = FakeSlaveBuilder(False, self.basedir) - s = runprocess.RunProcess(b, - [ bsutil.Obfuscated(u'abcd', u'ABCD') ], - self.basedir) - self.assertIsInstance(s.command[0], str) - self.assertIsInstance(s.fake_command[0], str) - - def testStart(self): - b = FakeSlaveBuilder(False, self.basedir) - s = runprocess.RunProcess(b, stdoutCommand('hello'), self.basedir) - - d = s.start() - def check(ign): - self.failUnless({'stdout': nl('hello\n')} in b.updates, b.show()) - self.failUnless({'rc': 0} in b.updates, b.show()) - d.addCallback(check) - return d - - def testNoStdout(self): - b = FakeSlaveBuilder(False, self.basedir) - s = runprocess.RunProcess(b, stdoutCommand('hello'), self.basedir, sendStdout=False) - - d = s.start() - def check(ign): - self.failIf({'stdout': nl('hello\n')} in b.updates, b.show()) - self.failUnless({'rc': 0} in b.updates, b.show()) - d.addCallback(check) - return d - - def testKeepStdout(self): - b = FakeSlaveBuilder(False, self.basedir) - s = runprocess.RunProcess(b, stdoutCommand('hello'), self.basedir, keepStdout=True) - - d = s.start() - def check(ign): - self.failUnless({'stdout': nl('hello\n')} in b.updates, b.show()) - self.failUnless({'rc': 0} in b.updates, b.show()) - self.failUnlessEquals(s.stdout, nl('hello\n')) - d.addCallback(check) - return d - - def testStderr(self): - b = FakeSlaveBuilder(False, self.basedir) - s = runprocess.RunProcess(b, stderrCommand("hello"), self.basedir) - - d = s.start() - def check(ign): - self.failIf({'stderr': nl('hello\n')} not in b.updates, b.show()) - self.failUnless({'rc': 0} in b.updates, b.show()) - d.addCallback(check) - return d - - def testNoStderr(self): - b = FakeSlaveBuilder(False, self.basedir) - s = runprocess.RunProcess(b, stderrCommand("hello"), self.basedir, sendStderr=False) - - d = s.start() - def check(ign): - self.failIf({'stderr': nl('hello\n')} in b.updates, b.show()) - self.failUnless({'rc': 0} in b.updates, b.show()) - d.addCallback(check) - return d - - def testKeepStderr(self): - b = FakeSlaveBuilder(False, self.basedir) - s = runprocess.RunProcess(b, stderrCommand("hello"), self.basedir, keepStderr=True) - - d = s.start() - def check(ign): - self.failUnless({'stderr': nl('hello\n')} in b.updates, b.show()) - self.failUnless({'rc': 0} in b.updates, b.show()) - self.failUnlessEquals(s.stderr, nl('hello\n')) - d.addCallback(check) - return d - - def testStringCommand(self): - b = FakeSlaveBuilder(False, self.basedir) - # careful! This command must execute the same on windows and UNIX - s = runprocess.RunProcess(b, 'echo hello', self.basedir) - - d = s.start() - def check(ign): - self.failUnless({'stdout': nl('hello\n')} in b.updates, b.show()) - self.failUnless({'rc': 0} in b.updates, b.show()) - d.addCallback(check) - return d - - def testMultiWordStringCommand(self): - b = FakeSlaveBuilder(False, self.basedir) - # careful! This command must execute the same on windows and UNIX - s = runprocess.RunProcess(b, 'echo Happy Days and Jubilation', - self.basedir) - - # no quoting occurs - exp = nl('Happy Days and Jubilation\n') - d = s.start() - def check(ign): - self.failUnless({'stdout': exp} in b.updates, b.show()) - self.failUnless({'rc': 0} in b.updates, b.show()) - d.addCallback(check) - return d - - def testMultiWordStringCommandQuotes(self): - b = FakeSlaveBuilder(False, self.basedir) - # careful! This command must execute the same on windows and UNIX - s = runprocess.RunProcess(b, 'echo "Happy Days and Jubilation"', - self.basedir) - - if runtime.platformType == "win32": - # echo doesn't parse out the quotes, so they come through in the - # output - exp = nl('"Happy Days and Jubilation"\n') - else: - exp = nl('Happy Days and Jubilation\n') - d = s.start() - def check(ign): - self.failUnless({'stdout': exp} in b.updates, b.show()) - self.failUnless({'rc': 0} in b.updates, b.show()) - d.addCallback(check) - return d - - def testMultiWordCommand(self): - b = FakeSlaveBuilder(False, self.basedir) - # careful! This command must execute the same on windows and UNIX - s = runprocess.RunProcess(b, ['echo', 'Happy Days and Jubilation'], - self.basedir) - - if runtime.platformType == "win32": - # Twisted adds quotes to all arguments, and echo doesn't remove - # them, so they appear in the output. - exp = nl('"Happy Days and Jubilation"\n') - else: - exp = nl('Happy Days and Jubilation\n') - - d = s.start() - def check(ign): - self.failUnless({'stdout': exp} in b.updates, b.show()) - self.failUnless({'rc': 0} in b.updates, b.show()) - d.addCallback(check) - return d - - @compat.skipUnlessPlatformIs("win32") - def testPipeEmbedded(self): - b = FakeSlaveBuilder(False, self.basedir) - s = runprocess.RunProcess(b, ['echo', 'escaped|pipe'], - self.basedir) - - d = s.start() - def check(ign): - self.failUnless({'stdout': nl('escaped|pipe\n')} in b.updates, b.show()) - self.failUnless({'rc': 0} in b.updates, b.show()) - d.addCallback(check) - return d - - @compat.skipUnlessPlatformIs("win32") - def testPipeAlone(self): - b = FakeSlaveBuilder(False, self.basedir) - #this is highly contrived, but it proves the point. - cmd = stdoutCommand("b\\na") - cmd[0] = cmd[0].replace(".exe","") - cmd.extend(['|','sort']) - s = runprocess.RunProcess(b, cmd, self.basedir) - - d = s.start() - def check(ign): - self.failUnless({'stdout': nl('a\nb\n')} in b.updates, b.show()) - self.failUnless({'rc': 0} in b.updates, b.show()) - d.addCallback(check) - return d - - @compat.skipUnlessPlatformIs("win32") - def testPipeString(self): - b = FakeSlaveBuilder(False, self.basedir) - #this is highly contrived, but it proves the point. - cmd = sys.executable + ' -c "import sys; sys.stdout.write(\'b\\na\\n\')" | sort' - s = runprocess.RunProcess(b, cmd, self.basedir) - - d = s.start() - def check(ign): - self.failUnless({'stdout': nl('a\nb\n')} in b.updates, b.show()) - self.failUnless({'rc': 0} in b.updates, b.show()) - d.addCallback(check) - return d - - def testCommandTimeout(self): - b = FakeSlaveBuilder(False, self.basedir) - s = runprocess.RunProcess(b, sleepCommand(10), self.basedir, timeout=5) - clock = task.Clock() - s._reactor = clock - d = s.start() - def check(ign): - self.failUnless({'stdout': nl('hello\n')} not in b.updates, b.show()) - self.failUnless({'rc': FATAL_RC} in b.updates, b.show()) - d.addCallback(check) - clock.advance(6) - return d - - def testCommandMaxTime(self): - b = FakeSlaveBuilder(False, self.basedir) - s = runprocess.RunProcess(b, sleepCommand(10), self.basedir, maxTime=5) - clock = task.Clock() - s._reactor = clock - d = s.start() - def check(ign): - self.failUnless({'stdout': nl('hello\n')} not in b.updates, b.show()) - self.failUnless({'rc': FATAL_RC} in b.updates, b.show()) - d.addCallback(check) - clock.advance(6) # should knock out maxTime - return d - - @compat.skipUnlessPlatformIs("posix") - def test_stdin_closed(self): - b = FakeSlaveBuilder(False, self.basedir) - s = runprocess.RunProcess(b, - scriptCommand('assert_stdin_closed'), - self.basedir, - usePTY=False, # if usePTY=True, stdin is never closed - logEnviron=False) - d = s.start() - def check(ign): - self.failUnless({'rc': 0} in b.updates, b.show()) - d.addCallback(check) - return d - - @compat.usesFlushLoggedErrors - def test_startCommand_exception(self): - b = FakeSlaveBuilder(False, self.basedir) - s = runprocess.RunProcess(b, ['whatever'], self.basedir) - - # set up to cause an exception in _startCommand - def _startCommand(*args, **kwargs): - raise RuntimeError() - s._startCommand = _startCommand - - d = s.start() - def check(err): - err.trap(AbandonChain) - stderr = [] - # Here we're checking that the exception starting up the command - # actually gets propogated back to the master in stderr. - for u in b.updates: - if 'stderr' in u: - stderr.append(u['stderr']) - stderr = "".join(stderr) - self.failUnless("RuntimeError" in stderr, stderr) - d.addBoth(check) - d.addBoth(lambda _ : self.flushLoggedErrors()) - return d - - def testLogEnviron(self): - b = FakeSlaveBuilder(False, self.basedir) - s = runprocess.RunProcess(b, stdoutCommand('hello'), self.basedir, - environ={"FOO": "BAR"}) - - d = s.start() - def check(ign): - headers = "".join([update.values()[0] for update in b.updates if update.keys() == ["header"] ]) - self.failUnless("FOO=BAR" in headers, "got:\n" + headers) - d.addCallback(check) - return d - - def testNoLogEnviron(self): - b = FakeSlaveBuilder(False, self.basedir) - s = runprocess.RunProcess(b, stdoutCommand('hello'), self.basedir, - environ={"FOO": "BAR"}, logEnviron=False) - - d = s.start() - def check(ign): - headers = "".join([update.values()[0] for update in b.updates if update.keys() == ["header"] ]) - self.failUnless("FOO=BAR" not in headers, "got:\n" + headers) - d.addCallback(check) - return d - - def testEnvironExpandVar(self): - b = FakeSlaveBuilder(False, self.basedir) - environ = {"EXPND": "-${PATH}-", - "DOESNT_EXPAND": "-${---}-", - "DOESNT_FIND": "-${DOESNT_EXISTS}-"} - s = runprocess.RunProcess(b, stdoutCommand('hello'), self.basedir, environ=environ) - - d = s.start() - def check(ign): - headers = "".join([update.values()[0] for update in b.updates if update.keys() == ["header"] ]) - self.failUnless("EXPND=-$" not in headers, "got:\n" + headers) - self.failUnless("DOESNT_FIND=--" in headers, "got:\n" + headers) - self.failUnless("DOESNT_EXPAND=-${---}-" in headers, "got:\n" + headers) - d.addCallback(check) - return d - - def testUnsetEnvironVar(self): - b = FakeSlaveBuilder(False, self.basedir) - s = runprocess.RunProcess(b, stdoutCommand('hello'), self.basedir, - environ={"PATH":None}) - - d = s.start() - def check(ign): - headers = "".join([update.values()[0] for update in b.updates if update.keys() == ["header"] ]) - self.failUnless(not re.match('\bPATH=',headers), "got:\n" + headers) - d.addCallback(check) - return d - - def testEnvironPythonPath(self): - b = FakeSlaveBuilder(False, self.basedir) - s = runprocess.RunProcess(b, stdoutCommand('hello'), self.basedir, - environ={"PYTHONPATH":'a'}) - - d = s.start() - def check(ign): - headers = "".join([update.values()[0] for update in b.updates if update.keys() == ["header"] ]) - self.failUnless(not re.match('\bPYTHONPATH=a%s' % (os.pathsep),headers), - "got:\n" + headers) - d.addCallback(check) - return d - - def testEnvironArray(self): - b = FakeSlaveBuilder(False, self.basedir) - s = runprocess.RunProcess(b, stdoutCommand('hello'), self.basedir, - environ={"FOO":['a', 'b']}) - - d = s.start() - def check(ign): - headers = "".join([update.values()[0] for update in b.updates if update.keys() == ["header"] ]) - self.failUnless(not re.match('\bFOO=a%sb\b' % (os.pathsep),headers), - "got:\n" + headers) - d.addCallback(check) - return d - - def testEnvironInt(self): - b = FakeSlaveBuilder(False, self.basedir) - self.assertRaises(RuntimeError, lambda : - runprocess.RunProcess(b, stdoutCommand('hello'), self.basedir, - environ={"BUILD_NUMBER":13})) - - -class TestPOSIXKilling(BasedirMixin, unittest.TestCase): - - if runtime.platformType != "posix": - skip = "not a POSIX platform" - - def setUp(self): - self.pidfiles = [] - self.setUpBasedir() - - def tearDown(self): - # make sure all of the subprocesses are dead - for pidfile in self.pidfiles: - if not os.path.exists(pidfile): continue - pid = open(pidfile).read() - if not pid: return - pid = int(pid) - try: os.kill(pid, signal.SIGKILL) - except OSError: pass - - # and clean up leftover pidfiles - for pidfile in self.pidfiles: - if os.path.exists(pidfile): - os.unlink(pidfile) - - self.tearDownBasedir() - - def newPidfile(self): - pidfile = os.path.abspath("test-%d.pid" % len(self.pidfiles)) - if os.path.exists(pidfile): - os.unlink(pidfile) - self.pidfiles.append(pidfile) - return pidfile - - def waitForPidfile(self, pidfile): - # wait for a pidfile, and return the pid via a Deferred - until = time.time() + 10 - d = defer.Deferred() - def poll(): - if reactor.seconds() > until: - d.errback(RuntimeError("pidfile %s never appeared" % pidfile)) - return - if os.path.exists(pidfile): - try: - pid = int(open(pidfile).read()) - except: - pid = None - - if pid is not None: - d.callback(pid) - return - reactor.callLater(0.01, poll) - poll() # poll right away - return d - - def assertAlive(self, pid): - try: - os.kill(pid, 0) - except OSError: - self.fail("pid %d still alive" % (pid,)) - - def assertDead(self, pid, timeout=5): - log.msg("checking pid %r" % (pid,)) - def check(): - try: - os.kill(pid, 0) - except OSError: - return True # dead - return False # alive - - # check immediately - if check(): return - - # poll every 100'th of a second; this allows us to test for - # processes that have been killed, but where the signal hasn't - # been delivered yet - until = time.time() + timeout - while time.time() < until: - time.sleep(0.01) - if check(): - return - self.fail("pid %d still alive after %ds" % (pid, timeout)) - - # tests - - def test_simple_interruptSignal(self): - return self.test_simple('TERM') - - def test_simple(self, interruptSignal=None): - - # test a simple process that just sleeps waiting to die - pidfile = self.newPidfile() - self.pid = None - - b = FakeSlaveBuilder(False, self.basedir) - s = runprocess.RunProcess(b, - scriptCommand('write_pidfile_and_sleep', pidfile), - self.basedir) - if interruptSignal is not None: - s.interruptSignal = interruptSignal - runproc_d = s.start() - - pidfile_d = self.waitForPidfile(pidfile) - - def check_alive(pid): - self.pid = pid # for use in check_dead - # test that the process is still alive - self.assertAlive(pid) - # and tell the RunProcess object to kill it - s.kill("diaf") - pidfile_d.addCallback(check_alive) - - def check_dead(_): - self.assertDead(self.pid) - runproc_d.addCallback(check_dead) - return defer.gatherResults([pidfile_d, runproc_d]) - - def test_pgroup_usePTY(self): - return self.do_test_pgroup(usePTY=True) - - def test_pgroup_no_usePTY(self): - return self.do_test_pgroup(usePTY=False) - - def test_pgroup_no_usePTY_no_pgroup(self): - # note that this configuration is not *used*, but that it is - # still supported, and correctly fails to kill the child process - return self.do_test_pgroup(usePTY=False, useProcGroup=False, - expectChildSurvival=True) - - def do_test_pgroup(self, usePTY, useProcGroup=True, - expectChildSurvival=False): - # test that a process group gets killed - parent_pidfile = self.newPidfile() - self.parent_pid = None - child_pidfile = self.newPidfile() - self.child_pid = None - - b = FakeSlaveBuilder(False, self.basedir) - s = runprocess.RunProcess(b, - scriptCommand('spawn_child', parent_pidfile, child_pidfile), - self.basedir, - usePTY=usePTY, - useProcGroup=useProcGroup) - runproc_d = s.start() - - # wait for both processes to start up, then call s.kill - parent_pidfile_d = self.waitForPidfile(parent_pidfile) - child_pidfile_d = self.waitForPidfile(child_pidfile) - pidfiles_d = defer.gatherResults([parent_pidfile_d, child_pidfile_d]) - def got_pids(pids): - self.parent_pid, self.child_pid = pids - pidfiles_d.addCallback(got_pids) - def kill(_): - s.kill("diaf") - pidfiles_d.addCallback(kill) - - # check that both processes are dead after RunProcess is done - d = defer.gatherResults([pidfiles_d, runproc_d]) - def check_dead(_): - self.assertDead(self.parent_pid) - if expectChildSurvival: - self.assertAlive(self.child_pid) - else: - self.assertDead(self.child_pid) - d.addCallback(check_dead) - return d - - def test_double_fork_usePTY(self): - return self.do_test_double_fork(usePTY=True) - - def test_double_fork_no_usePTY(self): - return self.do_test_double_fork(usePTY=False) - - def test_double_fork_no_usePTY_no_pgroup(self): - # note that this configuration is not *used*, but that it is - # still supported, and correctly fails to kill the child process - return self.do_test_double_fork(usePTY=False, useProcGroup=False, - expectChildSurvival=True) - - def do_test_double_fork(self, usePTY, useProcGroup=True, - expectChildSurvival=False): - # when a spawned process spawns another process, and then dies itself - # (either intentionally or accidentally), we should be able to clean up - # the child. - parent_pidfile = self.newPidfile() - self.parent_pid = None - child_pidfile = self.newPidfile() - self.child_pid = None - - b = FakeSlaveBuilder(False, self.basedir) - s = runprocess.RunProcess(b, - scriptCommand('double_fork', parent_pidfile, child_pidfile), - self.basedir, - usePTY=usePTY, - useProcGroup=useProcGroup) - runproc_d = s.start() - - # wait for both processes to start up, then call s.kill - parent_pidfile_d = self.waitForPidfile(parent_pidfile) - child_pidfile_d = self.waitForPidfile(child_pidfile) - pidfiles_d = defer.gatherResults([parent_pidfile_d, child_pidfile_d]) - def got_pids(pids): - self.parent_pid, self.child_pid = pids - pidfiles_d.addCallback(got_pids) - def kill(_): - s.kill("diaf") - pidfiles_d.addCallback(kill) - - # check that both processes are dead after RunProcess is done - d = defer.gatherResults([pidfiles_d, runproc_d]) - def check_dead(_): - self.assertDead(self.parent_pid) - if expectChildSurvival: - self.assertAlive(self.child_pid) - else: - self.assertDead(self.child_pid) - d.addCallback(check_dead) - return d - -class TestLogging(BasedirMixin, unittest.TestCase): - def setUp(self): - self.setUpBasedir() - - def tearDown(self): - self.tearDownBasedir() - - def testSendStatus(self): - b = FakeSlaveBuilder(False, self.basedir) - s = runprocess.RunProcess(b, stdoutCommand('hello'), self.basedir) - s.sendStatus({'stdout': nl('hello\n')}) - self.failUnlessEqual(b.updates, [{'stdout': nl('hello\n')}], b.show()) - - def testSendBuffered(self): - b = FakeSlaveBuilder(False, self.basedir) - s = runprocess.RunProcess(b, stdoutCommand('hello'), self.basedir) - s._addToBuffers('stdout', 'hello ') - s._addToBuffers('stdout', 'world') - s._sendBuffers() - self.failUnlessEqual(b.updates, [{'stdout': 'hello world'}], b.show()) - - def testSendBufferedInterleaved(self): - b = FakeSlaveBuilder(False, self.basedir) - s = runprocess.RunProcess(b, stdoutCommand('hello'), self.basedir) - s._addToBuffers('stdout', 'hello ') - s._addToBuffers('stderr', 'DIEEEEEEE') - s._addToBuffers('stdout', 'world') - s._sendBuffers() - self.failUnlessEqual(b.updates, [ - {'stdout': 'hello '}, - {'stderr': 'DIEEEEEEE'}, - {'stdout': 'world'}, - ]) - - def testSendChunked(self): - b = FakeSlaveBuilder(False, self.basedir) - s = runprocess.RunProcess(b, stdoutCommand('hello'), self.basedir) - data = "x" * (runprocess.RunProcess.CHUNK_LIMIT * 3 / 2) - s._addToBuffers('stdout', data) - s._sendBuffers() - self.failUnlessEqual(len(b.updates), 2) - - def testSendNotimeout(self): - b = FakeSlaveBuilder(False, self.basedir) - s = runprocess.RunProcess(b, stdoutCommand('hello'), self.basedir) - data = "x" * (runprocess.RunProcess.BUFFER_SIZE + 1) - s._addToBuffers('stdout', data) - self.failUnlessEqual(len(b.updates), 1) - -class TestLogFileWatcher(BasedirMixin, unittest.TestCase): - def setUp(self): - self.setUpBasedir() - - def tearDown(self): - self.tearDownBasedir() - - def makeRP(self): - b = FakeSlaveBuilder(False, self.basedir) - rp = runprocess.RunProcess(b, stdoutCommand('hello'), self.basedir) - return rp - - def test_statFile_missing(self): - rp = self.makeRP() - if os.path.exists('statfile.log'): - os.remove('statfile.log') - lf = runprocess.LogFileWatcher(rp, 'test', 'statfile.log', False) - self.assertFalse(lf.statFile(), "statfile.log doesn't exist") - - def test_statFile_exists(self): - rp = self.makeRP() - open('statfile.log', 'w').write('hi') - lf = runprocess.LogFileWatcher(rp, 'test', 'statfile.log', False) - st = lf.statFile() - self.assertEqual(st and st[2], 2, "statfile.log exists and size is correct") - os.remove('statfile.log') diff --git a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_scripts_base.py b/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_scripts_base.py deleted file mode 100644 index 68daff20..00000000 --- a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_scripts_base.py +++ /dev/null @@ -1,93 +0,0 @@ -# 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 - -import sys -import cStringIO -from twisted.trial import unittest -from buildslave.scripts import base -from buildslave.test.util import misc - -class TestIsBuildslaveDir(misc.OpenFileMixin, unittest.TestCase): - """Test buildslave.scripts.base.isBuildslaveDir()""" - - def setUp(self): - # capture output to stdout - self.mocked_stdout = cStringIO.StringIO() - self.patch(sys, "stdout", self.mocked_stdout) - - def assertReadErrorMessage(self, strerror): - self.assertEqual(self.mocked_stdout.getvalue(), - "error reading 'testdir/buildbot.tac': %s\n" - "invalid buildslave directory 'testdir'\n" % strerror, - "unexpected error message on stdout") - - def test_open_error(self): - """Test that open() errors are handled.""" - - # patch open() to raise IOError - self.setUpOpenError(1, "open-error", "dummy") - - # check that isBuildslaveDir() flags directory as invalid - self.assertFalse(base.isBuildslaveDir("testdir")) - - # check that correct error message was printed to stdout - self.assertReadErrorMessage("open-error") - - # check that open() was called with correct path - self.open.assert_called_once_with("testdir/buildbot.tac") - - def test_read_error(self): - """Test that read() errors on buildbot.tac file are handled.""" - - # patch open() to return file object that raises IOError on read() - self.setUpReadError(1, "read-error", "dummy") - - # check that isBuildslaveDir() flags directory as invalid - self.assertFalse(base.isBuildslaveDir("testdir")) - - # check that correct error message was printed to stdout - self.assertReadErrorMessage("read-error") - - # check that open() was called with correct path - self.open.assert_called_once_with("testdir/buildbot.tac") - - def test_unexpected_tac_contents(self): - """Test that unexpected contents in buildbot.tac is handled.""" - - # patch open() to return file with unexpected contents - self.setUpOpen("dummy-contents") - - # check that isBuildslaveDir() flags directory as invalid - self.assertFalse(base.isBuildslaveDir("testdir")) - - # check that correct error message was printed to stdout - self.assertEqual(self.mocked_stdout.getvalue(), - "unexpected content in 'testdir/buildbot.tac'\n" - "invalid buildslave directory 'testdir'\n", - "unexpected error message on stdout") - # check that open() was called with correct path - self.open.assert_called_once_with("testdir/buildbot.tac") - - def test_slavedir_good(self): - """Test checking valid buildslave directory.""" - - # patch open() to return file with valid buildslave tac contents - self.setUpOpen("Application('buildslave')") - - # check that isBuildslaveDir() flags directory as good - self.assertTrue(base.isBuildslaveDir("testdir")) - - # check that open() was called with correct path - self.open.assert_called_once_with("testdir/buildbot.tac") diff --git a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_scripts_runner.py b/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_scripts_runner.py deleted file mode 100644 index 5656d97c..00000000 --- a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_scripts_runner.py +++ /dev/null @@ -1,306 +0,0 @@ -# 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 - -import os -import time -import mock -import errno -import signal -from twisted.trial import unittest -from twisted.python import usage -from buildslave.scripts import runner, base -from buildslave.scripts import startup -from buildslave.test.util import misc - - -class IsBuildslaveDirMixin: - """ - Mixin for setting up mocked base.isBuildslaveDir() function - """ - def setupUpIsBuildslaveDir(self, return_value): - self.isBuildslaveDir = mock.Mock(return_value=return_value) - self.patch(base, "isBuildslaveDir", self.isBuildslaveDir) - - -class TestStopSlave(misc.OpenFileMixin, - misc.StdoutAssertionsMixin, - unittest.TestCase): - """ - Test buildslave.scripts.runner.stopSlave() - """ - PID = 9876 - def setUp(self): - self.setUpStdoutAssertions() - - # patch os.chdir() to do nothing - self.patch(os, "chdir", mock.Mock()) - - def test_no_pid_file(self): - """ - test calling stopSlave() when no pid file is present - """ - - # patch open() to raise 'file not found' exception - self.setUpOpenError(2) - - # check that stop() raises SlaveNotRunning exception - self.assertRaises(runner.SlaveNotRunning, - runner.stopSlave, None, False) - - def test_successful_stop(self): - """ - test stopSlave() on a successful slave stop - """ - - def emulated_kill(pid, sig): - if sig == 0: - # when probed if a signal can be send to the process - # emulate that it is dead with 'No such process' error - raise OSError(errno.ESRCH, "dummy") - - # patch open() to return a pid file - self.setUpOpen(str(self.PID)) - - # patch os.kill to emulate successful kill - mocked_kill = mock.Mock(side_effect=emulated_kill) - self.patch(os, "kill", mocked_kill) - - # don't waste time - self.patch(time, "sleep", mock.Mock()) - - # check that stopSlave() sends expected signal to right PID - # and print correct message to stdout - runner.stopSlave(None, False) - mocked_kill.assert_has_calls([mock.call(self.PID, signal.SIGTERM), - mock.call(self.PID, 0)]) - self.assertStdoutEqual("buildslave process %s is dead\n" % self.PID) - - -class TestStop(IsBuildslaveDirMixin, - misc.StdoutAssertionsMixin, - unittest.TestCase): - """ - Test buildslave.scripts.runner.stop() - """ - config = {"basedir": "dummy", "quiet": False} - - def setUp(self): - # patch basedir check to always succeed - self.setupUpIsBuildslaveDir(True) - - def test_no_slave_running(self): - """ - test calling stop() when no slave is running - """ - self.setUpStdoutAssertions() - - # patch stopSlave() to raise an exception - mock_stopSlave = mock.Mock(side_effect=runner.SlaveNotRunning()) - self.patch(runner, "stopSlave", mock_stopSlave) - - runner.stop(self.config) - self.assertStdoutEqual("buildslave not running\n") - - def test_successful_stop(self): - """ - test calling stop() when slave is running - """ - # patch stopSlave() to do nothing - mock_stopSlave = mock.Mock() - self.patch(runner, "stopSlave", mock_stopSlave) - - runner.stop(self.config) - mock_stopSlave.assert_called_once_with(self.config["basedir"], - self.config["quiet"], - "TERM") - - -class TestRestart(IsBuildslaveDirMixin, - misc.StdoutAssertionsMixin, - unittest.TestCase): - """ - Test buildslave.scripts.runner.restart() - """ - config = {"basedir": "dummy", "quiet": False} - - def setUp(self): - self.setUpStdoutAssertions() - - # patch basedir check to always succeed - self.setupUpIsBuildslaveDir(True) - - # patch startup.start() to do nothing - self.start = mock.Mock() - self.patch(startup, "start", self.start) - - def test_no_slave_running(self): - """ - test calling restart() when no slave is running - """ - # patch stopSlave() to raise an exception - mock_stopSlave = mock.Mock(side_effect=runner.SlaveNotRunning()) - self.patch(runner, "stopSlave", mock_stopSlave) - - # check that restart() calls start() and prints correct messages - runner.restart(self.config) - self.start.assert_called_once_with(self.config) - self.assertStdoutEqual("no old buildslave process found to stop\n" - "now restarting buildslave process..\n") - - - def test_restart(self): - """ - test calling restart() when slave is running - """ - # patch stopSlave() to do nothing - mock_stopSlave = mock.Mock() - self.patch(runner, "stopSlave", mock_stopSlave) - - # check that restart() calls start() and prints correct messages - runner.restart(self.config) - self.assertStdoutEqual("now restarting buildslave process..\n") - self.start.assert_called_once_with(self.config) - - -class TestUpgradeSlave(IsBuildslaveDirMixin, unittest.TestCase): - """ - Test buildslave.scripts.runner.upgradeSlave() - """ - - def test_upgradeSlave_bad_basedir(self): - """ - test calling upgradeSlave() with bad base directory - """ - # override isBuildslaveDir() to always fail - self.setupUpIsBuildslaveDir(False) - - # call upgradeSlave() and check that SystemExit exception is raised - config = {"basedir" : "dummy"} - exception = self.assertRaises(SystemExit, runner.upgradeSlave, config) - - # check exit code - self.assertEqual(exception.code, 1, "unexpected exit code") - - # check that isBuildslaveDir was called with correct argument - self.isBuildslaveDir.assert_called_once_with("dummy") - - -class OptionsMixin(object): - def assertOptions(self, opts, exp): - got = dict([(k, opts[k]) for k in exp]) - if got != exp: - msg = [] - for k in exp: - if opts[k] != exp[k]: - msg.append(" %s: expected %r, got %r" % - (k, exp[k], opts[k])) - self.fail("did not get expected options\n" + ("\n".join(msg))) - - -class TestCreateSlaveOptions(OptionsMixin, unittest.TestCase): - """ - Test buildslave.scripts.runner.CreateSlaveOptions class. - """ - - req_args = ["bdir", "mstr", "name", "pswd"] - - def parse(self, *args): - opts = runner.CreateSlaveOptions() - opts.parseOptions(args) - return opts - - def test_defaults(self): - self.assertRaisesRegexp(usage.UsageError, - "incorrect number of arguments", - self.parse) - - def test_synopsis(self): - opts = runner.CreateSlaveOptions() - self.assertIn('buildslave create-slave', opts.getSynopsis()) - - def test_min_args(self): - - # patch runner.MakerBase.postOptions() so that 'basedir' - # argument will not be converted to absolute path - self.patch(runner.MakerBase, "postOptions", mock.Mock()) - - self.assertOptions(self.parse(*self.req_args), - dict(basedir="bdir", master="mstr", - name="name", passwd="pswd")) - - def test_all_args(self): - - # patch runner.MakerBase.postOptions() so that 'basedir' - # argument will not be converted to absolute path - self.patch(runner.MakerBase, "postOptions", mock.Mock()) - - opts = self.parse("--force", "--relocatable", "--no-logrotate", - "--keepalive=4", "--usepty=0", "--umask=022", - "--maxdelay=3", "--log-size=2", "--log-count=1", - "--allow-shutdown=file", *self.req_args) - self.assertOptions(opts, - {"force" : True, - "relocatable" : True, - "no-logrotate" : True, - "usepty" : 0, - "umask" : "022", - "maxdelay" : 3, - "log-size" : 2, - "log-count" : "1", - "allow-shutdown" : "file", - "basedir" : "bdir", - "master" : "mstr", - "name" : "name", - "passwd" : "pswd"}) - - def test_master_url(self): - self.assertRaisesRegexp(usage.UsageError, - "<master> is not a URL - do not use URL", - self.parse, "a", "http://b.c", "d", "e") - - def test_inv_keepalive(self): - self.assertRaisesRegexp(usage.UsageError, - "keepalive parameter needs to be an number", - self.parse, "--keepalive=X", *self.req_args) - - def test_inv_usepty(self): - self.assertRaisesRegexp(usage.UsageError, - "usepty parameter needs to be an number", - self.parse, "--usepty=X", *self.req_args) - - def test_inv_maxdelay(self): - self.assertRaisesRegexp(usage.UsageError, - "maxdelay parameter needs to be an number", - self.parse, "--maxdelay=X", *self.req_args) - - def test_inv_log_size(self): - self.assertRaisesRegexp(usage.UsageError, - "log-size parameter needs to be an number", - self.parse, "--log-size=X", *self.req_args) - - def test_inv_log_count(self): - self.assertRaisesRegexp(usage.UsageError, - "log-count parameter needs to be an number or None", - self.parse, "--log-count=X", *self.req_args) - - def test_too_few_args(self): - self.assertRaisesRegexp(usage.UsageError, - "incorrect number of arguments", - self.parse, "arg1", "arg2") - - def test_too_many_args(self): - self.assertRaisesRegexp(usage.UsageError, - "incorrect number of arguments", - self.parse, "extra_arg", *self.req_args) diff --git a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_util.py b/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_util.py deleted file mode 100644 index 738e6e45..00000000 --- a/lib/python2.7/site-packages/buildbot_slave-0.8.8-py2.7.egg/buildslave/test/unit/test_util.py +++ /dev/null @@ -1,71 +0,0 @@ -# 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 twisted.trial import unittest - -from buildslave import util - -class remove_userpassword(unittest.TestCase): - - def assertUrl(self, real_url, expected_url): - new_url = util.remove_userpassword(real_url) - self.assertEqual(expected_url, new_url) - - def test_url_with_no_user_and_password(self): - self.assertUrl('http://myurl.com/myrepo', 'http://myurl.com/myrepo') - - def test_url_with_user_and_password(self): - self.assertUrl('http://myuser:mypass@myurl.com/myrepo', 'http://myurl.com/myrepo') - - def test_another_url_with_no_user_and_password(self): - self.assertUrl('http://myurl2.com/myrepo2', 'http://myurl2.com/myrepo2') - - def test_another_url_with_user_and_password(self): - self.assertUrl('http://myuser2:mypass2@myurl2.com/myrepo2', 'http://myurl2.com/myrepo2') - - def test_with_different_protocol_without_user_and_password(self): - self.assertUrl('ssh://myurl3.com/myrepo3', 'ssh://myurl3.com/myrepo3') - - def test_with_different_protocol_with_user_and_password(self): - self.assertUrl('ssh://myuser3:mypass3@myurl3.com/myrepo3', 'ssh://myurl3.com/myrepo3') - - def test_file_path(self): - self.assertUrl('/home/me/repos/my-repo', '/home/me/repos/my-repo') - - def test_win32file_path(self): - self.assertUrl('c:\\repos\\my-repo', 'c:\\repos\\my-repo') - -class TestObfuscated(unittest.TestCase): - def testSimple(self): - c = util.Obfuscated('real', '****') - self.failUnlessEqual(str(c), '****') - self.failUnlessEqual(repr(c), "'****'") - - def testObfuscatedCommand(self): - cmd = ['echo', util.Obfuscated('password', '*******')] - - self.failUnlessEqual(['echo', 'password'], util.Obfuscated.get_real(cmd)) - self.failUnlessEqual(['echo', '*******'], util.Obfuscated.get_fake(cmd)) - - def testObfuscatedNonString(self): - cmd = ['echo', 1] - self.failUnlessEqual(['echo', '1'], util.Obfuscated.get_real(cmd)) - self.failUnlessEqual(['echo', '1'], util.Obfuscated.get_fake(cmd)) - - def testObfuscatedNonList(self): - cmd = 1 - self.failUnlessEqual(1, util.Obfuscated.get_real(cmd)) - self.failUnlessEqual(1, util.Obfuscated.get_fake(cmd)) - |