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

[tor-commits] [stem/master] Support assertRaisesRegexp with python 2.6



commit 3bb6377b83890c42061ca50b5e91c2b99be56df0
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Mon Mar 13 08:50:39 2017 -0700

    Support assertRaisesRegexp with python 2.6
    
    Python 2.7 added assertRaisesRegexp so until we drop support for 2.6 we'll need
    to provide it.
---
 stem/util/test_tools.py | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/stem/util/test_tools.py b/stem/util/test_tools.py
index 0d70dc7..b75c4d0 100644
--- a/stem/util/test_tools.py
+++ b/stem/util/test_tools.py
@@ -27,6 +27,7 @@ import re
 import time
 import unittest
 
+import stem.prereq
 import stem.util.conf
 import stem.util.system
 
@@ -70,6 +71,17 @@ class TimedTestRunner(unittest.TextTestRunner):
           TEST_RUNTIMES[self.id()] = time.time() - start_time
           return result
 
+        # TODO: remove when dropping python 2.6 support
+
+        def assertRaisesRegexp(self, exc_type, exc_msg, func, *args, **kwargs):
+          if stem.prereq._is_python_26():
+            try:
+              func(*args, **kwargs)
+            except exc_type as exc:
+              self.assertTrue(re.match(exc_msg, str(exc)))
+          else:
+            return super(original_type, self).assertRaisesRegexp(exc_type, exc_msg, func, *args, **kwargs)
+
         def id(self):
           return '%s.%s.%s' % (original_type.__module__, original_type.__name__, self._testMethodName)
 



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