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

Source Code for Module pysys.constants

  1  #!/usr/bin/env python 
  2  # PySys System Test Framework, Copyright (C) 2006-2013  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   
146  # set the directories to not recursively walk when looking for the descriptors 
147  OSWALK_IGNORES = [ DEFAULT_INPUT, DEFAULT_OUTPUT, DEFAULT_REFERENCE, 'CVS', '.svn' ] 
148   
149   
150  # set the timeout values for specific executables when executing a test 
151  DEFAULT_TIMEOUT = 600 
152  TIMEOUTS = {} 
153  TIMEOUTS['WaitForSocket'] = 60 
154  TIMEOUTS['WaitForFile'] = 30 
155  TIMEOUTS['WaitForSignal'] = 60 
156  TIMEOUTS['WaitForProcessStop'] = 10 
157  TIMEOUTS['ManualTester'] = 1800 
158   
159   
160  # reference to the project instance defining parameters for the  
161  # pysys project 
162  PROJECT = None 
163   
164   
165  # load the project specific details 
166 -def loadproject(start):
167 """Load the PySys project file. 168 169 The method walks up the directory tree from the supplied path until the 170 PySys project file is found. The location of the project file defines 171 the project root location. The contents of the project file determine 172 project specific constants as specified by property elements in the 173 xml project file. 174 175 To ensure that all loaded modules have a pre-initialised projects 176 instance, any launching application should first import the loadproject 177 file, and then make a call to it prior to importing all names within the 178 constants module. 179 180 @param start: The initial path to start from when trying to locate the project file 181 182 """ 183 184 global PROJECT 185 186 projectFile = None 187 projectFileSet = set(DEFAULT_PROJECTFILE) 188 189 search = start 190 drive, path = os.path.splitdrive(search) 191 while (not search == drive): 192 intersection = projectFileSet & set(os.listdir(search)) 193 if intersection : 194 projectFile = intersection.pop() 195 break 196 else: 197 search, drop = os.path.split(search) 198 if not drop: search = drive 199 PROJECT = Project(search, projectFile)
200 201
202 -class Project:
203 """Class detailing project specific information for a set or PySys tests. 204 205 Reads and parses the PySys project file if it exists and translates property element 206 name/value entries in the project file into data attributes of the class instance. 207 208 @ivar root: Full path to the project root, as specified by the first PySys project 209 file encountered when walking down the directory tree from the start directory 210 @type root: string 211 212 """ 213
214 - def __init__(self, root, projectFile):
215 self.root = root 216 self.formatters=type('Formatters',(object,),{'stdout':logging.Formatter(DEFAULT_FORMAT_STDOUT), 217 'runlog':logging.Formatter(DEFAULT_FORMAT_RUNLOG)}) 218 219 self.runnerClassname, self.runnerModule = DEFAULT_RUNNER 220 self.makerClassname, self.makerModule = DEFAULT_MAKER 221 self.writers = [DEFAULT_WRITER] 222 223 if projectFile is not None and os.path.exists(os.path.join(root, projectFile)): 224 # parse the project file 225 from pysys.xml.project import XMLProjectParser 226 try: 227 parser = XMLProjectParser(root, projectFile) 228 except: 229 sys.stderr.write("ERROR: Error parsing project file %s, %s\n" % (os.path.join(root, projectFile),sys.exc_info()[1])) 230 sys.exit(1) 231 else: 232 # get the properties 233 properties = parser.getProperties() 234 keys = properties.keys() 235 keys.sort() 236 for key in keys: setattr(self, key, properties[key]) 237 238 # add to the python path 239 parser.addToPath() 240 241 # get the runner if specified 242 self.runnerClassname, self.runnerModule = parser.getRunnerDetails() 243 244 # get the maker if specified 245 self.makerClassname, self.makerModule = parser.getMakerDetails() 246 247 # get the loggers to use 248 self.writers = parser.getWriterDetails() 249 250 # get the stdout and runlog formatters 251 parser.setFormatters(self.formatters) 252 253 # set the data attributes 254 parser.unlink() 255 else: 256 sys.stderr.write("WARNING: No project file found, taking project root to be %s \n" % root) 257 258 stdoutHandler.setFormatter(self.formatters.stdout)
259