FOSSology  4.4.0
Open Source License Compliance by Open Source Software
Functional.testsuite Class Reference

class that handles running a test suite #################################### More...

Collaboration diagram for Functional.testsuite:
Collaboration graph

Public Member Functions

def __init__ (self, node)
 
def substitute (self, string, node=None)
 
def processVariable (self, node, match)
 
def failure (self, doc, dest, type, value)
 
def createAllActions (self, node)
 actions that tests can take # More...
 
def createAction (self, node)
 
def required (self, node, name)
 
def optional (self, node, name)
 
def concurrently (self, node, doc, dest)
 
def sequential (self, node, doc, dest)
 
def sleep (self, node, doc, dest)
 
def loadConf (self, node, doc, dest)
 
def loop (self, node, doc, dest)
 
def upload (self, node, doc, dest)
 
def schedule (self, node, doc, dest)
 
def database (self, node, doc, dest)
 
def dbequal (self, node, doc, dest)
 
def performTests (self, suiteNode, document, fname)
 run tests and produce output # More...
 

Public Attributes

 name
 
 defines
 
 setup
 
 cleanup
 
 tests
 
 subpro
 
 dbresult
 

Detailed Description

class that handles running a test suite ####################################

The testsuite class is used to deserialize a test suite from the xml file,
run the tests and report the results to another xml document.

name     the name of the test suite
defs     a map of strings to values used to do variables replacement
setup    list of Actions that will be taken before running the tests
cleanup  list of Actions that will be taken after running the tests
tests    list of Actions that are the actual tests
subpro   list of processes that are running concurrently with the tests

Definition at line 75 of file Functional.py.

Constructor & Destructor Documentation

◆ __init__()

def Functional.testsuite.__init__ (   self,
  node 
)
Constructor for the testsuite class. This will deserialize the testsuite
from the xml file that describes all the tests. For each element in the
setup, and cleanup and action will be created. For each element under each
<test></test> tag an action will be created.

This will also grab the definitions of variables for the self.defines map. The
variable substitution will be performed when the definition is loaded from
the file.

Returns nothing

Definition at line 88 of file Functional.py.

Member Function Documentation

◆ concurrently()

def Functional.testsuite.concurrently (   self,
  node,
  doc,
  dest 
)
Action

Attributes:
  command [required]: the name of the process that will be executed
  params  [required]: the command line parameters passed to the command

This executes a shell command concurrently with the testing harness. This
starts the process, sleeps for a second and then checks the pid of the
process. The pid will be appended to the list of pid's in the definitions
map. This action cannot fail as it does not check any of the results of the
process that was created.

Returns True

Definition at line 292 of file Functional.py.

◆ createAction()

def Functional.testsuite.createAction (   self,
  node 
)
Creates an action given a particular test suite and xml node. This uses
simple python reflection to get the method of the testsuite class that has
the same name as the xml node tag. The action is a functor that can be
called later be another part of the test harness.

To write a new type of action write a function with the signature:
  actionName(self, source_node, xml_document, destination_node)

* The source_node is the xml node that described the action, this node
  should describe everything that is necessary for the action to be
  performed. This is passed to the action when the action is created.
* The xml_document is the document that the test results are being written
  to. This is passed to the action when it is called, not during creation.
* The destination_node is the node in the results xml document that this
  particular action should be writing its results to. This is passed in when
  the action is called, not during creation.

The action should return the number of tests that it ran and the number of
failures that it experienced. A failing action has different meanings
during different parts of the code. During setup, a failing action
indicates that the setup is not ready to proceed. Failing actions during
setup will be called repeatedly once every five seconds until they no
longer register a failure. Failing actions during testing indicate a
failing test. The failure will be reported to results document, but the
action should still call the failure method to indicate in the results
document why the failure happened. During cleanup what an action returns is
ignored.

Returns the new action

Definition at line 232 of file Functional.py.

◆ createAllActions()

def Functional.testsuite.createAllActions (   self,
  node 
)

actions that tests can take #

Creates all the child actions for a particular node in the xml file.

Definition at line 226 of file Functional.py.

◆ database()

def Functional.testsuite.database (   self,
  node,
  doc,
  dest 
)
Action

Attributes:
  sql    [required]: the sql that will be exectued

Sub nodes:
  

This action will execute an sql statement on the relevant database. It can
check that the results of the sql were correct.

Returns True if results aren't expected or the results were correct

Definition at line 506 of file Functional.py.

◆ dbequal()

def Functional.testsuite.dbequal (   self,
  node,
  doc,
  dest 
)
Action

Attributes:
  row [required]: the row of the database results
  col [required]: the column of the database results
  val [required]: the expected value found at that row and column

checks if a particular row and column in the results of a database call are
an expected value. This fails if the correct value is not reported by the
database.

returns True if the expected is the same as the result

Definition at line 541 of file Functional.py.

◆ failure()

def Functional.testsuite.failure (   self,
  doc,
  dest,
  type,
  value 
)
Puts a failure node into an the results document

Return nothing

Definition at line 207 of file Functional.py.

◆ loadConf()

def Functional.testsuite.loadConf (   self,
  node,
  doc,
  dest 
)
Action

Attributes:
  directory [required]: the directory location of the fossology.conf file

This loads the configuration and VERSION data from the fossology.conf file
and the VERSION file. It puts the information in the definitions map.

Returns True

Definition at line 374 of file Functional.py.

◆ loop()

def Functional.testsuite.loop (   self,
  node,
  doc,
  dest 
)
Action

Attributes:
  varname    [required]: the name of the variable storing the current iteration
  values     [optional]: the values that the variable should take
  iterations [optional]: the number of iterations the loop with take

This action actually executes the actions contained within it. This will loop
over the values specified or loop for the number of iterations specified. The
current value of the variable will be stored in the definitions mapping with
the value varname. While both "values" and "iterations" are optional
parameters, one of them is required to be provided.

Definition at line 406 of file Functional.py.

◆ optional()

def Functional.testsuite.optional (   self,
  node,
  name 
)
Gets an options attribute for a particular action. This will perform the
necessary substitution for the value of the attribute.

Definition at line 285 of file Functional.py.

◆ performTests()

def Functional.testsuite.performTests (   self,
  suiteNode,
  document,
  fname 
)

run tests and produce output #

Runs the tests and writes the output to the results document.

Returns nothing

Definition at line 578 of file Functional.py.

◆ processVariable()

def Functional.testsuite.processVariable (   self,
  node,
  match 
)
Function passed to the regular expression library to replace variables in a
string from the xml file.
doc, dest, "")
  return (1, 0)
The regular expression used is "{([^\s]*?)}". This will match anything that
doesn't contain any whitespace and falls between two curly braces. For
example "{hello}" will match, but "{hello goodbye}" and "hello" will not.

Any variable name that starts with a "$" has a special meaning. The text
following the "$" will be used as a shell command and executed. The
"{$text}" will be replaced with the output of the shell command. For example
"{$pwd}" will be replaced with the output of the shell command "pwd".

If a variable has a ":" in it, anything that follows the ":" will be used
to index into the associative array in the definitions map. For example
"{pids:0}" will access the element that is mapped to the string "0" in the
associative array that is as the mapped to the string "pids" in the defs
map.

Returns the replacement string

Definition at line 150 of file Functional.py.

◆ required()

def Functional.testsuite.required (   self,
  node,
  name 
)
Get a required attribute for a particular action. If the attribute is not
defined in the xml file, this will throw a DefineError. This will perform
the necessary substitution for the value of the attribute.

Definition at line 273 of file Functional.py.

◆ schedule()

def Functional.testsuite.schedule (   self,
  node,
  doc,
  dest 
)
Action

Attributes:
  upload [required]: the index of the upload in the ['upload_pk'] mapping
  agents [optional]: comma seperated list of agent to schedule. If this is
      not specified, all agents will be scheduled

This action will schedule agents to run on a particular upload.

Returns True if and only if fossjobs succeeded

Definition at line 479 of file Functional.py.

◆ sequential()

def Functional.testsuite.sequential (   self,
  node,
  doc,
  dest 
)
Action

Attributes:
  command [required]: the name of the process that will be executed
  params  [required]: the command line parameters passed to the command
  result  [optional]: what the process should print to stdout
  retval  [optional]: what the exit value of the process should be

This executes a shell command synchronously with the testing harness. This
starts the process, grabs anything written to stdout by the process and the
return value of the process. If the results and retval attributes are
provided, these are compared with what the process printed/returned. If
the results or return value do not match, this will return False.

Returns True if the results and return value match those provided

Definition at line 319 of file Functional.py.

◆ sleep()

def Functional.testsuite.sleep (   self,
  node,
  doc,
  dest 
)
Action

Attributes:
  duration [require]: how long the test harness should sleep for

This action simply pauses execution of the test harness for duration
seconds. This action cannot fail and will always return True.

Returns True

Definition at line 358 of file Functional.py.

◆ substitute()

def Functional.testsuite.substitute (   self,
  string,
  node = None 
)
Simple function to make calling processVariable a lot cleaner

Returns the string with the variables correctly substituted

Definition at line 140 of file Functional.py.

◆ upload()

def Functional.testsuite.upload (   self,
  node,
  doc,
  dest 
)
Action

Attributes:
  file [required]: the file that will be uploaded to the fossology database

This action uploads a new file into the fossology test(hopefully) database
so that an agent can work with it. This will place the upload_pk for the
file in the self.sefs map under the name ['upload_pk'][index] where the
index is the current number of elements in the ['upload_pk'] mapping. So the
upload_pk's for the files should showup in the order they were uploaded.

Returns True if and only if cp2foss succeeded

Definition at line 448 of file Functional.py.


The documentation for this class was generated from the following file: