Suggestions for changes to resource interface
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
testresources |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
Having used testresources for a little while, I've been wondering if it'd make sense to change the API somewhat. The current TestResource.
The suggested API for TestResource authors would be:
make(
reset(
clean(resource)
To maintain compatibility with the existing code, a default implementation of reset() could be included that does something like:
def reset(self, resource, dependent_
if self._dirty:
return resource
For the testcase/testsuite side, the interface could look something like this:
getResource():
* If the resource has not been created yet, make it and its dependent resources.
* If the resource has been created and has been used by a test, call its reset() method. This would also need to reset dependent resources first, to be passed
* Increment the refcount and return the resource.
markUsed():
* mark the resource as having been used (as checked by the second point for getResource()).
* call markUsed() on all dependent resources.
finishedWith():
* decrement the ref count.
* If the ref count hits zero, clean() the resource and call finishedWith() on all dependent resources.
neededResources():
* as it is now.
This interface would be used as follows:
ResourcedTestCa
* call getResource() on each resource as is done now.
* call markUsed() on each resource.
ResourcedTestCa
* call finishedWith() on each resource as is done now.
OptimisingTestS
* behave as it does now.
I think this design would also fix bug 271257 and bug 271619.
Related branches
- Jonathan Lange (community): Needs Information
- Robert Collins: Pending requested
Changed in testresources: | |
status: | New → Incomplete |
I'm not sure I follow the difference. self._dirty is a memo, but wouldn't it be trivial to make that a property for some resources?
In terms of making it nicer for reuse we could have a query method to be called, which can ask the resource.