Re: [Python-Dev] cpython: Fix closes Issue11281 - smtplib.STMP gets source_address parameter, which adds

2011-07-30 Thread Antoine Pitrou

Hi Senthil,

 +if source_address: self.source_address = source_address

Could you try to follow PEP 8?
(I know PEP 8 is not always followed in old code, but there's no reason
not to follow it in code that we add to the stdlib)

 +SMTP.__init__(self, host, port, local_hostname = local_hostname,
 +source_address = source_address)

Ditto here (and other similar occurrences).

 +def testSourceAddress(self):
 +# connect
 +smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', 
 timeout=3,
 +source_address=('127.0.0.1', 19876))
 +self.assertEqual(smtp.source_address, ('127.0.0.1', 19876))
 +self.assertEqual(smtp.local_hostname, 'localhost')

Unless this test is also using some kind of mock socket (it doesn't
seem to), this can break as soon as port 19876 is already in use.
There are utilities in test.support to help with this, such as
bind_port() or (less reliable) find_unused_port().

Actually, this can be triggered quite easily by running the test a
couple of times in parallel:

$ ./python -m test -m testSourceAddress -Fv -j3 test_smtplib

[...]

[ 14/4] test_smtplib
testSourceAddress (test.test_smtplib.GeneralTests) ... ok
testSourceAddress (test.test_smtplib.DebuggingServerTests) ... ERROR

==
ERROR: testSourceAddress (test.test_smtplib.DebuggingServerTests)
--
Traceback (most recent call last):
  File /home/antoine/cpython/default/Lib/test/test_smtplib.py, line
220, in testSourceAddress source_address=('127.0.0.1', 19876))
  File /home/antoine/cpython/default/Lib/smtplib.py, line 238, in
__init__ (code, msg) = self.connect(host, port)
  File /home/antoine/cpython/default/Lib/smtplib.py, line 313, in
connect self.sock = self._get_socket(host, port, self.timeout)
  File /home/antoine/cpython/default/Lib/smtplib.py, line 287, in
_get_socket self.source_address)
  File /home/antoine/cpython/default/Lib/socket.py, line 407, in
create_connection raise err
  File /home/antoine/cpython/default/Lib/socket.py, line 397, in
create_connection sock.bind(source_address)
socket.error: [Errno 98] Address already in use

--


 +print(dir(smtp))

Usually, we avoid printing anything in tests, except when
support.verbose is True.

Regards

Antoine.


___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] cpython: Fix closes Issue11281 - smtplib.STMP gets source_address parameter, which adds

2011-07-30 Thread Senthil Kumaran
Hello Antoine,

On Sat, Jul 30, 2011 at 08:46:00AM +0200, Antoine Pitrou wrote:

 (I know PEP 8 is not always followed in old code, but there's no reason
 not to follow it in code that we add to the stdlib)
 

Thanks for pointing out. I somehow overlooked it. I shall refactor
that lib.


 Unless this test is also using some kind of mock socket (it doesn't
 seem to), this can break as soon as port 19876 is already in use.

Yes, there is one test which does not follow the mock socket and had
not realized this it may break when run in parallel (and 19876 is
use). Shall use the test facilities which are provided to resolve
(/synchronize) that condition.

  +print(dir(smtp))

:-) That's was definitely my unintentional mistake. Funny that when I
ran the individual tests a couple of times, I did not see that
remaining and hard to see it when run the entire suite. Should
be removed.

-- 
Senthil
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com