1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# 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 buildbot.steps.shell import ShellCommand, SetPropertyFromCommand
from buildbot.process.properties import WithProperties, Properties
from buildbot.process.factory import BuildFactory
from buildbot.sourcestamp import SourceStamp
from buildbot import config
class FakeSlaveBuilder:
slave = None
class FakeBuildStatus:
def __init__(self):
self.names = []
def addStepWithName(self, name):
self.names.append(name)
return FakeStepStatus()
def getProperties(self):
return Properties()
def setSourceStamps(self, ss_list):
self.ss_list = ss_list
def setReason(self, reason):
self.reason = reason
def setBlamelist(self, bl):
self.bl = bl
def setProgress(self, p):
self.progress = p
class FakeStepStatus:
txt = None
def setText(self, txt):
self.txt = txt
def setProgress(self, sp):
pass
class FakeBuildRequest:
def __init__(self, reason, sources, buildername):
self.reason = reason
self.sources = sources
self.buildername = buildername
self.changes = []
self.properties = Properties()
def mergeSourceStampsWith(self, others):
return [source for source in self.sources.itervalues()]
def mergeReasons(self, others):
return self.reason
class TestShellCommandProperties(unittest.TestCase):
def testCommand(self):
f = BuildFactory()
f.addStep(SetPropertyFromCommand(command=["echo", "value"], property="propname"))
f.addStep(ShellCommand(command=["echo", WithProperties("%(propname)s")]))
ss = SourceStamp()
req = FakeBuildRequest("Testing", {ss.repository:ss}, None)
b = f.newBuild([req])
b.build_status = FakeBuildStatus()
b.slavebuilder = FakeSlaveBuilder()
# This shouldn't raise an exception
b.setupBuild(None)
class TestSetProperty(unittest.TestCase):
def testGoodStep(self):
f = BuildFactory()
f.addStep(SetPropertyFromCommand(command=["echo", "value"], property="propname"))
ss = SourceStamp()
req = FakeBuildRequest("Testing", {ss.repository:ss}, None)
b = f.newBuild([req])
b.build_status = FakeBuildStatus()
b.slavebuilder = FakeSlaveBuilder()
# This shouldn't raise an exception
b.setupBuild(None)
def testErrorBothSet(self):
self.assertRaises(config.ConfigErrors,
SetPropertyFromCommand, command=["echo", "value"], property="propname", extract_fn=lambda x:{"propname": "hello"})
def testErrorNoneSet(self):
self.assertRaises(config.ConfigErrors,
SetPropertyFromCommand, command=["echo", "value"])
|