1688
1689
return super(ExtendedToStreamDecorator, self).wasSuccessful()
1692
class ResourcedToStreamDecorator(ExtendedToStreamDecorator):
1693
"""Report ``testresources``-related activity to StreamResult objects.
1695
Implement the resource lifecycle TestResult protocol extension supported
1696
by the ``testresources.TestResourceManager`` class. At each stage of a
1697
resource's lifecycle, a stream event with relevant details will be
1700
Each stream event will have its test_id field set to the resource manager's
1701
identifier (see ``testresources.TestResourceManager.id()``) plus the method
1702
being executed (either 'make' or 'clean').
1704
The test_status will be either 'inprogress' or 'success'.
1706
The runnable flag will be set to False.
1709
def startMakeResource(self, resource):
1710
self._convertResourceLifecycle(resource, 'make', 'start')
1712
def stopMakeResource(self, resource):
1713
self._convertResourceLifecycle(resource, 'make', 'stop')
1715
def startCleanResource(self, resource):
1716
self._convertResourceLifecycle(resource, 'clean', 'start')
1718
def stopCleanResource(self, resource):
1719
self._convertResourceLifecycle(resource, 'clean', 'stop')
1721
def _convertResourceLifecycle(self, resource, method, phase):
1722
"""Convert a resource lifecycle report to a stream event."""
1724
# If the resource implements the TestResourceManager.id() API, let's
1725
# use it, otherwise fallback to the class name.
1726
if safe_hasattr(resource, "id"):
1727
resource_id = resource.id()
1729
resource_id = "%s.%s" % (
1730
resource.__class__.__module__, resource.__class__.__name__)
1732
test_id = '%s.%s' % (resource_id, method)
1734
if phase == 'start':
1735
test_status = 'inprogress'
1737
test_status = 'success'
1740
test_id=test_id, test_status=test_status, runnable=False,
1741
timestamp=self._now())
1691
1744
class StreamToExtendedDecorator(StreamResult):
1692
1745
"""Convert StreamResult API calls into ExtendedTestResult calls.