[Python-checkins] cpython: provide a common method to check for RETR_DATA validity, first checking the

giampaolo.rodola python-checkins at python.org
Mon Jan 9 17:10:21 CET 2012


http://hg.python.org/cpython/rev/53a5a5b8859d
changeset:   74308:53a5a5b8859d
user:        Giampaolo Rodola' <g.rodola at gmail.com>
date:        Mon Jan 09 17:10:10 2012 +0100
summary:
  provide a common method to check for RETR_DATA validity, first checking the expected len and then the actual data content; this way we get a failure on len mismatch rather than content mismatch (which is very long and unreadable)

files:
  Lib/test/test_ftplib.py |  18 ++++++++++--------
  1 files changed, 10 insertions(+), 8 deletions(-)


diff --git a/Lib/test/test_ftplib.py b/Lib/test/test_ftplib.py
--- a/Lib/test/test_ftplib.py
+++ b/Lib/test/test_ftplib.py
@@ -461,6 +461,10 @@
         self.client.close()
         self.server.stop()
 
+    def check_data(self, received, expected):
+        self.assertEqual(len(received), len(expected))
+        self.assertEqual(received, expected)
+
     def test_getwelcome(self):
         self.assertEqual(self.client.getwelcome(), '220 welcome')
 
@@ -542,7 +546,7 @@
             received.append(data.decode('ascii'))
         received = []
         self.client.retrbinary('retr', callback)
-        self.assertEqual(''.join(received), RETR_DATA)
+        self.check_data(''.join(received), RETR_DATA)
 
     def test_retrbinary_rest(self):
         def callback(data):
@@ -550,20 +554,17 @@
         for rest in (0, 10, 20):
             received = []
             self.client.retrbinary('retr', callback, rest=rest)
-            self.assertEqual(''.join(received), RETR_DATA[rest:],
-                             msg='rest test case %d %d %d' % (rest,
-                                                              len(''.join(received)),
-                                                              len(RETR_DATA[rest:])))
+            self.check_data(''.join(received), RETR_DATA[rest:])
 
     def test_retrlines(self):
         received = []
         self.client.retrlines('retr', received.append)
-        self.assertEqual(''.join(received), RETR_DATA.replace('\r\n', ''))
+        self.check_data(''.join(received), RETR_DATA.replace('\r\n', ''))
 
     def test_storbinary(self):
         f = io.BytesIO(RETR_DATA.encode('ascii'))
         self.client.storbinary('stor', f)
-        self.assertEqual(self.server.handler_instance.last_received_data, RETR_DATA)
+        self.check_data(self.server.handler_instance.last_received_data, RETR_DATA)
         # test new callback arg
         flag = []
         f.seek(0)
@@ -580,7 +581,7 @@
     def test_storlines(self):
         f = io.BytesIO(RETR_DATA.replace('\r\n', '\n').encode('ascii'))
         self.client.storlines('stor', f)
-        self.assertEqual(self.server.handler_instance.last_received_data, RETR_DATA)
+        self.check_data(self.server.handler_instance.last_received_data, RETR_DATA)
         # test new callback arg
         flag = []
         f.seek(0)
@@ -781,6 +782,7 @@
                 received.append(data.decode('ascii'))
             received = []
             self.client.retrbinary('retr', callback)
+            self.assertEqual(len(''.join(received)), len(RETR_DATA))
             self.assertEqual(''.join(received), RETR_DATA)
         self.client.set_pasv(True)
         retr()

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list