[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Fix python3 testing regression
commit d1284e6d0301de59ddf286b5e799dee50a5d4a5a
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Wed Aug 8 16:08:06 2018 -0700
Fix python3 testing regression
The addition of assertRaisesWith is causing unit test failures with python3...
======================================================================
FAIL: test_pack
----------------------------------------------------------------------
ValueError: b'\x00\x12' is the wrong size for a BAD_SIZE field
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/atagar/Desktop/stem/test/unit/client/size.py", line 29, in test_pack
self.assertRaisesWith(ValueError, "'\\x00\\x12' is the wrong size for a BAD_SIZE field", bad_size.pack, 18)
File "/home/atagar/Desktop/stem/stem/util/test_tools.py", line 280, in assertRaisesWith
return self.assertRaisesRegexp(exc_type, '^%s$' % re.escape(exc_msg), func, *args, **kwargs)
File "/home/atagar/Desktop/stem/stem/util/test_tools.py", line 290, in assertRaisesRegexp
return super(original_type, self).assertRaisesRegexp(exc_type, exc_msg, func, *args, **kwargs)
AssertionError: "^\'\\x00\\x12\'\ is\ the\ wrong\ size\ for\ a\ BAD_SIZE\ field$" does not match "b'\x00\x12' is the wrong size for a BAD_SIZE field"
----------------------------------------------------------------------
Trouble is that b'' prefix added to byte representations in python3. That's
fine, I don't mind if it's in the message or not so simply going back to our
prior assertion.
---
test/unit/client/size.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/test/unit/client/size.py b/test/unit/client/size.py
index ea08a0d5..eebe3619 100644
--- a/test/unit/client/size.py
+++ b/test/unit/client/size.py
@@ -2,6 +2,7 @@
Unit tests for stem.client.Size.
"""
+import re
import unittest
from stem.client.datatype import Size
@@ -26,7 +27,7 @@ class TestSize(unittest.TestCase):
self.assertRaisesWith(ValueError, 'Size.pack encodes an integer, but was a str', Size.CHAR.pack, 'hi')
bad_size = Size('BAD_SIZE', 1, '!H')
- self.assertRaisesWith(ValueError, "'\\x00\\x12' is the wrong size for a BAD_SIZE field", bad_size.pack, 18)
+ self.assertRaisesRegexp(ValueError, re.escape("'\\x00\\x12' is the wrong size for a BAD_SIZE field"), bad_size.pack, 18)
def test_unpack(self):
self.assertEqual(18, Size.CHAR.unpack(b'\x12'))
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits