Skip to content

Commit

Permalink
ensure that PYTHONPATH order does not change
Browse files Browse the repository at this point in the history
This also updates the tests to use ExpectShell.log, and adds some more
tests.
  • Loading branch information
djmitche committed Jul 26, 2011
1 parent 046b2db commit 7c97db1
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 21 deletions.
5 changes: 3 additions & 2 deletions master/buildbot/steps/python_twisted.py
Expand Up @@ -387,8 +387,9 @@ def setupEnvironment(self, cmd):
ppath = e.get('PYTHONPATH', self.testpath)
if isinstance(ppath, str):
ppath = [ppath]
pathset = set([self.testpath]) | set(ppath)
e['PYTHONPATH'] = list(pathset)
if self.testpath not in ppath:
ppath.insert(0, self.testpath)
e['PYTHONPATH'] = ppath

def start(self):
# now that self.build.allFiles() is nailed down, finish building the
Expand Down
79 changes: 60 additions & 19 deletions master/buildbot/test/unit/test_steps_python_twisted.py
Expand Up @@ -20,7 +20,7 @@
from buildbot.test.fake.remotecommand import ExpectShell


class TestTrialExeceution(steps.BuildStepMixin, unittest.TestCase):
class Trial(steps.BuildStepMixin, unittest.TestCase):

def setUp(self):
return self.setUpBuildStep()
Expand All @@ -29,23 +29,18 @@ def tearDown(self):
return self.tearDownBuildStep()

def test_run_env(self):
step = self.setupStep(
self.setupStep(
python_twisted.Trial(workdir='build',
tests = 'testname',
testpath = None,
env = {'PYTHONPATH': 'somepath'}))
def firstInWins(name):
if name not in self.step_status.logs:
self.step.backupAddLog(name)
return self.step_status.logs[name]
self.step.backupAddLog = self.step.addLog
self.step.addLog = firstInWins
self.step.addLog("stdio").addStdout("Ran 0 tests\n")
self.expectCommands(
ExpectShell(workdir='build', command=['trial', '--reporter=bwverbose', 'testname'],
ExpectShell(workdir='build',
command=['trial', '--reporter=bwverbose', 'testname'],
usePTY="slave-config",
logfiles={'test.log': '_trial_temp/test.log'},
env=dict(PYTHONPATH='somepath'))
+ ExpectShell.log('stdio', stdout="Ran 0 tests\n")
+ 0
)
self.expectOutcome(result=SUCCESS, status_text=['no tests', 'run'])
Expand All @@ -57,19 +52,65 @@ def test_run_env_supplement(self):
tests = 'testname',
testpath = 'path1',
env = {'PYTHONPATH': ['path2','path3']}))
def firstInWins(name):
if name not in self.step_status.logs:
self.step.backupAddLog(name)
return self.step_status.logs[name]
self.step.backupAddLog = self.step.addLog
self.step.addLog = firstInWins
self.step.addLog("stdio").addStdout("Ran 0 tests\n")
self.expectCommands(
ExpectShell(workdir='build', command=['trial', '--reporter=bwverbose', 'testname'],
ExpectShell(workdir='build',
command=['trial', '--reporter=bwverbose', 'testname'],
usePTY="slave-config",
logfiles={'test.log': '_trial_temp/test.log'},
env=dict(PYTHONPATH=['path1', 'path2', 'path3']))
+ ExpectShell.log('stdio', stdout="Ran 0 tests\n")
+ 0
)
self.expectOutcome(result=SUCCESS, status_text=['no tests', 'run'])
return self.runStep()

def test_run_env_nodupe(self):
self.setupStep(
python_twisted.Trial(workdir='build',
tests = 'testname',
testpath = 'path2',
env = {'PYTHONPATH': ['path1','path2']}))
self.expectCommands(
ExpectShell(workdir='build',
command=['trial', '--reporter=bwverbose', 'testname'],
usePTY="slave-config",
logfiles={'test.log': '_trial_temp/test.log'},
env=dict(PYTHONPATH=['path2','path3','path1']))
env=dict(PYTHONPATH=['path1','path2']))
+ ExpectShell.log('stdio', stdout="Ran 0 tests\n")
+ 0
)
self.expectOutcome(result=SUCCESS, status_text=['no tests', 'run'])
return self.runStep()

def test_run_singular(self):
self.setupStep(
python_twisted.Trial(workdir='build',
tests = 'testname',
testpath=None))
self.expectCommands(
ExpectShell(workdir='build',
command=['trial', '--reporter=bwverbose', 'testname'],
usePTY="slave-config",
logfiles={'test.log': '_trial_temp/test.log'})
+ ExpectShell.log('stdio', stdout="Ran 1 tests\n")
+ 0
)
self.expectOutcome(result=SUCCESS, status_text=['1 test', 'passed'])
return self.runStep()

def test_run_plural(self):
self.setupStep(
python_twisted.Trial(workdir='build',
tests = 'testname',
testpath=None))
self.expectCommands(
ExpectShell(workdir='build',
command=['trial', '--reporter=bwverbose', 'testname'],
usePTY="slave-config",
logfiles={'test.log': '_trial_temp/test.log'})
+ ExpectShell.log('stdio', stdout="Ran 2 tests\n")
+ 0
)
self.expectOutcome(result=SUCCESS, status_text=['2 tests', 'passed'])
return self.runStep()

0 comments on commit 7c97db1

Please sign in to comment.