1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 """Check an installed FunkLoad.
20
21 $Id: test_Install.py 54042 2009-12-02 10:49:48Z kward $
22 """
23 import os
24 import sys
25 import unittest
26 import commands
27
46
47
49 """Check installation."""
50
52 self.test_file = 'test_dummy.py'
53 self.doctest_file = 'doctest_dummy.txt'
54
55 - def system(self, cmd, expected_code=0):
56 """Execute a cmd and exit on fail return cmd output."""
57
58 if 'win' in sys.platform:
59 ret = winplatform_getstatusoutput(cmd)
60 if not ret:
61 self.fail('Cannot run self.system on windows without the subprocess module (python 2.6)')
62 else:
63 ret = commands.getstatusoutput(cmd)
64
65 if ret[0] != expected_code:
66 self.fail("exec [%s] return code %s != %s output:\n%s" %
67 (cmd, ret[0], expected_code, ret[1]))
68 return ret[1]
69
71 try:
72 import webunit
73 except ImportError:
74 self.fail('Missing Required module webunit')
75 try:
76 import funkload
77 except ImportError:
78 self.fail('Unable to import funkload module.')
79 try:
80 import docutils
81 except ImportError:
82 print ("WARNING: missing docutils module, "
83 "no HTML report available.")
84
85 if 'win' in sys.platform:
86 ret = winplatform_getstatusoutput('wgnuplot --version')
87 if not ret:
88 self.fail('Cannot run self.system on windows without the subprocess module (python 2.6)')
89 else:
90 ret = commands.getstatusoutput('gnuplot --version')
91
92 print ret[1]
93 if ret[0]:
94 print ("WARNING: gnuplot is missing, no charts available in "
95 "HTML reports.")
96
97 from funkload.TestRunner import g_has_doctest
98 if not g_has_doctest:
99 print "WARNING: Python 2.4 is required to support doctest"
100
101
103
104 test_file = self.test_file
105
106 output = self.system("fl-run-test %s --list" % test_file)
107 self.assert_('test_dummy1_1' in output)
108 self.assert_('test_dummy2_1' in output)
109 self.assert_('test_dummy3_1' in output)
110
111
112 output = self.system("fl-run-test %s test_suite --list" % test_file)
113 self.assert_('test_dummy1_1' in output)
114 self.assert_('test_dummy2_1' in output)
115 self.assert_('test_dummy3_1' not in output)
116
117
118 output = self.system("fl-run-test %s TestDummy1 --list" % test_file)
119 self.assert_('test_dummy1_1' in output)
120 self.assert_('test_dummy1_2' in output)
121 self.assert_('test_dummy2_1' not in output)
122
123
124 output = self.system("fl-run-test %s --list -e dummy1_1" % test_file)
125 self.assert_('test_dummy1_1' in output)
126 self.assert_('test_dummy2_1' not in output)
127
128 output = self.system("fl-run-test %s TestDummy1 --list -e dummy1_1" %
129 test_file)
130 self.assert_('test_dummy1_1' in output)
131 self.assert_('test_dummy2_1' not in output)
132
133 output = self.system("fl-run-test %s --list -e 2$" % test_file)
134 self.assert_('test_dummy1_2' in output)
135 self.assert_('test_dummy2_2' in output)
136 self.assert_('test_dummy1_1' not in output)
137 self.assert_('test_dummy2_1' not in output)
138
139 output = self.system("fl-run-test %s --list -e '!2$'" % test_file)
140 self.assert_('test_dummy1_1' in output, output)
141 self.assert_('test_dummy2_1' in output)
142 self.assert_('test_dummy1_2' not in output)
143 self.assert_('test_dummy2_2' not in output)
144
145
147
148 from funkload.TestRunner import g_has_doctest
149 if not g_has_doctest:
150 self.fail('Python 2.4 is required to support doctest')
151
152 test_file = self.test_file
153
154 output = self.system("fl-run-test %s --list" % test_file)
155 self.assert_('Dummy.double' in output, 'missing doctest')
156
157
158 output = self.system("fl-run-test %s test_suite --list" % test_file)
159 self.assert_('Dummy.double' not in output,
160 'doctest is not part of the suite')
161
162
163 output = self.system("fl-run-test %s TestDummy1 --list" % test_file)
164 self.assert_('Dummy.double' not in output,
165 'doctest is not part of the testcase')
166
167
168 doctest_file = self.doctest_file
169 output = self.system("fl-run-test %s --list" % doctest_file)
170 self.assert_(doctest_file.replace('.', '_') in output,
171 'no %s in output %s' % (doctest_file, output))
172
173
174 output = self.system("fl-run-test %s --list -e dummy1_1" % test_file)
175
176
178
179 test_file = self.test_file
180 output = self.system('fl-run-test %s TestDummy1 -v' % test_file)
181 self.assert_('Ran 0 tests' not in output,
182 'not expected output:"""%s"""' % output)
183
184 output = self.system('fl-run-test %s TestDummy2 -v' % test_file)
185 self.assert_('Ran 0 tests' not in output,
186 'not expected output:"""%s"""' % output)
187
188 from funkload.TestRunner import g_has_doctest
189 if g_has_doctest:
190 output = self.system('fl-run-test %s -e double -v' % test_file)
191 self.assert_('Ran 0 tests' not in output,
192 'not expected output:"""%s"""' % output)
193
194
195 output = self.system('fl-run-test %s TestDummy3 -v' % test_file,
196 expected_code=256)
197 self.assert_('Ran 0 tests' not in output,
198 'not expected output:"""%s"""' % output)
199 self.assert_('FAILED' in output)
200 self.assert_('ERROR' in output)
201
202
204
205 if 'win' not in sys.platform:
206
207 from tempfile import mkdtemp
208 pwd = os.getcwd()
209 tmp_path = mkdtemp('funkload')
210 os.chdir(tmp_path)
211 self.system('fl-install-demo')
212 os.chdir(os.path.join(tmp_path, 'funkload-demo', 'xmlrpc'))
213 self.system("fl-credential-ctl cred.conf restart")
214 self.system("fl-monitor-ctl monitor.conf restart")
215 self.system("fl-run-test -v test_Credential.py")
216 self.system("fl-run-bench -c 1:10:20 -D 4 "
217 "test_Credential.py Credential.test_credential")
218 self.system("fl-monitor-ctl monitor.conf stop")
219 self.system("fl-credential-ctl cred.conf stop")
220 self.system("fl-build-report credential-bench.xml --html")
221 os.chdir(pwd)
222
223
225 """Return a test suite."""
226 suite = unittest.TestSuite()
227 suite.addTest(unittest.makeSuite(TestInstall))
228 return suite
229
230 if __name__ in ('main', '__main__'):
231 unittest.main()
232