Skip to content

Commit

Permalink
Make tests future proof.
Browse files Browse the repository at this point in the history
  • Loading branch information
sallner committed Oct 5, 2018
1 parent 24b994f commit 76d6ba4
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/DocumentTemplate/tests/test_DT_Try.py
Expand Up @@ -7,12 +7,19 @@
class DT_Try_Tests(unittest.TestCase):
"""Testing ..DT_Try.Try."""

def _get_doc_class(self):
def assertRaisesRegex(self, *args, **kw):
try:
# available from Python 3.2
return unittest.TestCase.assertRaisesRegex(self, *args, **kw)
except AttributeError:
# only available till Python 3.7
return unittest.TestCase.assertRaisesRegexp(self, *args, **kw)

@property
def doc_class(self):
from DocumentTemplate.DT_HTML import HTML
return HTML

doc_class = property(_get_doc_class,)

def test_DT_Try__Try____init__1(self):
"""It allows only one else block."""
html = self.doc_class(
Expand All @@ -24,7 +31,7 @@ def test_DT_Try__Try____init__1(self):
'<dtml-else>'
'<dtml-var expr="str(110)">'
'</dtml-try>')
with self.assertRaisesRegexp(ParseError, '^No more than one else '):
with self.assertRaisesRegex(ParseError, '^No more than one else '):
html()

def test_DT_Try__Try____init__2(self):
Expand All @@ -36,7 +43,7 @@ def test_DT_Try__Try____init__2(self):
'<dtml-var expr="str(100)">'
'<dtml-except>'
'</dtml-try>')
with self.assertRaisesRegexp(
with self.assertRaisesRegex(
ParseError, '^The else block should be the last '):
html()

Expand All @@ -49,7 +56,7 @@ def test_DT_Try__Try____init__3(self):
'<dtml-finally>'
'<dtml-var expr="str(100)">'
'</dtml-try>')
with self.assertRaisesRegexp(
with self.assertRaisesRegex(
ParseError, '^A try..finally combination cannot '):
html()

Expand All @@ -63,7 +70,7 @@ def test_DT_Try__Try____init__4(self):
'<dtml-except>'
'<dtml-var expr="str(110)">'
'</dtml-try>')
with self.assertRaisesRegexp(
with self.assertRaisesRegex(
ParseError, '^Only one default exception handler '):
html()

Expand Down

0 comments on commit 76d6ba4

Please sign in to comment.