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