Package funkload :: Package tests :: Module test_Install
[hide private]
[frames] | no frames]

Source Code for Module funkload.tests.test_Install

  1  # (C) Copyright 2005 Nuxeo SAS <http://nuxeo.com> 
  2  # Author: bdelbosc@nuxeo.com 
  3  # 
  4  # This program is free software; you can redistribute it and/or modify 
  5  # it under the terms of the GNU General Public License version 2 as published 
  6  # by the Free Software Foundation. 
  7  # 
  8  # This program is distributed in the hope that it will be useful, 
  9  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 10  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 11  # GNU General Public License for more details. 
 12  # 
 13  # You should have received a copy of the GNU General Public License 
 14  # along with this program; if not, write to the Free Software 
 15  # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 
 16  # 02111-1307, USA. 
 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   
28 -def winplatform_getstatusoutput(cmd):
29 """A replacement for commands.getstatusoutput on the windows platform. 30 commands.getstatusoutput only works on unix platforms. 31 This only works with python2.6+ as the subprocess module is required. 32 os.system provides the return code value but not the output streams of the 33 commands. 34 os.popen provides the output streams but no reliable easy to get return code. 35 """ 36 try: 37 import subprocess 38 except ImportError: 39 return None 40 41 # create a new handle for the stdout pipe of cmd, and redirect cmd's stderr to stdout 42 process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 43 shell=True, universal_newlines=True) 44 stdoutdata, stderrdata = process.communicate() 45 return (process.returncode, stdoutdata)
46 47
48 -class TestInstall(unittest.TestCase):
49 """Check installation.""" 50
51 - def setUp(self):
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
70 - def test_01_requires(self):
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
102 - def test_testloader(self):
103 # check testrunner loader 104 test_file = self.test_file 105 # listing test 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 # list a test suite 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 # list all test in a test case class 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 # match regex 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
146 - def test_doctestloader(self):
147 # check testrunner loader 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 # listing test 154 output = self.system("fl-run-test %s --list" % test_file) 155 self.assert_('Dummy.double' in output, 'missing doctest') 156 157 # list a test suite 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 # list all test in a test case class 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 # pure doctest 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 # match regex 174 output = self.system("fl-run-test %s --list -e dummy1_1" % test_file)
175 176
177 - def test_testrunner(self):
178 # try to launch a test 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 # doctest 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 # failing test 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
203 - def test_xmlrpc(self):
204 # windows os does not support the monitor server 205 if 'win' not in sys.platform: 206 # extract demo example and run the xmlrpc test 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
224 -def test_suite():
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