PATCH: Replace resource_adapter with ResourceAdapter

Mark Mitchell mark at codesourcery.com
Fri Sep 2 20:43:41 UTC 2005


Stefan suggested a cleaner way of doing the resource adapter that I
posted yesterday, using a mix-in.  With this method, you do:

  class R(ResourceAdapter, T):

    ...

to make "R" a resource class based on T, a test class.

Committed.

--
Mark Mitchell
CodeSourcery, LLC
mark at codesourcery.com

2005-09-02  Mark Mitchell  <mark at codesourcery.com>

	* qm/test/resource_adapter.py: New file.
	* qm/test/resource.py (resource_adapter): Remove.

Index: qm/test/resource.py
===================================================================
RCS file: /home/qm/Repository/qm/qm/test/resource.py,v
retrieving revision 1.11
diff -c -5 -p -r1.11 resource.py
*** qm/test/resource.py	1 Sep 2005 23:22:04 -0000	1.11
--- qm/test/resource.py	2 Sep 2005 20:40:11 -0000
***************
*** 17,27 ****
  # Imports
  ########################################################################
  
  import qm
  import qm.test.runnable
- from   qm.test.test import Test
  
  ########################################################################
  # Classes
  ########################################################################
  
--- 17,26 ----
*************** class Resource(qm.test.runnable.Runnable
*** 104,147 ****
          This method should not return a value.
  
          Derived classes may override this method."""
  
          pass
- 
- 
- 
- ########################################################################
- # Functions
- ########################################################################
- 
- def resource_adapter(test_class):
-     """Return a resource class based on 'test_class'.
- 
-     'test_class' -- A 'Test' class.  This argument is not the name of
-     a 'Test' class; it is the actuall class object itself.
- 
-     returns -- A 'Resource' class.  The 'Resource' class 'SetUp'
-     method is equivalent to the 'Test' class 'Run' method.  The
-     'CleanUp' action is empty.
- 
-     If this function is called more than once with the same
-     'test_class', it will return a new class each time."""
- 
-     assert test_class.kind == Test.kind
- 
-     # Construct a new class.  By listing 'Resource' first, we ensure
-     # that the 'kind' field for the new class is 'Resource.kind'.
-     class ResourceAdapter(Resource, test_class):
-         """A 'ResourceAdapter' is a resource based on a 'Test' class.
- 
-         The 'SetUp' method for this class behaves just like the 'Run'
-         method for the test class on which this resource is based.""" 
- 
-         def SetUp(self, context, result):
- 
-             # To set up the resource, just run the underlying test class.
-             self.Run(context, result)
- 
- 
- 
-     # Return the new class.        
-     return ResourceAdapter
--- 103,107 ----
Index: qm/test/resource_adapter.py
===================================================================
RCS file: qm/test/resource_adapter.py
diff -N qm/test/resource_adapter.py
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- qm/test/resource_adapter.py	2 Sep 2005 20:40:11 -0000
***************
*** 0 ****
--- 1,39 ----
+ ########################################################################
+ #
+ # File:   resource_adapter.py
+ # Author: Mark Mitchell
+ # Date:   2005-09-02
+ #
+ # Contents:
+ #   QMTest ResourceAdapter class.
+ #
+ # Copyright (c) 2005 by CodeSourcery, LLC.  All rights reserved. 
+ #
+ # For license terms see the file COPYING.
+ #
+ ########################################################################
+ 
+ ########################################################################
+ # Imports
+ ########################################################################
+ 
+ from qm.test.resource import Resource
+ 
+ ########################################################################
+ # Classes
+ ########################################################################
+ 
+ class ResourceAdapter(Resource):
+     """A 'ResourceAdapter' converts test classes to resource classes.
+ 
+     If 'C' is a test class, then a class derived from
+     'ResourceAdapter' and 'C' (in that order!) will be a resource
+     class.  The resource class 'Setup' method is equivalent to the
+     'Test' class 'Run' method.  The 'CleanUp' action is empty."""
+ 
+     def SetUp(self, context, result):
+         
+         # To set up the resource, just run the underlying test class.
+         self.Run(context, result)
+ 
+     



More information about the qmtest mailing list