Package qm :: Package test :: Module runnable
[hide private]
[frames] | no frames]

Source Code for Module qm.test.runnable

  1  ######################################################################## 
  2  # 
  3  # File:   runnable.py 
  4  # Author: Mark Mitchell 
  5  # Date:   10/11/2002 
  6  # 
  7  # Contents: 
  8  #   QMTest Runnable class. 
  9  # 
 10  # Copyright (c) 2002, 2003 by CodeSourcery, LLC.  All rights reserved.  
 11  # 
 12  # For license terms see the file COPYING. 
 13  # 
 14  ######################################################################## 
 15   
 16  ######################################################################## 
 17  # Imports 
 18  ######################################################################## 
 19   
 20  import qm 
 21  import qm.extension 
 22  from   qm.fields import AttachmentField, TupleField, SetField 
 23   
 24  ######################################################################## 
 25  # Classes 
 26  ######################################################################## 
 27   
28 -class Runnable(qm.extension.Extension):
29 """A 'Runnable' can run on a 'Target'. 30 31 'Runnable' is an abstract base class for 'Test' and 'Resource'.""" 32
33 - class ResourceField(qm.fields.ChoiceField):
34 """A 'ResourceField' contains the name of a resource. 35 36 The exact format of the name depends on the test database in use.""" 37
38 - def GetItems(self):
42 43 44 45 EXTRA_ID = "qmtest_id" 46 """The name of the extra keyword argument to '__init__' that 47 specifies the name of the test or resource.""" 48 49 EXTRA_DATABASE = "qmtest_database" 50 """The name of the extra keyword argument to '__init__' that 51 specifies the database containing the test or resource.""" 52 53 RESOURCE_FIELD_ID = "resources" 54 """The name of the field that contains the resources on which this 55 test or resource depends.""" 56 57 arguments = [ 58 qm.fields.SetField( 59 ResourceField( 60 name = RESOURCE_FIELD_ID, 61 title = "Resources", 62 description = \ 63 """Resources on which this test or resource depends. 64 65 Before this test or resource is executed, the 66 resources on which it depends will be set up.""", 67 not_empty_text = "true", 68 )), 69 ] 70 71
72 - def __init__(self, arguments = None, **args):
73 """Construct a new 'Runnable'. 74 75 'arguments' -- As for 'Extension.__init__'. 76 77 'args' -- As for 'Extension.__init__.""" 78 79 self.__id = args.pop(self.EXTRA_ID) 80 self.__database = args.pop(self.EXTRA_DATABASE) 81 if arguments: args.update(arguments) 82 super(Runnable, self).__init__(**args)
83 84 85
86 - def GetId(self):
87 """Return the name of this test or resource. 88 89 'context' -- The 'Context' in which this entity is running. 90 91 returns -- The name of this test or resource.""" 92 93 return self.__id
94 95
96 - def GetDatabase(self):
97 """Return the 'Database' in which this test or resource is stored. 98 99 returns -- The 'Database' in which this test or resource is 100 stored.""" 101 102 return self.__database
103 104
105 - def GetAttachments(self):
106 """Return the 'Attachment's to this 'Runnable'. 107 108 returns -- A sequence consisting of the 'Attachment' objects 109 associated with this runnable.""" 110 111 attachments = [] 112 for f in qm.extension.get_class_arguments(self.__class__): 113 self.__GetAttachments(f, 114 getattr(self, f.GetName()), 115 attachments) 116 return attachments
117 118
119 - def __GetAttachments(self, field, value, attachments):
120 """Return the 'Attachments' that are part of 'field'. 121 122 'field' -- The 'Field' being examined. 123 124 'value' -- The value of that 'Field' in 'self'. 125 126 'attachments' -- A sequence consisting of the attachments 127 found so far. Additional 'Attachment's are appended to this 128 sequence by this function.""" 129 130 if isinstance(field, AttachmentField): 131 attachments.append(getattr(self, field.GetName())) 132 elif isinstance(field, TupleField): 133 subfields = field.GetSubfields() 134 for i in xrange(len(subfields)): 135 self.__GetAttachments(subfields[i], value[i], 136 attachments) 137 elif isinstance(field, SetField): 138 subfield = field.GetSubfields()[0] 139 for i in xrange(len(value)): 140 self.__GetAttachments(subfield, value[i], 141 attachments) 142 143 return
144