summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Howitz <mh@gocept.com>2019-03-22 08:27:52 +0100
committerMichael Howitz <mh@gocept.com>2019-03-22 08:27:52 +0100
commit7cf341b8faa8afe75eeb47f49cc12333c8c2d2da (patch)
tree14c1bf86597ac23decddc36a9e91231153200bc2
parent31442f369747eac6473cef1f62cf70030b436db6 (diff)
downloadzope-tales-7cf341b8faa8afe75eeb47f49cc12333c8c2d2da.tar.gz
Fix deprecation warnings.
-rw-r--r--src/zope/tales/testing.py12
-rw-r--r--src/zope/tales/tests/test_expressions.py13
-rw-r--r--src/zope/tales/tests/test_tales.py11
-rw-r--r--tox.ini2
4 files changed, 24 insertions, 14 deletions
diff --git a/src/zope/tales/testing.py b/src/zope/tales/testing.py
new file mode 100644
index 0000000..1bb3c4e
--- /dev/null
+++ b/src/zope/tales/testing.py
@@ -0,0 +1,12 @@
+import six
+import unittest
+
+
+class TestCase(unittest.TestCase):
+ """Base test case for Python version compatibility."""
+
+ if six.PY2: # pragma: no cover
+ # Avoid DeprecationWarning for assertRaisesRegexp on Python 3 while
+ # coping with Python 2 not having the Regex spelling variant
+ assertRaisesRegex = getattr(unittest.TestCase, 'assertRaisesRegex',
+ unittest.TestCase.assertRaisesRegexp)
diff --git a/src/zope/tales/tests/test_expressions.py b/src/zope/tales/tests/test_expressions.py
index bc820cf..0ff2b2c 100644
--- a/src/zope/tales/tests/test_expressions.py
+++ b/src/zope/tales/tests/test_expressions.py
@@ -60,7 +60,7 @@ class OldStyleCallable: # NOT object
pass
-class ExpressionTestBase(unittest.TestCase):
+class ExpressionTestBase(zope.tales.testing.TestCase):
def setUp(self):
# Test expression compilation
@@ -110,7 +110,7 @@ class ExpressionTestBase(unittest.TestCase):
def _check_raises_compiler_error(self, expr_str, regex=None):
from zope.tales.tales import CompilerError
- meth = self.assertRaises if regex is None else self.assertRaisesRegexp
+ meth = self.assertRaises if regex is None else self.assertRaisesRegex
args = (regex,) if regex is not None else ()
with meth(CompilerError, *args) as exc:
self.engine.compile(expr_str)
@@ -119,8 +119,7 @@ class ExpressionTestBase(unittest.TestCase):
def _check_subexpr_raises_compiler_error(self, expr, regexp):
from zope.tales.expressions import SubPathExpr
from zope.tales.tales import CompilerError
- with self.assertRaisesRegexp(CompilerError,
- regexp):
+ with self.assertRaisesRegex(CompilerError, regexp):
SubPathExpr(expr, None, self.engine)
@@ -178,8 +177,7 @@ class TestParsedExpressions(ExpressionTestBase):
def test_dynamic_invalid_variable_name(self):
from zope.tales.tales import CompilerError
- with self.assertRaisesRegexp(CompilerError,
- "Invalid variable name"):
+ with self.assertRaisesRegex(CompilerError, "Invalid variable name"):
self.engine.compile('path:a/?123')
def testOldStyleClassIsCalled(self):
@@ -476,8 +474,7 @@ class FunctionTests(ExpressionTestBase):
def test_path_through_non_callable_nampspace(self):
expr = self.engine.compile('adapterTest/not_callable_ns:nope')
- with self.assertRaisesRegexp(ValueError,
- 'None'):
+ with self.assertRaisesRegex(ValueError, 'None'):
expr(self.context)
class TestSimpleModuleImporter(unittest.TestCase):
diff --git a/src/zope/tales/tests/test_tales.py b/src/zope/tales/tests/test_tales.py
index 356413c..591bf87 100644
--- a/src/zope/tales/tests/test_tales.py
+++ b/src/zope/tales/tests/test_tales.py
@@ -21,6 +21,7 @@ import six
from zope.tales import tales
from zope.tales.tests.simpleexpr import SimpleExpr
from zope.testing import renormalizing
+import zope.tales.testing
class TestIterator(unittest.TestCase):
@@ -150,20 +151,20 @@ class TALESTests(unittest.TestCase):
ctxt.endScope()
-class TestExpressionEngine(unittest.TestCase):
+class TestExpressionEngine(zope.tales.testing.TestCase):
def setUp(self):
self.engine = tales.ExpressionEngine()
def test_register_invalid_name(self):
- with self.assertRaisesRegexp(tales.RegistrationError,
- "Invalid base name"):
+ with self.assertRaisesRegex(tales.RegistrationError,
+ "Invalid base name"):
self.engine.registerBaseName('123', None)
def test_register_duplicate_name(self):
self.engine.registerBaseName('abc', 123)
- with self.assertRaisesRegexp(tales.RegistrationError,
- "Multiple registrations"):
+ with self.assertRaisesRegex(tales.RegistrationError,
+ "Multiple registrations"):
self.engine.registerBaseName('abc', None)
self.assertEqual({'abc': 123}, self.engine.getBaseNames())
diff --git a/tox.ini b/tox.ini
index 526027d..07ba40a 100644
--- a/tox.ini
+++ b/tox.ini
@@ -14,7 +14,7 @@ basepython =
python3.7
commands =
coverage run -m zope.testrunner --test-path=src []
- coverage report --fail-under=100
+ coverage report --show-missing --fail-under=100
deps =
{[testenv]deps}
coverage