From 7bf80e0aca7d59128fd2f0add07a6ffef0128ea1 Mon Sep 17 00:00:00 2001 From: Jens Vagelpohl Date: Fri, 23 Apr 2021 10:18:53 +0200 Subject: [PATCH] - Fix several DeprecationWarnings during unit tests --- CHANGES.rst | 3 ++ buildout.cfg | 3 +- .../fake_skins/fake_skin/test_text.metadata | 2 + .../CMFCore/tests/test_ActionsTool.py | 37 +++++++++++-------- src/Products/CMFCore/tests/test_FSFile.py | 8 +++- 5 files changed, 35 insertions(+), 18 deletions(-) create mode 100644 src/Products/CMFCore/tests/fake_skins/fake_skin/test_text.metadata diff --git a/CHANGES.rst b/CHANGES.rst index a108967b..9da2e794 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,9 @@ Products.CMFCore Changelog 2.5.2 (unreleased) ------------------ +- Fix several DeprecationWarnings during unit tests + (`#112 `_) + - Set Cache-Control header in '304 Not Modified' response case as well. (`#111 `_) diff --git a/buildout.cfg b/buildout.cfg index 30a48b7d..2ca977a5 100644 --- a/buildout.cfg +++ b/buildout.cfg @@ -7,16 +7,15 @@ parts = test_no_zsql sphinx + [test] recipe = zc.recipe.testrunner -defaults = ['-cv'] eggs = Products.CMFCore[zsql] [test_no_zsql] recipe = zc.recipe.testrunner -defaults = ['-cv'] eggs = Products.CMFCore diff --git a/src/Products/CMFCore/tests/fake_skins/fake_skin/test_text.metadata b/src/Products/CMFCore/tests/fake_skins/fake_skin/test_text.metadata new file mode 100644 index 00000000..95315051 --- /dev/null +++ b/src/Products/CMFCore/tests/fake_skins/fake_skin/test_text.metadata @@ -0,0 +1,2 @@ +[default] +encoding=UTF-8 diff --git a/src/Products/CMFCore/tests/test_ActionsTool.py b/src/Products/CMFCore/tests/test_ActionsTool.py index db69ac71..dc966e8b 100644 --- a/src/Products/CMFCore/tests/test_ActionsTool.py +++ b/src/Products/CMFCore/tests/test_ActionsTool.py @@ -159,21 +159,28 @@ def test_listActionInformationActions(self): visible=1),) newSecurityManager(None, OmnipotentUser().__of__(self.app.acl_users)) - self.assertEqual(tool.listFilteredActionsFor(self.app.foo), - {'workflow': [], - 'user': [], - 'object': [], - 'folder': [{'id': 'folderContents', - 'url': 'http://nohost/folder_contents', - 'icon': 'http://nohost/icon.gif', - 'title': 'Folder contents', - 'description': '', - 'visible': True, - 'available': True, - 'allowed': True, - 'category': 'folder', - 'link_target': '_top'}], - 'global': []}) + expected = {'workflow': [], + 'user': [], + 'object': [], + 'folder': [{'id': 'folderContents', + 'url': 'http://nohost/folder_contents', + 'icon': 'http://nohost/icon.gif', + 'title': 'Folder contents', + 'description': '', + 'visible': True, + 'available': True, + 'allowed': True, + 'category': 'folder', + 'link_target': '_top'}], + 'global': []} + with warnings.catch_warnings(): + # Ignore the warning - anything that uses the attribute + # ``_actions`` will raise it. The DeprecationWarning mentions the + # goal of removing old-style actions, but this is too hard and may + # never happen. + warnings.simplefilter('ignore') + self.assertEqual(tool.listFilteredActionsFor(self.app.foo), + expected) def test_suite(): diff --git a/src/Products/CMFCore/tests/test_FSFile.py b/src/Products/CMFCore/tests/test_FSFile.py index f73a63da..47f38c4d 100644 --- a/src/Products/CMFCore/tests/test_FSFile.py +++ b/src/Products/CMFCore/tests/test_FSFile.py @@ -15,6 +15,7 @@ import os import unittest +import warnings import six @@ -119,7 +120,12 @@ def test_str(self): if six.PY2: self.assertEqual(str(file), real_data) else: - self.assertRaises(UnicodeDecodeError, file.__str__) + # Calling ``__str__`` on non-text binary data in Python 3 + # will raise a DeprecationWarning because it makes no sense. + # Ignore it here, the warning is irrelevant for the test. + with warnings.catch_warnings(): + warnings.simplefilter('ignore') + self.assertRaises(UnicodeDecodeError, file.__str__) def test_index_html(self): path, ref = self._extractFile('test_file.swf')