Package qm :: Package test :: Module resource :: Class Resource
[show private | hide private]
[frames | no frames]

Type Resource

object --+        
         |        
 Extension --+    
             |    
      Runnable --+
                 |
                Resource

Known Subclasses:
ResourceAdapter, TempDirectoryResource

A 'Resource' sets up before a test and cleans up afterwards.

Some tests take a lot of work to set up. For example, a database test that checks the result of SQL queries may require that the database first be populated with a substantial number of records. If there are many tests that all use the same set of records, it would be wasteful to set up the database for each test. It would be more efficient to set up the database once, run all of the tests, and then remove the databases upon completion.

You can use a 'Resource' to gain this efficiency. If a test depends on a resource, QMTest will ensure that the resource is available before the test runs. Once all tests that depend on the resource have been run QMTest will destroy the resource.

Each resource class (i.e., class derived from 'Resource') describes a set of "arguments". Each argument has a name and a type. The values of these arguments determine the design-time parameters for the resource. See the documentation for the 'Test' class for more complete information.

Each resource class also defines a 'SetUp' method that indicates how to set up the resource, and a 'CleanUp' method that indicates how to clean up afterwards.

'Resource' is an abstract class.

You can extend QMTest by providing your own resource class implementation. If the resource classes that come with QMTest cannot be used conveniently with your application domain, you may wish to create a new resource class.

To create your own resource class, you must create a Python class derived (directly or indirectly) from 'Resource'. The documentation for each method of 'Resource' indicates whether you must override it in your resource class implementation. Some methods may be overridden, but do not need to be. You might want to override such a method to provide a more efficient implementation, but QMTest will work fine if you just use the default version.

If QMTest calls a method on a resource and that method raises an exception that is not caught within the method itself, QMTest will catch the exception and continue processing.
Method Summary
  CleanUp(self, result)
Clean up the resource.
  SetUp(self, context, result)
Set up the resource.
    Inherited from Runnable
  __init__(self, arguments, **args)
Construct a new 'Runnable'.
  GetAttachments(self)
Return the 'Attachment's to this 'Runnable'.
  GetDatabase(self)
Return the 'Database' in which this test or resource is stored.
  GetId(self)
Return the name of this test or resource.
    Inherited from Extension
  __getattr__(self, name)
  GetClassName(self)
Return the name of the extension class.
  GetExplicitArguments(self)
Return the arguments to this extension instance.
  MakeDomDocument(self)
Create a DOM document for 'self'.
  MakeDomElement(self, document, element)
Create a DOM node for 'self'.
  Write(self, file)
Write an XML description of 'self' to a file.
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
x.__hash__() <==> hash(x)
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __repr__(x)
x.__repr__() <==> repr(x)
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value
  __str__(x)
x.__str__() <==> str(x)

Class Variable Summary
str kind = 'resource'
list resources = []
    Inherited from Runnable
list arguments = [<<class 'qm.fields.SetField'> resources>]
str EXTRA_DATABASE = 'qmtest_database'
str EXTRA_ID = 'qmtest_id'
str RESOURCE_FIELD_ID = 'resources'

Method Details

CleanUp(self, result)

Clean up the resource.

'result' -- A 'Result' object. The outcome will be 'Result.PASS' when this method is called. The 'result' may be modified by this method to indicate outcomes other than 'Result.PASS' or to add annotations.

This method should not return a value.

Derived classes may override this method.

SetUp(self, context, result)

Set up the resource.

'context' -- A 'Context' giving run-time parameters to the resource. The resource may place additional variables into the 'context'; these variables will be visible to tests that depend on the resource.

'result' -- A 'Result' object. The outcome will be 'Result.PASS' when this method is called. The 'result' may be modified by this method to indicate outcomes other than 'Result.PASS' or to add annotations.

This method should not return a value.

Derived classes must override this method.

Class Variable Details

kind

Type:
str
Value:
'resource'                                                             

resources

Type:
list
Value:
[]                                                                     

Generated by Epydoc 2.1 on Thu Sep 27 15:49:07 2007 http://epydoc.sf.net