[qmtest] command.ShellCommandTest run directory

Mark Mitchell mark at codesourcery.com
Thu Nov 13 04:28:16 UTC 2003


> > I think that the best change would be to have QMTest include the test 
> > ID
> > and the database path in the shell-script context, i.e., as $QMV_*
> > variables.
> >
> > Would that work for you?
> 
> That would be perfect and is exactly what I was looking for.

This patch implements that change.

-- 
Mark Mitchell <mark at codesourcery.com>
CodeSourcery, LLC
-------------- next part --------------
2003-11-12  Mark Mitchell  <mark at codesourcery.com>

	* qm/test/context.py (Context.DB_PATH_CONTEXT_PROPERTY): New
	variable.
	(Context.ID_CONTEXT_PROPERTY): Likewise.
	(Context.TMPDIR_CONTEXT_PROPERTY): Likewise.
	* qm/test/target.py (Target.RunTest): Set them.
	(Target._FinishResourceSetUp): Clear ID_CONTEXT_PROPERTY.
	(Target._SetUpResource): Set ID_CONTEXT_PROPERTY.

Index: qm/test/context.py
===================================================================
RCS file: /home/sc/Repository/qm/qm/test/context.py,v
retrieving revision 1.13
diff -c -5 -p -r1.13 context.py
*** qm/test/context.py	13 Nov 2003 03:08:01 -0000	1.13
--- qm/test/context.py	13 Nov 2003 03:48:20 -0000
*************** class Context(types.DictType):
*** 73,82 ****
--- 73,97 ----
          the command line.
  
      A 'Context' object is effectively a mapping object whose keys must
      be labels and values must be strings."""
  
+     DB_PATH_CONTEXT_PROPERTY = "qmtest.dbpath"
+     """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."""
+ 
+     ID_CONTEXT_PROPERTY = "qmtest.id"
+     """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."""
+     
      TMPDIR_CONTEXT_PROPERTY = "qmtest.tmpdir"
      """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
Index: qm/test/target.py
===================================================================
RCS file: /home/sc/Repository/qm/qm/test/target.py,v
retrieving revision 1.22
diff -c -5 -p -r1.22 target.py
*** qm/test/target.py	29 Aug 2003 22:59:22 -0000	1.22
--- qm/test/target.py	13 Nov 2003 03:48:20 -0000
*************** class Target(qm.extension.Extension):
*** 199,214 ****
          Derived classes may override this method."""
  
          # Create the result.
          result = Result(Result.TEST, descriptor.GetId())
          try:
!             # Augment the context with the tmpdir property.
              context = Context(context)
              context[context.TMPDIR_CONTEXT_PROPERTY] \
                  = self._GetTemporaryDirectory()
              # Set up any required resources.
              self.__SetUpResources(descriptor, context)
              # Run the test.
              descriptor.Run(context, result)
          except KeyboardInterrupt:
              result.NoteException(cause = "Interrupted by user.")
              # We received a KeyboardInterrupt, indicating that the
--- 199,218 ----
          Derived classes may override this method."""
  
          # Create the result.
          result = Result(Result.TEST, descriptor.GetId())
          try:
!             # Augment the context appropriately.
              context = Context(context)
              context[context.TMPDIR_CONTEXT_PROPERTY] \
                  = self._GetTemporaryDirectory()
+             context[context.DB_PATH_CONTEXT_PROPERTY] \
+                 = descriptor.GetDatabase().GetPath()
              # Set up any required resources.
              self.__SetUpResources(descriptor, context)
+             # Make the ID of the test available.
+             context[context.ID_CONTEXT_PROPERTY] = descriptor.GetId()
              # Run the test.
              descriptor.Run(context, result)
          except KeyboardInterrupt:
              result.NoteException(cause = "Interrupted by user.")
              # We received a KeyboardInterrupt, indicating that the
*************** class Target(qm.extension.Extension):
*** 302,311 ****
--- 306,318 ----
  
          # The temporary directory is not be preserved; there is no
          # guarantee that it will be the same in a test that depends on
          # this resource as it was in the resource itself.
          del properties[Context.TMPDIR_CONTEXT_PROPERTY]
+         # Similarly, the ID property should be the name of the dependent
+         # entity, not the name of the reosurce.
+         del properties[Context.ID_CONTEXT_PROPERTY]
          rop = (resource, result.GetOutcome(), properties)
          self.__resources[result.GetId()] = rop
          return rop
  
  
*************** class Target(qm.extension.Extension):
*** 360,369 ****
--- 367,378 ----
          # Get the resource descriptor.
          try:
              resource_desc = self.GetDatabase().GetResource(resource_name)
              # Set up the resources on which this resource depends.
              self.__SetUpResources(resource_desc, wrapper)
+             # Make the ID of the resource available.
+             wrapper[Context.ID_CONTEXT_PROPERTY] = resource_name
              # Set up the resource itself.
              resource_desc.SetUp(wrapper, result)
              # Obtain the resource within the try-block so that if it
              # cannot be obtained the exception is handled below.
              resource = resource_desc.GetItem()


More information about the qmtest mailing list