Merge lp://staging/~jml/testtools/extract-factory into lp://staging/~testtools-committers/testtools/trunk
Status: | Needs review |
---|---|
Proposed branch: | lp://staging/~jml/testtools/extract-factory |
Merge into: | lp://staging/~testtools-committers/testtools/trunk |
Diff against target: |
278 lines (+132/-15) 7 files modified
NEWS (+7/-0) doc/for-test-authors.rst (+16/-8) testtools/__init__.py (+2/-0) testtools/factory.py (+48/-0) testtools/testcase.py (+10/-7) testtools/tests/__init__.py (+2/-0) testtools/tests/test_factory.py (+47/-0) |
To merge this branch: | bzr merge lp://staging/~jml/testtools/extract-factory |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Robert Collins | Approve | ||
Review via email: mp+85833@code.staging.launchpad.net |
Description of the change
This branch follows the advice that I recall receiving from Rob ages ago: it extracts a separate factory class out of TestCase.
It's fairly straightforward, but there are a few questions that came to mind while I was doing the work:
testtools/
XXX: Are we happy with the name ObjectFactory?
testtools/
XXX: Is this a good opportunity to change the getUniqueInteger and
getUniqueString methods here to be get_unique_integer and get_unique_string?
testtools/
XXX: We could have a class variable factory_factory (except with a
better name) and then instead write:
self.factory = self.factory_
Which would allow others to plugin in their factories more easily,
rather than using the TestCaseWithFactory mixin pattern. Just a
thought.
Would be interested in opinions.
jml
Unmerged revisions
- 242. By Jonathan Lange
-
Unexpose TestCase.factory, and recommend that people use ObjectFactory for themselves.
- 241. By Jonathan Lange
-
Documentation update.
- 240. By Jonathan Lange
-
News.
- 239. By Jonathan Lange
-
Some thoughts on options
Deprecation
Expose ObjectFactory at the top-level. - 238. By Jonathan Lange
-
Use ObjectFactory rather than implementing it ourselves.
- 237. By Jonathan Lange
-
Extract out a factory.
Does the factory need to be exposed at all?
On 15/12/2011 10:19 PM, "Jonathan Lange" <email address hidden> wrote:
Jonathan Lange has proposed merging lp:~jml/testtools/extract-factory into
lp:testtools.
Requested ...
Your team testtools developers is subscribed to branch lp:testtools.
=== modified file 'NEWS'
--- NEWS 2011-12-05 15:33:37 +0000
+++ NEWS 2011-12-15 11:18:22 +0000
@@ -14,6 +14,14 @@
``MatchesAll`` with keyword arguments, then this change might affect your
test results. (Jonathan Lange)
+* ``TestCase`` now has a ``factory`` attribute, set to an instance of getUniqueIntege r`` and ``TestCase. getUniqueString `` are now factory. getUniqueIntege r`` and factory. getUniqueString `` instead. (Jonathan Lange)
+ ``ObjectFactory``. It now uses this instance for generating unique
strings
+ and integers. (Jonathan Lange)
+
+* ``TestCase.
+ deprecated. Use ``TestCase.
+ ``TestCase.
+
Improvements
------------
=== modified file 'doc/for- test-authors. rst' test-authors. rst 2011-12-07 11:32:45 +0000 test-authors. rst 2011-12-15 11:18:22 +0000
--- doc/for-
+++ doc/for-
@@ -1240,17 +1240,19 @@
fine. However, sometimes it's useful to be able to create arbitrary
objects
at will, without having to make up silly sample data.
-To help with this, ``testtools. TestCase` ` implements creation methods ing`` and ``getUniqueInte ger``. They return strings and ing`` is used instead of saying "foo" or "bar" or whatever:: TestCase` ` comes with an ``ObjectFactory`` ger``. They return strings and integers that are unique
called
-``getUniqueStr
-integers that are unique within the context of the test that can be used to
-assemble more complex objects. Here's a basic example where
-``getUniqueStr
+To help with this, ``testtools.
that
+you can access as the ``factory`` attribute within your test
+case. ``ObjectFactory`` implements creation methods called
``getUniqueString``
+and ``getUniqueInte
+within the context of the test that can be used to assemble more complex
+objects. Here's a basic example where ``getUniqueString`` is used instead
of
+saying "foo" or "bar" or whatever::
class SomeTest(TestCase):
def test_full_ name(self) : tring() tring() getUniqueString () getUniqueString ()
self. assertEqual( p.full_ name, "%s %s" % (first_name, last_name))
- first_name = self.getUniqueS
- last_name = self.getUniqueS
+ first_name = self.factory.
+ last_name = self.factory.
p = Person(first_name, last_name)
@@ -1260,13 +1262,15 @@ (TestCase) :
class TestCoupleLogic
def make_arbitrary_ person( self): self.getUniqueS tring() , self.getUniqueS tring() ) getUniqueString (), getUniqueString ())
- return Person(
+ return Person(
+ self.factory.
+ self.factory.
def test_get_ invitation( self): arbitrary_ person( ) arbitrary_ person( ) tring() getUniqueString ()
invitation = couple. get_invitation( event_name)
self. assertEqual(
invitation,
a = self.make_
b = self.make_
couple = Couple(a, b)
- event_name = self.getUniqueS
+ event_name = self.factory.
=== modified file 'testtools/ __init_ ...