Package pysys :: Module constants
[hide private]
[frames] | no frames]

Source Code for Module pysys.constants

  1  #!/usr/bin/env python 
  2  # PySys System Test Framework, Copyright (C) 2006-2016  M.B.Grieve 
  3   
  4  # This library is free software; you can redistribute it and/or 
  5  # modify it under the terms of the GNU Lesser General Public 
  6  # License as published by the Free Software Foundation; either 
  7  # version 2.1 of the License, or (at your option) any later version. 
  8   
  9  # This library is distributed in the hope that it will be useful, 
 10  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 11  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
 12  # Lesser General Public License for more details. 
 13   
 14  # You should have received a copy of the GNU Lesser General Public 
 15  # License along with this library; if not, write to the Free Software 
 16  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 
 17   
 18  # Contact: moraygrieve@users.sourceforge.net 
 19  """ 
 20  Defines global constants that are used throughout the PySys framework.  
 21   
 22  The standard convention is to import all contents of the module so that the constants can  
 23  be referenced directly. The module also contains methods for locating and parsing the PySys  
 24  project file (L{pysys.constants.loadproject}), and the project class that provides an  
 25  abstraction over the contents of the file (L{pysys.constants.Project}). For more information  
 26  about the structure and contents of the project file, see the PySys examples  
 27  distribution.  
 28   
 29  """ 
 30  import sys, re, os, os.path, socket, logging 
 31   
 32  # if set is not available (>python 2.6) fall back to the sets module 
 33  try:   
 34          set   
 35  except NameError:   
 36          import sets 
 37          from sets import Set as set 
 38   
 39  from pysys import log 
 40  from pysys import stdoutHandler 
 41   
 42  # set the platform and platform related constants 
 43  HOSTNAME = socket.getfqdn() 
 44  if re.search('win32', sys.platform): 
 45          PLATFORM='win32'         
 46          OSFAMILY='windows' 
 47          DEVNULL = 'nul' 
 48          ENVSEPERATOR = ';' 
 49          WINDIR = os.getenv('windir', 'c:\WINDOWS') 
 50          PATH = r'%s;%s\system32;%s\System32\Wbem' % (WINDIR, WINDIR, WINDIR) 
 51          LD_LIBRARY_PATH = '' 
 52          DYLD_LIBRARY_PATH = '' 
 53          SITE_PACKAGES_DIR =  os.path.join(sys.prefix, "Lib", "site-packages") 
 54           
 55  elif re.search('sunos', sys.platform): 
 56          PLATFORM='sunos' 
 57          OSFAMILY='unix' 
 58          DEVNULL = '/dev/null' 
 59          ENVSEPERATOR = ':' 
 60          PATH = '/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/ccs/bin:/usr/openwin/bin:/opt/SUNWspro/bin' 
 61          LD_LIBRARY_PATH = '/usr/local/lib'  
 62          DYLD_LIBRARY_PATH = '' 
 63          SITE_PACKAGES_DIR = os.path.join(sys.prefix, "lib", "python%s" % sys.version[:3], "site-packages") 
 64   
 65  elif re.search('linux', sys.platform): 
 66          PLATFORM='linux' 
 67          OSFAMILY='unix' 
 68          DEVNULL = '/dev/null' 
 69          ENVSEPERATOR = ':' 
 70          PATH = '/bin:/usr/bin:/usr/sbin:/usr/local/bin' 
 71          LD_LIBRARY_PATH = '/usr/lib' 
 72          DYLD_LIBRARY_PATH = '' 
 73          SITE_PACKAGES_DIR = os.path.join(sys.prefix, "lib", "python%s" % sys.version[:3], "site-packages") 
 74   
 75  elif re.search('darwin', sys.platform): 
 76          PLATFORM='darwin' 
 77          OSFAMILY='unix' 
 78          DEVNULL = '/dev/null' 
 79          ENVSEPERATOR = ':' 
 80          PATH = '/bin:/usr/bin:/usr/sbin:/usr/local/bin' 
 81          LD_LIBRARY_PATH = '' 
 82          DYLD_LIBRARY_PATH = '/usr/lib:/usr/local/lib' 
 83          SITE_PACKAGES_DIR = os.path.join(sys.prefix, "lib", "python%s" % sys.version[:3], "site-packages") 
 84   
 85  else: 
 86          # Fall back to assumed UNIX-like platform 
 87          PLATFORM=sys.platform 
 88          OSFAMILY='unix' 
 89          DEVNULL = '/dev/null' 
 90          ENVSEPERATOR = ':' 
 91          PATH = '/bin:/usr/bin:/usr/sbin:/usr/local/bin' 
 92          LD_LIBRARY_PATH = '/usr/lib' 
 93          DYLD_LIBRARY_PATH = '' 
 94          SITE_PACKAGES_DIR = os.path.join(sys.prefix, "lib", "python%s" % sys.version[:3], "site-packages") 
 95   
 96  # constants used in testing 
 97  TRUE=True 
 98  FALSE=False 
 99  BACKGROUND = 10 
100  FOREGROUND = 11 
101  PASSED = 20 
102  INSPECT = 21 
103  NOTVERIFIED = 22 
104  FAILED = 23 
105  TIMEDOUT = 24 
106  DUMPEDCORE = 25 
107  BLOCKED = 26 
108  SKIPPED = 27 
109   
110  LOOKUP = {} 
111  LOOKUP[True] = "TRUE" 
112  LOOKUP[False] = "FALSE" 
113  LOOKUP[TRUE] = "TRUE" 
114  LOOKUP[FALSE] = "FALSE" 
115  LOOKUP[PASSED] = "PASSED" 
116  LOOKUP[INSPECT] = "REQUIRES INSPECTION" 
117  LOOKUP[NOTVERIFIED] = "NOT VERIFIED" 
118  LOOKUP[FAILED] = "FAILED" 
119  LOOKUP[TIMEDOUT] = "TIMED OUT" 
120  LOOKUP[DUMPEDCORE] = "DUMPED CORE" 
121  LOOKUP[BLOCKED] = "BLOCKED" 
122  LOOKUP[SKIPPED] = "SKIPPED" 
123   
124   
125  # set the precedent for the test outcomes 
126  PRECEDENT = [SKIPPED, BLOCKED, DUMPEDCORE, TIMEDOUT, FAILED, NOTVERIFIED, INSPECT, PASSED] 
127  FAILS = [ BLOCKED, DUMPEDCORE, TIMEDOUT, FAILED ] 
128   
129   
130  # set the default descriptor filename, input, output and reference directory names 
131  DEFAULT_PROJECTFILE = ['pysysproject.xml', '.pysysproject'] 
132  DEFAULT_DESCRIPTOR = ['pysystest.xml', '.pysystest', 'descriptor.xml']   
133  DEFAULT_MODULE = 'run' 
134  DEFAULT_GROUP = "" 
135  DEFAULT_TESTCLASS = 'PySysTest' 
136  DEFAULT_INPUT = 'Input' 
137  DEFAULT_OUTPUT = 'Output' 
138  DEFAULT_REFERENCE = 'Reference' 
139  DEFAULT_RUNNER =  ['BaseRunner', 'pysys.baserunner'] 
140  DEFAULT_MAKER =  ['ConsoleMakeTestHelper', 'pysys.launcher.console'] 
141  DEFAULT_WRITER =  ['XMLResultsWriter', 'pysys.writer', 'testsummary_%Y%m%d%H%M%S.xml', {}] 
142  DEFAULT_STYLESHEET = os.path.join(SITE_PACKAGES_DIR, 'pysys-log.xsl') 
143  DEFAULT_FORMAT_STDOUT = '%(asctime)s %(levelname)-5s %(message)s' 
144  DEFAULT_FORMAT_RUNLOG = '%(asctime)s %(levelname)-5s %(message)s' 
145  DEFAULT_ABORT_ON_ERROR=False 
146   
147  # set the directories to not recursively walk when looking for the descriptors 
148  OSWALK_IGNORES = [ DEFAULT_INPUT, DEFAULT_OUTPUT, DEFAULT_REFERENCE, 'CVS', '.svn' ] 
149   
150   
151  # set the timeout values for specific executables when executing a test 
152  DEFAULT_TIMEOUT = 600 
153  TIMEOUTS = {} 
154  TIMEOUTS['WaitForSocket'] = 60 
155  TIMEOUTS['WaitForFile'] = 30 
156  TIMEOUTS['WaitForSignal'] = 60 
157  TIMEOUTS['WaitForProcessStop'] = 30 
158  TIMEOUTS['WaitForProcess'] = 60*10 
159  TIMEOUTS['ManualTester'] = 1800 
160   
161   
162  # reference to the project instance defining parameters for the  
163  # pysys project 
164  PROJECT = None 
165   
166   
167  # load the project specific details 
168 -def loadproject(start):
169 """Load the PySys project file. 170 171 The method walks up the directory tree from the supplied path until the 172 PySys project file is found. The location of the project file defines 173 the project root location. The contents of the project file determine 174 project specific constants as specified by property elements in the 175 xml project file. 176 177 To ensure that all loaded modules have a pre-initialised projects 178 instance, any launching application should first import the loadproject 179 file, and then make a call to it prior to importing all names within the 180 constants module. 181 182 @param start: The initial path to start from when trying to locate the project file 183 184 """ 185 186 global PROJECT 187 188 projectFile = None 189 projectFileSet = set(DEFAULT_PROJECTFILE) 190 191 search = start 192 drive, path = os.path.splitdrive(search) 193 while (not search == drive): 194 intersection = projectFileSet & set(os.listdir(search)) 195 if intersection : 196 projectFile = intersection.pop() 197 break 198 else: 199 search, drop = os.path.split(search) 200 if not drop: search = drive 201 202 if not (projectFile is not None and os.path.exists(os.path.join(search, projectFile))): 203 sys.stderr.write("WARNING: No project file found, taking project root to be %s \n" % search) 204 205 try: 206 PROJECT = Project(search, projectFile) 207 stdoutHandler.setFormatter(PROJECT.formatters.stdout) 208 except Exception, e: 209 sys.stderr.write("ERROR: %s\n", e) 210 sys.exit(1)
211 212 213
214 -class Project:
215 """Class detailing project specific information for a set of PySys tests. 216 217 Reads and parses the PySys project file if it exists and translates property element 218 name/value entries in the project file into data attributes of the class instance. 219 220 @ivar root: Full path to the project root, as specified by the first PySys project 221 file encountered when walking down the directory tree from the start directory 222 @type root: string 223 @ivar projectFile: Full path to the project file. May be None, though providing a file is recommended. 224 @type projectFile: string 225 226 """ 227
228 - def __init__(self, root, projectFile):
229 self.root = root 230 self.formatters=type('Formatters',(object,),{'stdout':logging.Formatter(DEFAULT_FORMAT_STDOUT), 231 'runlog':logging.Formatter(DEFAULT_FORMAT_RUNLOG)}) 232 233 self.runnerClassname, self.runnerModule = DEFAULT_RUNNER 234 self.makerClassname, self.makerModule = DEFAULT_MAKER 235 self.writers = [DEFAULT_WRITER] 236 237 if projectFile is not None and os.path.exists(os.path.join(root, projectFile)): 238 # parse the project file 239 from pysys.xml.project import XMLProjectParser 240 try: 241 parser = XMLProjectParser(root, projectFile) 242 except Exception, e: 243 raise Exception("Error parsing project file %s, %s" % (os.path.join(root, projectFile),sys.exc_info()[1])) 244 else: 245 # get the properties 246 properties = parser.getProperties() 247 keys = properties.keys() 248 keys.sort() 249 for key in keys: setattr(self, key, properties[key]) 250 251 # add to the python path 252 parser.addToPath() 253 254 # get the runner if specified 255 self.runnerClassname, self.runnerModule = parser.getRunnerDetails() 256 257 # get the maker if specified 258 self.makerClassname, self.makerModule = parser.getMakerDetails() 259 260 # get the loggers to use 261 self.writers = parser.getWriterDetails() 262 263 # get the stdout and runlog formatters 264 parser.setFormatters(self.formatters) 265 266 # set the data attributes 267 parser.unlink()
268