Skip to content

Commit

Permalink
Fix deprecation warnings (#17)
Browse files Browse the repository at this point in the history
* Drop support for Python 3.4.

Its test cannot be run any more because `zope.testrunner` no longer supports
Python 3.4
  • Loading branch information
Michael Howitz committed Apr 5, 2019
1 parent 4607802 commit 8f7b7e0
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 29 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[run]
source = zope.tales
plugins = coverage_python_version
omit =
*/flycheck_*py

Expand Down
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: python
python:
- 2.7
- 3.4
- 3.5
- 3.6
- pypy
Expand All @@ -14,7 +13,7 @@ matrix:
dist: xenial
install:
- pip install -U pip setuptools
- pip install -U coverage coveralls
- pip install -U coverage coverage-python-version coveralls
- pip install -U -e .[test]
script:
- coverage run -m zope.testrunner --test-path=src
Expand Down
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
Changes
=========

4.4 (unreleased)
5.0 (unreleased)
================

- Drop support for Python 3.4.

- Fix test failures and deprecation warnings occurring when using Python 3.8a1.
(`#15 <https://github.com/zopefoundation/zope.tales/pull/15>`_)

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def read(*rnames):
]

setup(name='zope.tales',
version='4.4.dev0',
version='5.0.dev0',
author='Zope Foundation and Contributors',
author_email='zope-dev@zope.org',
description='Zope Template Application Language Expression Syntax '
Expand All @@ -52,7 +52,6 @@ def read(*rnames):
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
Expand All @@ -68,6 +67,7 @@ def read(*rnames):
packages=find_packages('src'),
package_dir={'': 'src'},
namespace_packages=['zope'],
python_requires='>=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*',
extras_require={
'test': TESTS_REQUIRE,
'tal': [
Expand Down
2 changes: 1 addition & 1 deletion src/zope/tales/tales.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

try:
from html import escape
except ImportError:
except ImportError: # pragma: PY2
from cgi import escape

from zope.interface import implementer
Expand Down
13 changes: 11 additions & 2 deletions src/zope/tales/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
#
# This file is necessary to make this directory a package.
import six
import unittest


class TestCase(unittest.TestCase):
"""Base test case for Python version compatibility."""

if six.PY2: # pragma: PY2
# Avoid DeprecationWarning for assertRaisesRegexp on Python 3 while
# coping with Python 2 not having the Regex spelling variant
assertRaisesRegex = unittest.TestCase.assertRaisesRegexp
22 changes: 9 additions & 13 deletions src/zope/tales/tests/test_expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
##############################################################################
"""Default TALES expression implementations tests.
"""
import sys
import six
import unittest

from zope.tales.engine import Engine
from zope.tales.interfaces import ITALESFunctionNamespace
from zope.tales.tales import Undefined
from zope.interface import implementer
import zope.tales.tests

text_type = str if str is not bytes else unicode

PY3 = sys.version_info[0] == 3

class Data(object):

Expand Down Expand Up @@ -60,7 +60,7 @@ class OldStyleCallable: # NOT object

pass

class ExpressionTestBase(unittest.TestCase):
class ExpressionTestBase(zope.tales.tests.TestCase):

def setUp(self):
# Test expression compilation
Expand Down Expand Up @@ -94,7 +94,6 @@ def setUp(self):

self.py3BrokenEightBits = "a b'd\\xc3\\xa9j\\xc3\\xa0 vu'"


def _compiled_expr(self, expr):
return self.engine.compile(expr) if isinstance(expr, str) else expr

Expand All @@ -110,7 +109,7 @@ def _check_evals_to_instance(self, expr, result_kind):

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)
Expand All @@ -119,8 +118,7 @@ def _check_raises_compiler_error(self, expr_str, regex=None):
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)


Expand Down Expand Up @@ -178,8 +176,7 @@ def testBadInitalDynamic(self):

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):
Expand Down Expand Up @@ -223,7 +220,7 @@ def testString8Bits(self):
# Simple eight bit string interpolation should just work.
# Except on Py3, where we really mess it up.
expr = self.engine.compile('string:a ${eightBits}')
expected = 'a ' + self.context.vars['eightBits'] if not PY3 else self.py3BrokenEightBits
expected = 'a ' + self.context.vars['eightBits'] if not six.PY3 else self.py3BrokenEightBits
self._check_evals_to(expr, expected)

def testStringUnicode(self):
Expand All @@ -242,7 +239,7 @@ def testStringFailureWhenMixed(self):
result = expr(self.context)
# If we get here, we're on Python 3, which handles this
# poorly.
self.assertTrue(PY3)
self.assertTrue(six.PY3)
self.assertEqual(result, self.py3BrokenEightBits)
self.context.vars['eightBits'].decode('ascii') # raise UnicodeDecodeError

Expand Down Expand Up @@ -476,8 +473,7 @@ def testPathOnFunction(self):

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):
Expand Down
12 changes: 6 additions & 6 deletions src/zope/tales/tests/test_tales.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from zope.tales import tales
from zope.tales.tests.simpleexpr import SimpleExpr
from zope.testing import renormalizing
import zope.tales.tests


class TestIterator(unittest.TestCase):
Expand Down Expand Up @@ -122,7 +123,6 @@ def test_context_createErrorInfo(self):
self.assertEqual(ei.type, Exception)
self.assertEqual(ei.value, e)


def testVariables(self):
# Test variables
ctxt = self.getContext()
Expand Down Expand Up @@ -150,20 +150,20 @@ def testVariables(self):

ctxt.endScope()

class TestExpressionEngine(unittest.TestCase):
class TestExpressionEngine(zope.tales.tests.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())
Expand Down
5 changes: 3 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
envlist =
py27,py34,py35,py36,py37,py38,pypy,pypy3,coverage,docs
py27,py35,py36,py37,py38,pypy,pypy3,coverage,docs

[testenv]
commands =
Expand All @@ -14,10 +14,11 @@ 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
coverage-python-version

[testenv:docs]
basepython =
Expand Down

0 comments on commit 8f7b7e0

Please sign in to comment.