Skip to content

Commit

Permalink
patch some SourceBase methods to make tests more platform- and fs-ind…
Browse files Browse the repository at this point in the history
…ependent
  • Loading branch information
Dustin J. Mitchell committed Jun 10, 2010
1 parent e4683a6 commit a074a7e
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 36 deletions.
34 changes: 13 additions & 21 deletions slave/buildslave/test/unit/test_commands_svn.py
Expand Up @@ -4,10 +4,10 @@
from twisted.python import runtime

from buildslave.test.fake.runprocess import Expect
from buildslave.test.util.command import CommandTestMixin
from buildslave.test.util.sourcecommand import SourceCommandTestMixin
from buildslave.commands import svn

class TestSVN(CommandTestMixin, unittest.TestCase):
class TestSVN(SourceCommandTestMixin, unittest.TestCase):

def setUp(self):
self.setUpCommand()
Expand All @@ -24,23 +24,16 @@ def test_simple(self):
mode='copy',
revision=None,
svnurl='http://svn.local/app/trunk',
), patch_sourcedata_fns=True)
))

exp_environ = dict(PWD='.', LC_MESSAGES='C')
expects = []
# SourceBaseCommand won't use rm -rf on windows..
if runtime.platformType == 'posix':
expects.extend([
Expect([ 'rm', '-rf', self.basedir_workdir ],
self.basedir,
sendRC=0, timeout=120, usePTY=False)
+ 0,
Expect([ 'rm', '-rf', os.path.join(self.basedir, 'source') ],
self.basedir,
sendRC=0, timeout=120, usePTY=False)
+ 0,
])
expects.extend([
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', 'source' ],
self.basedir,
Expand All @@ -54,11 +47,10 @@ def test_simple(self):
sendStderr=False, sendStdout=False)
+ { 'stdout' : '9753\n' }
+ 0,
Expect([ 'cp', '-R', '-P', '-p', 'basedir/source', 'basedir/workdir' ],
self.basedir,
sendRC=False, timeout=120, usePTY=False)
Expect([ 'copy', 'source', 'workdir'],
self.basedir)
+ 0,
])
]
self.patch_runprocess(*expects)

d = self.run_command()
Expand Down
16 changes: 1 addition & 15 deletions slave/buildslave/test/util/command.py
Expand Up @@ -36,7 +36,7 @@ def tearDownCommand(self):
if hasattr(self, 'runprocess_patched') and self.runprocess_patched:
runprocess.FakeRunProcess.test_done()

def make_command(self, cmdclass, args, makedirs=False, patch_sourcedata_fns=False):
def make_command(self, cmdclass, args, makedirs=False):
"""
Create a new command object, creating the necessary arguments. The
cmdclass argument is the Command class, and args is the args dict
Expand All @@ -51,10 +51,6 @@ def make_command(self, cmdclass, args, makedirs=False, patch_sourcedata_fns=Fals
self.cmd -- the command
self.builder -- the (fake) SlaveBuilder
If patch_sourcedata_fns is true, then the resulting command's
writeSourceata and readSourcedata methods are patched to write and read
self.sourcedata instead.
"""

# set up the workdir and basedir
Expand All @@ -69,16 +65,6 @@ def make_command(self, cmdclass, args, makedirs=False, patch_sourcedata_fns=Fals
b = self.builder = slavebuilder.FakeSlaveBuilder(basedir=self.basedir)
self.cmd = cmdclass(b, 'fake-stepid', args)

if patch_sourcedata_fns:
self.sourcedata = ''
def readSourcedata():
return self.sourcedata
self.patch(self.cmd, 'readSourcedata', readSourcedata)
def writeSourcedata(res):
self.sourcedata = self.cmd.sourcedata
return res
self.patch(self.cmd, 'writeSourcedata', writeSourcedata)

return self.cmd

def run_command(self):
Expand Down
54 changes: 54 additions & 0 deletions slave/buildslave/test/util/sourcecommand.py
@@ -0,0 +1,54 @@
from buildslave import runprocess
from buildslave.test.util import command

class SourceCommandTestMixin(command.CommandTestMixin):
"""
Support for testing Source Commands; an extension of CommandTestMixin
"""

def make_command(self, cmdclass, args, makedirs=False):
"""
Same as the parent class method, but this also adds some source-specific
patches:
* writeSourcedata - writes to self.sourcedata (self is the TestCase)
* readSourcedata - reads from self.sourcedata
* doClobber - invokes RunProcess(['clobber', DIRECTORY])
* doCopy - invokes RunProcess(['copy', cmd.srcdir, cmd.workdir])
"""

cmd = command.CommandTestMixin.make_command(self, cmdclass, args, makedirs)

# note that these patches are to an *instance*, not a class, so there
# is no need to use self.patch() to reverse them

self.sourcedata = ''
def readSourcedata():
return self.sourcedata
cmd.readSourcedata = readSourcedata

def writeSourcedata(res):
self.sourcedata = cmd.sourcedata
return res
cmd.writeSourcedata = writeSourcedata

def doClobber(_, dirname):
r = runprocess.RunProcess(self.builder,
[ 'clobber', dirname ],
self.builder.basedir)
return r.start()
cmd.doClobber = doClobber

def doClobber(_, dirname):
r = runprocess.RunProcess(self.builder,
[ 'clobber', dirname ],
self.builder.basedir)
return r.start()
cmd.doClobber = doClobber

def doCopy(_):
r = runprocess.RunProcess(self.builder,
[ 'copy', cmd.srcdir, cmd.workdir ],
self.builder.basedir)
return r.start()
cmd.doCopy = doCopy

0 comments on commit a074a7e

Please sign in to comment.