Skip to content

Commit

Permalink
add tests for Arch and Bazaar, and fix minor bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Dustin J. Mitchell committed Jun 11, 2010
1 parent c278ee4 commit a6b5308
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 6 deletions.
17 changes: 11 additions & 6 deletions slave/buildslave/commands/arch.py
@@ -1,8 +1,9 @@
import os
import re

from twisted.python import log

from buildslave.commands.base import SourceBaseCommand
from buildslave.commands.base import SourceBaseCommand, AbandonChain
from buildslave import runprocess
from buildslave.commands import utils

Expand All @@ -21,9 +22,13 @@ class Arch(SourceBaseCommand):
header = "arch operation"
buildconfig = None

def setup(self, args):
def setup(self, args, no_getCommand=False):
SourceBaseCommand.setup(self, args)
self.vcexe = utils.getCommand("tla")

# avoid doing this if used via a subclass
if not no_getCommand:
self.vcexe = utils.getCommand("tla")

self.archive = args.get('archive')
self.url = args['url']
self.version = args['version']
Expand Down Expand Up @@ -124,7 +129,7 @@ def parseGotRevision(self):
command = [self.vcexe, "logs", "--full", "--reverse"]
c = runprocess.RunProcess(self.builder, command,
os.path.join(self.builder.basedir, self.srcdir),
environ=self.env,
environ=self.env, timeout=self.timeout,
sendStdout=False, sendStderr=False, sendRC=False,
keepStdout=True, usePTY=False)
d = c.start()
Expand All @@ -148,7 +153,7 @@ class Bazaar(Arch):
"""

def setup(self, args):
Arch.setup(self, args)
Arch.setup(self, args, no_getCommand=True)
self.vcexe = utils.getCommand("baz")
# baz doesn't emit the repository name after registration (and
# grepping through the output of 'baz archives' is too hard), so we
Expand Down Expand Up @@ -184,7 +189,7 @@ def parseGotRevision(self):
command = [self.vcexe, "tree-id"]
c = runprocess.RunProcess(self.builder, command,
os.path.join(self.builder.basedir, self.srcdir),
environ=self.env,
environ=self.env, timeout=self.timeout,
sendStdout=False, sendStderr=False, sendRC=False,
keepStdout=True, usePTY=False)
d = c.start()
Expand Down
120 changes: 120 additions & 0 deletions slave/buildslave/test/unit/test_commands_arch.py
@@ -0,0 +1,120 @@
import os

from twisted.trial import unittest
from twisted.python import runtime

from buildslave.test.fake.runprocess import Expect
from buildslave.test.util.sourcecommand import SourceCommandTestMixin
from buildslave.commands import arch

class TestArch(SourceCommandTestMixin, unittest.TestCase):

def setUp(self):
self.setUpCommand()

def tearDown(self):
self.tearDownCommand()

def test_simple(self):
self.patch_getCommand('tla', 'path/to/tla')
self.clean_environ()
self.make_command(arch.Arch, dict(
workdir='workdir',
mode='copy',
url='ftp://somewhere.com/pub/archive',
version='mainline',
revision='patch-22',
archive='funarchive',
))

exp_environ = dict(PWD='.', LC_MESSAGES='C')
expects = [
Expect([ 'clobber', 'workdir' ],
self.basedir)
+ 0,
Expect([ 'clobber', 'source' ],
self.basedir)
+ 0,
Expect(['path/to/tla', 'register-archive', '--force',
'ftp://somewhere.com/pub/archive'],
self.basedir,
sendRC=False, timeout=120, usePTY=False, keepStdout=True)
+ { 'stdout' : 'Registering archive: funarchive\n' }
+ 0,
Expect(['path/to/tla', 'get', '--archive', 'funarchive',
'--no-pristine', 'mainline--patch-22', 'source'],
self.basedir,
sendRC=False, usePTY=False, timeout=120)
+ { 'stdout' : '9753\n' }
+ 0,
Expect(['path/to/tla', 'logs', '--full', '--reverse'],
os.path.join(self.basedir, 'source'),
timeout=120, sendRC=False, usePTY=False, keepStdout=True,
sendStdout=False, sendStderr=False, environ=exp_environ)
+ { 'stdout' : 'funarchive/mainline--patch-22\n' }
+ 0,
Expect([ 'copy', 'source', 'workdir'],
self.basedir)
+ 0,
]
self.patch_runprocess(*expects)

d = self.run_command()
d.addCallback(self.check_sourcedata, "ftp://somewhere.com/pub/archive\nmainline\nNone\n")
return d

class TestBazaar(SourceCommandTestMixin, unittest.TestCase):

def setUp(self):
self.setUpCommand()

def tearDown(self):
self.tearDownCommand()

def test_simple(self):
self.patch_getCommand('baz', 'path/to/baz')
self.clean_environ()
self.make_command(arch.Bazaar, dict(
workdir='workdir',
mode='copy',
url='ftp://somewhere.com/pub/archive',
version='mainline',
revision='patch-22',
archive='funarchive',
))

exp_environ = dict(PWD='.', LC_MESSAGES='C')
expects = [
Expect([ 'clobber', 'workdir' ],
self.basedir)
+ 0,
Expect([ 'clobber', 'source' ],
self.basedir)
+ 0,
Expect(['path/to/baz', 'register-archive', '--force',
'ftp://somewhere.com/pub/archive'],
self.basedir,
sendRC=False, timeout=120, usePTY=False, keepStdout=True)
+ { 'stdout' : 'Registering archive: funarchive\n' }
+ 0,
Expect(['path/to/baz', 'get', '--no-pristine',
'funarchive/mainline--patch-22', 'source'],
self.basedir,
sendRC=False, usePTY=False, timeout=120)
+ { 'stdout' : '9753\n' }
+ 0,
Expect(['path/to/baz', 'tree-id'],
os.path.join(self.basedir, 'source'),
timeout=120, sendRC=False, usePTY=False, keepStdout=True,
sendStdout=False, sendStderr=False, environ=exp_environ)
+ { 'stdout' : 'funarchive/mainline--patch-22\n' }
+ 0,
Expect([ 'copy', 'source', 'workdir'],
self.basedir)
+ 0,
]
self.patch_runprocess(*expects)

d = self.run_command()
d.addCallback(self.check_sourcedata, "ftp://somewhere.com/pub/archive\nmainline\nNone\n")
return d

0 comments on commit a6b5308

Please sign in to comment.