[Zope3-dev] Re: [Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Services/SmtpService/Views - __init__.py:1.1 configure.zcml:1.1

Fred L. Drake, Jr. fred@zope.com
Mon, 28 Oct 2002 10:36:08 -0500


Jim Fulton writes:
 > Right. This would require hacking sys.modules.

Only if we can be sure that happens before
Zope.App.OFS.Services.SmtpService is imported, which seems reasonable
only if we run that test in isolation (bad assumption).

I just took a look at the code, and it looks like replacing the SMTP
class imported into the SmtpService's globals during the test is the
most reasonable way to go; the SmtpService code should include a
comment that the tests rely on the use of that global, so if the
implementation needs to change, the tests will be revised
appropriately.

A little hackish, but it means the test can be written without
changing the API.

Steve Alexander writes:
 > However, in this case I think it makes sense to make the module allow 
 > for testing by giving it an API where you can choose how the name 
 > 'smtplib' is resolved.

Perhaps, but that's seems pretty hackish.

 > I don't see anything wrong with making allowances in the code to let it 
 > be tested, provided these allowances are not too intrusive.

Agreed.

Leonardo Rochael Almeida writes:
 > That's the spirit of XP's "test everything". Not all code can be easily
 > tested, but all code can be refactored in a way that makes it easy to
 > test.
 > 
 > I think the Python "default argument" feature helps a lot in this
 > regard.

This may well be an even better way; not sure.  The changes to
SmtpService certainly seem trivial enough, which is good.


  -Fred

-- 
Fred L. Drake, Jr.  <fred at zope.com>
PythonLabs at Zope Corporation