[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Unit tests for connection.connect failed under python 3.x



commit d2171dc632d6c89f56c148bab1df282633dfd04b
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sun Aug 17 13:49:57 2014 -0700

    Unit tests for connection.connect failed under python 3.x
    
    Weird oddity with how StringIO works with python 3.x. This is a new regression
    after reinstalling my system so probably specific to the version of python 3.x
    I'm using.
---
 test/unit/connection/connect.py |   12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/test/unit/connection/connect.py b/test/unit/connection/connect.py
index 95edea0..0cc5ee4 100644
--- a/test/unit/connection/connect.py
+++ b/test/unit/connection/connect.py
@@ -69,9 +69,19 @@ class TestConnect(unittest.TestCase):
     if result is not None:
       self.fail()
 
+    # Python 3.x seems to have an oddity where StringIO has prefixed null
+    # characters (\x00) after we call truncate(). This could be addressed
+    # a couple ways...
+    #
+    #   * Don't use a stdout mock more than once.
+    #   * Strip the null characters.
+    #
+    # Opting for the second (which is admittedly a hack) so the tests are a
+    # little nicer.
+
     stdout_output = stdout_mock.getvalue()
     stdout_mock.truncate(0)
-    self.assertEqual(msg, stdout_output.strip())
+    self.assertEqual(msg, stdout_output.strip().lstrip('\x00'))
 
   @patch('stem.connection.authenticate')
   def test_auth_success(self, authenticate_mock):



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits