Package qm :: Package test :: Module context :: Class Context
[hide private]
[frames] | no frames]

Class Context
source code

object --+    
         |    
      dict --+
             |
            Context

Test-time and local configuration for tests.

A 'Context' object contains all of the information a test needs to
execute, beyond what is stored as part of the test specification
itself.  Information in the context can include,

  * Local (per-user, etc.) configuration, such as where to find the
    tested program.

  * Environmental information, such as which machine the test is
    running on.

  * One-time configuration, including test arguments specified on
    the command line.

A 'Context' object is effectively a mapping object whose keys must
be labels and values must be strings.



Instance Methods [hide private]
  __init__(self, context=None)
Construct a new context.
  GetDerivedValue(self, klass, variable, default=None)
Return the value for 'variable' in scope 'klass'.
  GetBoolean(self, key, default=None)
Return the boolean value associated with 'key'.
  GetStringList(self, key, default=None)
Return the list of strings associated with 'key'.
  GetTemporaryDirectory(self)
Return the path to the a temporary directory.
  Read(self, file_name)
Read the context file 'file_name'.
  __contains__(self, key)
  get(self, key, default=None)
d defaults to None.
  has_key(self, key)
  __getitem__(self, key)
x[y]
  items(self)
  GetAddedProperties(self)
Return the properties added to this context by resources.

Inherited from dict: __cmp__, __delitem__, __eq__, __ge__, __getattribute__, __gt__, __hash__, __iter__, __le__, __len__, __lt__, __ne__, __new__, __repr__, __setitem__, clear, copy, fromkeys, iteritems, iterkeys, itervalues, keys, pop, popitem, setdefault, update, values

Inherited from object: __delattr__, __reduce__, __reduce_ex__, __setattr__, __str__


Class Variables [hide private]
TARGET_CONTEXT_PROPERTY The context variable giving the name of the current target.
DB_PATH_CONTEXT_PROPERTY The context variable giving the path to the database.
ID_CONTEXT_PROPERTY The context variable giving the name of the running test or resource.
TMPDIR_CONTEXT_PROPERTY A context property whose value is a string giving the path to a temporary directory.
__safe_for_unpickling__ Required to unpickle new-style classes under Python 2.2.

Inherited from object: __class__


Method Details [hide private]

__init__(self, context=None)
(Constructor)

source code 

Construct a new context.

'context' -- If not 'None', the existing 'Context' being wrapped by this new context.
Overrides: dict.__init__

GetDerivedValue(self, klass, variable, default=None)

source code 
Return the value for 'variable' in scope 'klass'.
Scopes are nested with '.', and inner variables hide
outer variables of the same name. Thus, looking up the
value of 'a.b.c.var' will return 1 if the context
contains
  a.b.c.var=1
but 2 if it contains
  a.b.d.var=1
  a.b.var=2
  a.var=3.

'klass' -- The variable's scope.

'variable' -- The variable name.

'default' -- Default value.

GetBoolean(self, key, default=None)

source code 

Return the boolean value associated with 'key'.

'key' -- A string.

'default' -- A default boolean value.

returns -- The value associated with 'key' in the context, interpreted as a boolean.

If there is no value associated with 'key' and default is not 'None', then the boolean value associated with default is used. If there is no value associated with 'key' and default is 'None', an exception is raised.

The value associated with 'key' must be a string. If not, an exception is raised. If the value is a string, but does not correspond to a boolean value, an exception is raised.

GetStringList(self, key, default=None)

source code 

Return the list of strings associated with 'key'.

'key' -- A string.

'default' -- A default list.

If there is no value associated with 'key' and default is not 'None', then the boolean value associated with default is used. If there is no value associated with 'key' and default is 'None', an exception is raised.

The value associated with 'key' must be a string. If not, an exception is raised. If the value is a string, but does not correspond to a string list, an exception is raised.

GetTemporaryDirectory(self)

source code 

Return the path to the a temporary directory.

returns -- The path to the a temporary directory. The 'Runnable' object may make free use of this temporary directory; no other 'Runnable's will use the same directory at the same time.

Read(self, file_name)

source code 

Read the context file 'file_name'.

'file_name' -- The name of the context file.

Reads the context file and adds the context properties in the file to 'self'.

__contains__(self, key)
(In operator)

source code 
Returns:
True if D has a key k, else False

Overrides: dict.__contains__
(inherited documentation)

get(self, key, default=None)

source code 
d defaults to None.
Returns:
D[k] if k in D, else d

Overrides: dict.get
(inherited documentation)

has_key(self, key)

source code 
Returns:
True if D has a key k, else False

Overrides: dict.has_key
(inherited documentation)

__getitem__(self, key)
(Indexing operator)

source code 
x[y]
Overrides: dict.__getitem__
(inherited documentation)

items(self)

source code 
Returns:
list of D's (key, value) pairs, as 2-tuples

Overrides: dict.items
(inherited documentation)

GetAddedProperties(self)

source code 

Return the properties added to this context by resources.

returns -- A map from strings to values indicating properties that were added to this context by resources.

Class Variable Details [hide private]

TARGET_CONTEXT_PROPERTY

The context variable giving the name of the current target.
Value:
'qmtest.target'                                                        
      

DB_PATH_CONTEXT_PROPERTY

The context variable giving the path to the database.

The value of this context variable will be a string giving the path to the database directory. For example, if QMTest is invoked as 'qmtest -D /path/to/db run', the value of this variable would be '/path/to/db'. The value may be an absolute or a relative path.
Value:
'qmtest.dbpath'                                                        
      

ID_CONTEXT_PROPERTY

The context variable giving the name of the running test or resource.

This value of this context variable will be the string giving the name of the of the test or resource that is presently executing.
Value:
'qmtest.id'                                                            
      

TMPDIR_CONTEXT_PROPERTY

A context property whose value is a string giving the path to a temporary directory. This directory will be used only by the 'Runnable' in whose context this property occurs during the execution of that 'Runnable'. No other object will use the same temporary directory at the same time. There is no guarantee that the temporary directory is empty, however; it may contain files left behind by the execution of other 'Runnable' objects.
Value:
'qmtest.tmpdir'                                                        
      

__safe_for_unpickling__

Required to unpickle new-style classes under Python 2.2.
Value:
1