Merge lp:~mbp/testresources/doc into lp:~testresources-developers/testresources/trunk

Proposed by Martin Pool
Status: Merged
Merged at revision: 62
Proposed branch: lp:~mbp/testresources/doc
Merge into: lp:~testresources-developers/testresources/trunk
Diff against target: 101 lines (+21/-14)
1 file modified
README (+21/-14)
To merge this branch: bzr merge lp:~mbp/testresources/doc
Reviewer Review Type Date Requested Status
Robert Collins Approve
Review via email: mp+130895@code.launchpad.net

Description of the change

Hi,

I was using testresources and noticed a few unclear things in the readme - this fixes them.

Also, I was wondering how you would feel about a separate patch to add some specific managers, starting with the tempdir one.

thanks,
-m

To post a comment you must log in.
Revision history for this message
Robert Collins (lifeless) wrote :

Thanks for this, I shall look at it locally to see what the whitespace changes are and merge it.

I'd be happy to have specific managers that depend only on the standard library in testresources. For tempdir though, FixtureResource(fixtures.TempDir) should be all you need. Many things are probably best expressed as fixtures, not as resources + resource managers, and used via FixtureResource.

review: Approve
Revision history for this message
Martin Pool (mbp) wrote :

Maybe the testresources readme should mention fixtures too?

Revision history for this message
Martin Pool (mbp) wrote :

On 23 October 2012 07:44, Robert Collins <email address hidden> wrote:

> Review: Approve
>
> Thanks for this, I shall look at it locally to see what the whitespace
> changes are and merge it.
>
> I'd be happy to have specific managers that depend only on the standard
> library in testresources. For tempdir though,
> FixtureResource(fixtures.TempDir) should be all you need. Many things are
> probably best expressed as fixtures, not as resources + resource managers,
> and used via FixtureResource.
>
>
Could I persuade you to make a release with FixtureResource some time?

--
Martin

Revision history for this message
Robert Collins (lifeless) wrote :

On Thu, Oct 25, 2012 at 10:28 AM, Martin Pool <email address hidden> wrote:
> Maybe the testresources readme should mention fixtures too?

It should :)

Revision history for this message
Robert Collins (lifeless) wrote :

On Thu, Oct 25, 2012 at 10:43 AM, Martin Pool <email address hidden> wrote:

> Could I persuade you to make a release with FixtureResource some time?

Here's one I prepared earlier http://pypi.python.org/pypi/testresources :)

-Rob

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'README'
2--- README 2012-01-25 23:40:13 +0000
3+++ README 2012-10-22 20:32:27 +0000
4@@ -7,7 +7,7 @@
5 license at the users choice. A copy of both licenses are available in the
6 project source as Apache-2.0 and BSD. You may not use this file except in
7 compliance with one of these two licences.
8-
9+
10 Unless required by applicable law or agreed to in writing, software
11 distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
12 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13@@ -44,10 +44,10 @@
14 The basic idea of testresources is:
15
16 * Tests declare the resources they need in a ``resources`` attribute.
17-* When the test is run, the required resource objects are allocated (either
18+* When the test is run, the required resource objects are allocated (either
19 newly constructed, or reused), and assigned to attributes of the TestCase.
20
21-testresources distinguishes a 'resource manager' (a subclass of
22+testresources distinguishes a 'resource manager' (a subclass of
23 ``TestResourceManager``) which acts as a kind of factory, and a 'resource'
24 which can be any kind of object returned from the manager class's
25 ``getResource`` method.
26@@ -75,11 +75,11 @@
27 activated.
28
29 To declare the use of a resource, set the ``resources`` attribute to a list of
30-tuples of ``(attribute_name, resource_factory)``.
31+tuples of ``(attribute_name, resource_manager)``.
32
33 During setUp, for each declared requirement, the test gains an attribute
34 pointing to an allocated resource, which is the result of calling
35-``resource_factory.getResource()``. ``finishedWith`` will be called on each
36+``resource_manager.getResource()``. ``finishedWith`` will be called on each
37 resource during tearDown().
38
39 For example::
40@@ -103,16 +103,19 @@
41 overriding these methods:
42
43 ``make``
44- Must be overridden in every concrete subclass.
45+ Must be overridden in every concrete subclass.
46
47 Returns a new instance of the resource object
48- (the actual resource, not the TestResourceManager). Doesn't need to worry about
49- reuse, which is taken care of separately. This method is only called when a
50- new resource is definitely needed.
51+ (the actual resource, not the TestResourceManager). Doesn't need to worry about
52+ reuse, which is taken care of separately. This method is only called when a
53+ new resource is definitely needed.
54+
55+ ``make`` is called by ``getResource``; you should not normally need to override
56+ the latter.
57
58 ``clean``
59- Cleans up an existing resource instance, eg by deleting a directory or
60- closing a network connection. By default this does nothing, which may be
61+ Cleans up an existing resource instance, eg by deleting a directory or
62+ closing a network connection. By default this does nothing, which may be
63 appropriate for resources that are automatically garbage collected.
64
65 ``reset``
66@@ -121,7 +124,7 @@
67 faster way to reset them.
68
69 ``isDirty``
70- Check whether an existing resource is dirty. By default this just reports whether
71+ Check whether an existing resource is dirty. By default this just reports whether
72 ``TestResourceManager.dirtied`` has been called.
73
74 For instance::
75@@ -129,13 +132,13 @@
76 class TemporaryDirectoryResource(TestResourceManager):
77
78 def clean(self, resource):
79- osutils.rmtree(resource)
80+ shutil.rmtree(resource)
81
82 def make(self):
83 return tempfile.mkdtemp()
84
85 def isDirty(self, resource):
86- # Can't detect when the directory is written to, so assume it
87+ # Can't detect when the directory is written to, so assume it
88 # can never be reused. We could list the directory, but that might
89 # not catch it being open as a cwd etc.
90 return True
91@@ -235,6 +238,10 @@
92 declared statically, so that testresources can "smooth" resource usage across
93 several tests.
94
95+ But, you may be able to find some object that is statically declared and reusable
96+ to act as the resource, which can then provide methods to generate sub-elements
97+ of itself during a test.
98+
99 * If the resource is held inside the TestResourceManager object, and the
100 TestResourceManager is typically constructed inline in the test case
101 ``resources`` attribute, how can they be shared across different test

Subscribers

People subscribed via source and target branches