Skip to content

Commit f9e5051

Browse files
committed
Ported common code to testing common
1 parent 569843a commit f9e5051

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

Packages/testing/common.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
def test_values_setting(gm,attributes,good_values=[],bad_values=[]):
2+
if isinstance(attributes,str):
3+
attributes=[attributes,]
4+
for att in attributes:
5+
for val in good_values:
6+
setattr(gm,att,val)
7+
for val in bad_values:
8+
try:
9+
setattr(gm,att,val)
10+
success = True
11+
except:
12+
success = False
13+
else:
14+
if success:
15+
if hasattr(gm,"g_name"):
16+
nm = gm.g_name
17+
elif hasattr(gm,"s_name"):
18+
nm = gm.s_name
19+
else:
20+
nm=gm.p_name
21+
raise Exception,"Should not be able to set %s attribute '%s' to %s" % (nm,att,repr(val))
22+
sys.exit(1)

Packages/testing/regression.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,31 @@ def printDart(name, type, value, suff=""):
138138
printDart("ValidImage", "image/png", os.path.abspath(bestFilename), "File")
139139
return -1
140140

141+
142+
def test_values_setting(gm,attributes,good_values=[],bad_values=[]):
143+
if isinstance(attributes,str):
144+
attributes=[attributes,]
145+
for att in attributes:
146+
for val in good_values:
147+
setattr(gm,att,val)
148+
for val in bad_values:
149+
try:
150+
setattr(gm,att,val)
151+
success = True
152+
except:
153+
success = False
154+
else:
155+
if success:
156+
if hasattr(gm,"g_name"):
157+
nm = gm.g_name
158+
elif hasattr(gm,"s_name"):
159+
nm = gm.s_name
160+
else:
161+
nm=gm.p_name
162+
raise Exception,"Should not be able to set %s attribute '%s' to %s" % (nm,att,repr(val))
163+
sys.exit(1)
164+
165+
141166
def main():
142167
if len(sys.argv) != 4:
143168
print "Error:"

0 commit comments

Comments
 (0)