Commit 4b0b00a0 authored by Jérome Perrin's avatar Jérome Perrin

Rework warnings configuration and fix some warnings

Make sure we see *all* warnings, both in the tests and in the logfile in production.

Fix many warnings by updating imports and calls to deprecated APIs

See merge request nexedi/erp5!1879
parents 3ab8e40d da5abc38
......@@ -50,7 +50,7 @@ from OFS.Image import Pdata
WORKFLOW_TYPE = 'erp5_workflow'
from Products.MimetypesRegistry.common import MimeTypeException
from Products.MimetypesRegistry.interfaces import MimeTypeException
from Products.PortalTransforms.Transform import Transform
Transform_tr_init = Transform._tr_init
Transform_manage_beforeDelete = Transform.manage_beforeDelete
......
......@@ -576,7 +576,7 @@ class TestERP5Core(ERP5TypeTestCase, ZopeTestCase.Functional):
0 != i.getUid() != i.getProperty('uid')])
def test_04_site_manager_and_translation_migration(self):
from zope.site.hooks import setSite
from zope.component.hooks import setSite
from zope.component import queryUtility
# check translation is working normaly
erp5_ui_catalog = self.portal.Localizer.erp5_ui
......
......@@ -33,7 +33,8 @@ import six
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.tests.utils import createZODBPythonScript
from Persistence import PersistentMapping
from zope.site.hooks import setSite
from zope.component.hooks import setSite
class TestLocalizer(ERP5TypeTestCase):
def afterSetUp(self):
......
......@@ -28,7 +28,10 @@
import warnings
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from erp5.component.test.testDms import makeFileUpload
from Products.ERP5Type import Utils
original_warnings_showwarnings = warnings.showwarning
class TestERP5PDFMerge(ERP5TypeTestCase):
......@@ -37,7 +40,7 @@ class TestERP5PDFMerge(ERP5TypeTestCase):
We should not let PdfFileReader overwrite warnings.showwarning method because we already do it in ERP5
https://github.com/mstamy2/PyPDF2/blob/18a2627adac13124d4122c8b92aaa863ccfb8c29/PyPDF2/pdf.py#L1129
"""
self.assertEqual(Utils._showwarning, warnings.showwarning)
self.assertEqual(warnings.showwarning, original_warnings_showwarnings)
document = self.portal.portal_contributions.newContent(
file=makeFileUpload('REF-en-001.pdf'))
merged_pdf_data = self.portal.ERP5Site_mergePDFList(
......@@ -46,7 +49,7 @@ class TestERP5PDFMerge(ERP5TypeTestCase):
portal_type='PDF',
data=merged_pdf_data)
self.tic()
self.assertEqual(Utils._showwarning, warnings.showwarning)
self.assertEqual(warnings.showwarning, original_warnings_showwarnings)
def test_erp5_merge_pdf(self):
document = self.portal.portal_contributions.newContent(
......
......@@ -17,8 +17,6 @@
<value>
<tuple>
<string>action_type/object_view</string>
<string>portal_types/Trade Quantity Divergence Tester/1</string>
<string>portal_types/Float Divergence Tester/2</string>
</tuple>
</value>
</item>
......
......@@ -17,8 +17,6 @@
<value>
<tuple>
<string>action_type/object_view</string>
<string>portal_types/Trade Quantity Divergence Tester/1</string>
<string>portal_types/Float Divergence Tester/3</string>
</tuple>
</value>
</item>
......
......@@ -17,8 +17,6 @@
<value>
<tuple>
<string>action_type/object_view</string>
<string>portal_types/Float Divergence Tester/1</string>
<string>portal_types/Float Divergence Tester/1</string>
</tuple>
</value>
</item>
......
......@@ -17,8 +17,6 @@
<value>
<tuple>
<string>action_type/object_view</string>
<string>portal_types/Trade Quantity Divergence Tester/1</string>
<string>portal_types/Float Divergence Tester/2</string>
</tuple>
</value>
</item>
......
......@@ -17,8 +17,6 @@
<value>
<tuple>
<string>action_type/object_view</string>
<string>portal_types/Trade Quantity Divergence Tester/1</string>
<string>portal_types/Float Divergence Tester/3</string>
</tuple>
</value>
</item>
......
......@@ -17,8 +17,6 @@
<value>
<tuple>
<string>action_type/object_view</string>
<string>portal_types/Float Divergence Tester/1</string>
<string>portal_types/Float Divergence Tester/1</string>
</tuple>
</value>
</item>
......
......@@ -17,8 +17,6 @@
<value>
<tuple>
<string>action_type/object_view</string>
<string>portal_types/Trade Quantity Divergence Tester/1</string>
<string>portal_types/Float Divergence Tester/2</string>
</tuple>
</value>
</item>
......
......@@ -17,8 +17,6 @@
<value>
<tuple>
<string>action_type/object_view</string>
<string>portal_types/Trade Quantity Divergence Tester/1</string>
<string>portal_types/Float Divergence Tester/3</string>
</tuple>
</value>
</item>
......
......@@ -17,8 +17,6 @@
<value>
<tuple>
<string>action_type/object_view</string>
<string>portal_types/Float Divergence Tester/1</string>
<string>portal_types/Float Divergence Tester/1</string>
</tuple>
</value>
</item>
......
......@@ -17,8 +17,6 @@
<value>
<tuple>
<string>action_type/object_view</string>
<string>portal_types/Trade Quantity Divergence Tester/1</string>
<string>portal_types/Float Divergence Tester/2</string>
</tuple>
</value>
</item>
......
......@@ -17,8 +17,6 @@
<value>
<tuple>
<string>action_type/object_view</string>
<string>portal_types/Trade Quantity Divergence Tester/1</string>
<string>portal_types/Float Divergence Tester/3</string>
</tuple>
</value>
</item>
......
......@@ -17,8 +17,6 @@
<value>
<tuple>
<string>action_type/object_view</string>
<string>portal_types/Float Divergence Tester/1</string>
<string>portal_types/Float Divergence Tester/1</string>
</tuple>
</value>
</item>
......
......@@ -17,7 +17,6 @@
<value>
<tuple>
<string>action_type/object_view</string>
<string>portal_types/Tester Type/7</string>
</tuple>
</value>
</item>
......
......@@ -17,8 +17,6 @@
<value>
<tuple>
<string>action_type/object_view</string>
<string>portal_types/Trade Quantity Divergence Tester/1</string>
<string>portal_types/Float Divergence Tester/2</string>
</tuple>
</value>
</item>
......
......@@ -17,8 +17,6 @@
<value>
<tuple>
<string>action_type/object_view</string>
<string>portal_types/Trade Quantity Divergence Tester/1</string>
<string>portal_types/Float Divergence Tester/3</string>
</tuple>
</value>
</item>
......
......@@ -17,8 +17,6 @@
<value>
<tuple>
<string>action_type/object_view</string>
<string>portal_types/Float Divergence Tester/1</string>
<string>portal_types/Float Divergence Tester/1</string>
</tuple>
</value>
</item>
......
......@@ -17,8 +17,6 @@
<value>
<tuple>
<string>action_type/object_view</string>
<string>portal_types/Trade Quantity Divergence Tester/1</string>
<string>portal_types/Float Divergence Tester/2</string>
</tuple>
</value>
</item>
......
......@@ -17,8 +17,6 @@
<value>
<tuple>
<string>action_type/object_view</string>
<string>portal_types/Trade Quantity Divergence Tester/1</string>
<string>portal_types/Float Divergence Tester/3</string>
</tuple>
</value>
</item>
......
......@@ -17,8 +17,6 @@
<value>
<tuple>
<string>action_type/object_view</string>
<string>portal_types/Trade Quantity Divergence Tester/1</string>
<string>portal_types/Float Divergence Tester/3</string>
</tuple>
</value>
</item>
......
......@@ -58,7 +58,7 @@ from BTrees.OIBTree import OIBTree
from BTrees.OOBTree import OOBTree
from Zope2 import app
from Products.ERP5Type.UnrestrictedMethod import PrivilegedUser
from zope.site.hooks import setSite
from zope.component.hooks import setSite
import transaction
from App.config import getConfiguration
from Shared.DC.ZRDB.Results import Results
......@@ -327,7 +327,9 @@ class Message(BaseMessage):
user = user.__of__(user_folder)
newSecurityManager(None, user)
if annotate_transaction:
transaction.get().setUser(user_name, '/'.join(user_folder.getPhysicalPath()))
if six.PY2:
user_name = user_name.decode('utf-8')
transaction.get().setUser(user_name, u'/'.join(user_folder.getPhysicalPath()))
else :
LOG("CMFActivity", WARNING,
"Unable to find user %r in the portal" % user_name)
......
......@@ -111,7 +111,7 @@ try:
except TypeError:
pass
cache_database = threading.local()
from Products.MimetypesRegistry.common import MimeTypeException
from Products.MimetypesRegistry.interfaces import MimeTypeException
import imghdr
# those attributes from CatalogMethodTemplateItem are kept for
......
......@@ -478,7 +478,7 @@ class ERP5Site(ResponseHeaderGenerator, FolderMixIn, PortalObjectBase, CacheCook
# one. Including setting up ZTK style utilities and adapters. We
# can even call setSite(self), as long as we roll back that later,
# since we are actually in the middle of a setSite() call.
from zope.site.hooks import getSite, setSite
from zope.component.hooks import getSite, setSite
old_site = getSite()
try:
setSite(self)
......@@ -2634,7 +2634,7 @@ def initialize(self):
manage_addERP5Site(app.__of__(RequestContainer(REQUEST=REQUEST)),
**{k: kw.get(k, v) for k, v in six.iteritems(default_kw)
if isinstance(v, str)})
transaction.get().note('Created ' + meta_type)
transaction.get().note(u'Created ' + meta_type)
transaction.commit()
break
except OperationalError as e:
......
......@@ -11,6 +11,7 @@ import socket
import sys
from tempfile import TemporaryFile
import time
import warnings
from six.moves.urllib.parse import quote, urlsplit
from waitress.server import create_server
......@@ -187,6 +188,9 @@ def runwsgi():
action="store_true")
args = parser.parse_args()
if not sys.warnoptions:
warnings.simplefilter('default')
# Configure logging previously handled by ZConfig/ZServer
logging.captureWarnings(True)
root_logger = logging.getLogger()
......
......@@ -39,7 +39,7 @@ from erp5.component.mixin.DocumentProxyMixin import DocumentProxyMixin, Document
from MethodObject import Method
try:
from Products.MimetypesRegistry.common import MimeTypeException # pylint: disable=unused-import
from Products.MimetypesRegistry.interfaces import MimeTypeException # pylint: disable=unused-import
except ImportError:
class MimeTypeException(Exception):
"""
......
......@@ -110,6 +110,7 @@
<list>
<string>your_debug</string>
<string>your_verbose</string>
<string>your_warnings</string>
</list>
</value>
</item>
......
......@@ -148,7 +148,7 @@
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: {\'run_test_url\': here.absolute_url() + \'/runLiveTest\', \'read_test_url\': here.absolute_url() + \'/readTestOutput\', \'test_list\': here.REQUEST.get(\'field_your_test\', \'\'), \'run_only\': here.REQUEST.get(\'field_your_run_only\', \'\'), \'debug\': int(here.REQUEST.get(\'field_your_debug\', \'\') == \'on\'), \'verbose\': int(here.REQUEST.get(\'field_your_verbose\', \'\') == \'on\')}</string> </value>
<value> <string>python: {\'run_test_url\': here.absolute_url() + \'/runLiveTest\', \'read_test_url\': here.absolute_url() + \'/readTestOutput\', \'test_list\': here.REQUEST.get(\'field_your_test\', \'\'), \'run_only\': here.REQUEST.get(\'field_your_run_only\', \'\'), \'debug\': int(here.REQUEST.get(\'field_your_debug\', \'\') == \'on\'), \'verbose\': int(here.REQUEST.get(\'field_your_verbose\', \'\') == \'on\'), \'warnings\': request.get(\'field_your_warnings\')}</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -530,8 +530,8 @@
<value>
<list>
<tuple>
<string>none</string>
<string>none</string>
<string>None</string>
<string></string>
</tuple>
</list>
</value>
......
......@@ -118,7 +118,7 @@
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: [(x, x) for x in here.getParent().getManagedRoleList()]</string> </value>
<value> <string>python: [(x, x) for x in here.getParentValue().getManagedRoleList()]</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -36,6 +36,7 @@ import os
import random
import unittest
from unittest import expectedFailure
import warnings
from AccessControl.SecurityManagement import newSecurityManager
from DateTime import DateTime
......@@ -4189,7 +4190,14 @@ class TestUnitConversionBackwardCompatibility(BaseTestUnitConversion):
delivery.confirm()
delivery.start()
delivery.stop()
with warnings.catch_warnings(record=True) as catched_warnings:
self.tic()
self.assertIn(
'quantity field of quantity_unit categories is deprecated. '
'Please use Quantity Unit Conversion Definitions instead and '
'reset the value of this field.',
[str(w.message) for w in catched_warnings],
)
# inventories of that resource are indexed in grams
self.assertEqual(3010,
......
......@@ -1044,9 +1044,12 @@ class ListBoxRenderer:
sort_dict[c] = ':' + cast
else:
if cast:
warn('Each line of the "Sortable Columns" field property must be'
' in the form "<column_id> | <cast_type>", where <cast_type>'
" is one of ('', 'float').", DeprecationWarning)
warn(
'{form}/{field}:'.format(
form=self.getForm().getId(), field=self.field.getId())
+ ' Each line of the "Sortable Columns" field property must be'
+ ' in the form "<column_id> | <cast_type>", where <cast_type>'
+ " is one of ('', 'float').", DeprecationWarning)
sort_dict[c] = ''
return sort_dict
......
......@@ -46,7 +46,7 @@ from Products.ERP5Type.Utils import UpperCase
from zLOG import LOG
try:
from webdav.Lockable import ResourceLockedError
from zExceptions import ResourceLockedError
from webdav.WriteLockInterface import WriteLockInterface
SUPPORTS_WEBDAV_LOCKS = 1
except ImportError:
......
......@@ -53,7 +53,7 @@ import re
import six
try:
from webdav.Lockable import ResourceLockedError
from zExceptions import ResourceLockedError
SUPPORTS_WEBDAV_LOCKS = 1
except ImportError:
SUPPORTS_WEBDAV_LOCKS = 0
......
......@@ -50,7 +50,7 @@ import itertools
import six
try:
from webdav.Lockable import ResourceLockedError
from zExceptions import ResourceLockedError
from webdav.WriteLockInterface import WriteLockInterface
SUPPORTS_WEBDAV_LOCKS = 1
except ImportError:
......
......@@ -1751,11 +1751,11 @@ class Base(
"""Returns the parent of the current object (whereas it should return the
relative_url of the parent for consistency with CMFCategory.
This method still uses this behaviour, because some part of the code still
This method still uses this behavior, because some part of the code still
uses getParent instead of getParentValue. This may change in the future.
"""
warnings.warn("getParent implementation still returns the parent object, "\
"which is inconsistant with CMFCategory API. "\
"which is inconsistent with CMFCategory API. "\
"Use getParentValue instead", FutureWarning)
return self.getParentValue() # Compatibility
......
......@@ -31,12 +31,9 @@
from ERP5Type.Globals instead of Globals
"""
# Globals.InitializeClass a.k.a. default__class_init__. This import location
# has not changed since 2.8 and still works on 2.12
from App.class_init import default__class_init__, ApplicationDefaultPermissions
# Nicer alias for class initializer.
InitializeClass = default__class_init__
# This is a re-export, some custom classes import from here
from AccessControl.class_init import InitializeClass
from zope.globalrequest import getRequest as get_request
......
......@@ -38,8 +38,7 @@ http://dev.zope.org/Wikis/DevSite/Projects/DeclarativeSecurity/ZopeSecurityForDe
from Products.CMFCore import permissions
from AccessControl import Permissions as ac_permissions
setDefaultRoles = permissions.setDefaultRoles
from AccessControl.Permission import addPermission
# Default Zope Permissions
View = permissions.View
......@@ -89,14 +88,14 @@ DeletePortalContent = permissions.ModifyPortalContent
# ERP5 addition: default content translation permissions
# this comes from Base18
TranslateContent = 'Translate Content'
setDefaultRoles(TranslateContent, ('Manager', 'Owner', 'Member'))
addPermission(TranslateContent, ('Manager', 'Owner', 'Member'))
# ERP5 additions: we define some content creations
# securities here. Each ERP5 Document will
# point to one of these securities through the
# add_permission attribute
#
# we define here the "setDefaultRoles" although
# we define here the "addPermission" although
# it does not apply to most roles since roles are defines
# on a ERP5 per ERP5 user basis. Most ERP5 users will
# subclass ERP5 basic types and define their own roles
......@@ -140,7 +139,7 @@ setDefaultRoles(TranslateContent, ('Manager', 'Owner', 'Member'))
# - using technical types / interfaces (ie. Entity, Coordinate, Predicate, etc.)
#AddERP5Content = 'Add ERP5 content'
#setDefaultRoles(AddERP5Content, ('Manager', ))
#addPermission(AddERP5Content, ('Manager', ))
AddERP5Content = AddPortalContent # Since we put come CPS content in ERP5 documents, there is no rationale in having 2 permissions
# Source Code Management - this is the highest possible permission
......
......@@ -275,7 +275,7 @@ class Test(ERP5TypeTestCase):
security.declareProtected(Permissions.ManagePortal, 'runLiveTest')
def runLiveTest(self, test_list=None, run_only=None, debug=False,
verbose=False):
verbose=False, warnings='default'):
"""
Launch live tests
......@@ -315,7 +315,8 @@ class Test(ERP5TypeTestCase):
debug=debug,
stream=global_stream,
request_server_url=request_server_url,
verbosity=verbosity)
verbosity=verbosity,
warnings=warnings)
except ImportError:
import traceback
traceback.print_exc(file=global_stream)
......
......@@ -28,6 +28,8 @@
"""
Most of the code in this file has been taken from patches/WorkflowTool.py
"""
import re
import warnings
from six import string_types as basestring
from AccessControl import ClassSecurityInfo, Unauthorized
from Acquisition import aq_base
......@@ -257,9 +259,17 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
return workflow_list
# WITH_LEGACY_WORKFLOW
getWorkflowsFor = deprecated(
"getWorkflowsFor() is deprecated; use getWorkflowValueListFor() instead")(
getWorkflowValueListFor)
__getWorkflowsFor_warning = \
"getWorkflowsFor() is deprecated; use getWorkflowValueListFor() instead"
getWorkflowsFor = deprecated(__getWorkflowsFor_warning)(getWorkflowValueListFor)
# ignore the warning when called from Products.CMFCore, getWorkflowsFor is a
# CMFCore API that is used internally in CMFCore, we only want to warn when
# using it from ERP5.
warnings.filterwarnings(
'ignore',
message=re.escape(__getWorkflowsFor_warning),
module='Products.CMFCore.WorkflowTool')
@deprecated("getChainFor() is deprecated; use getWorkflowValueListFor() instead")
def getChainFor(self, ob):
return [wf.getId() for wf in self.getWorkflowValueListFor(ob)]
......
......@@ -62,7 +62,7 @@ from Products.CMFCore.DirectoryView import registerDirectory
from Products.CMFCore.utils import getToolByName
from Products.PageTemplates.Expressions import getEngine
from Products.PageTemplates.Expressions import SecureModuleImporter
from Products.ZCatalog.Lazy import LazyMap
from ZTUtils.Lazy import LazyMap
try:
import chardet
......@@ -218,18 +218,8 @@ def sortValueList(value_list, sort_on=None, sort_order=None, **kw):
return value_list
#####################################################
# Logging
# Decorators
#####################################################
warnings.simplefilter("default")
def _showwarning(message, category, filename, lineno, file=None, line=None):
if file is None:
LOG(category.__name__, WARNING, "%s:%u %s" % (filename, lineno, message))
else:
file.write(warnings.formatwarning(message, category, filename, lineno, line))
warnings.showwarning = _showwarning
def deprecated(message=''):
@simple_decorator
def _deprecated(wrapped):
......
......@@ -21,7 +21,7 @@ from BTrees.OOBTree import OOBTree
from BTrees.OIBTree import OIBTree, union
from BTrees.Length import Length
from OFS.ObjectManager import BadRequestException, BeforeDeleteException
from Products.ZCatalog.Lazy import LazyMap
from ZTUtils.Lazy import LazyMap
from zLOG import LOG, WARNING, ERROR, INFO
class ERP5BTreeFolder2Base(BTreeFolder2Base):
......
......@@ -26,7 +26,7 @@ when ERP5 runs in "require_referer" mode.
"""
from AccessControl.SecurityInfo import ClassSecurityInfo
from App.class_init import InitializeClass
from AccessControl.class_init import InitializeClass
from Products.CMFCore.CookieCrumbler import CookieCrumbler
from Products.CMFCore.CookieCrumbler import CookieCrumblerDisabled
from six.moves.urllib.parse import quote, unquote
......
......@@ -29,7 +29,7 @@ from Products.DCWorkflow.DCWorkflow import ObjectDeleted, ObjectMoved
from Products.DCWorkflow import DCWorkflow
from Products.DCWorkflow.Transitions import TRIGGER_WORKFLOW_METHOD, TransitionDefinition
from Products.DCWorkflow.Transitions import TRIGGER_USER_ACTION
from Products.DCWorkflow.permissions import ManagePortal
from Products.CMFCore.permissions import ManagePortal
from AccessControl import getSecurityManager, ModuleSecurityInfo
from AccessControl.SecurityInfo import ClassSecurityInfo
from Products.ERP5Type.Globals import InitializeClass
......
......@@ -17,7 +17,6 @@ import six
from six import string_types as basestring
from OFS.PropertyManager import PropertyManager, type_converters
from OFS.PropertyManager import escape
from Products.ERP5Type.Globals import DTMLFile
from Products.ERP5Type.Utils import createExpressionContext
from Products.CMFCore.Expression import Expression
......@@ -28,6 +27,12 @@ from DateTime import DateTime
ERP5PropertyManager = PropertyManager # BBB
if six.PY3:
from html import escape
else:
from cgi import escape
PropertyManager_manage_propertiesForm=DTMLFile('properties',
_dtmldir,
property_extensible_schema__=1)
......
......@@ -20,6 +20,8 @@
from __future__ import absolute_import
import sys
import warnings
import six
from Products.ERP5Type import IS_ZOPE2
# TODO: make sure that trying to use it does not import isort, because the
......@@ -495,12 +497,23 @@ register_xpkg('xlte')
# File "develop-eggs/astroid-1.3.8+slapospatched001-py2.7.egg/astroid/raw_building.py", line 360, in _set_proxied
# return _CONST_PROXY[const.value.__class__]
# KeyError: <type 'CompiledFFI'>
if six.PY2:
warnings.filterwarnings(
'ignore',
message='Python 2 is no longer supported by the Python core team. '
'Support for it is now deprecated in cryptography.*')
import cryptography.hazmat.bindings._openssl
_register_module_extender_from_live_module(
'cryptography.hazmat.bindings._openssl',
cryptography.hazmat.bindings._openssl)
if six.PY2:
# xmlsec has a module with .pyi files which python2 does not understand
warnings.filterwarnings(
'ignore',
category=ImportWarning,
message='Not importing directory .*/xmlsec\': missing __init__.py')
try:
import xmlsec
except ImportError:
......
......@@ -15,6 +15,8 @@ from Shared.DC.ZRDB import sqltest
from DateTime import DateTime
from Products.ERP5Type import IS_ZOPE2
import six
list_type_list = list, tuple, set, frozenset, dict
if IS_ZOPE2: # BBB Zope2
......
......@@ -276,9 +276,7 @@ class FunctionalTestRunner:
kw.update(
firefox_binary=firefox_bin,
executable_path=geckodriver,
# BBB in selenium 3.8.0 this option was named log_path
log_path=os.path.join(log_directory, 'geckodriver.log'),
# service_log_path=os.path.join(log_directory, 'geckodriver.log'),
service_log_path=os.path.join(log_directory, 'geckodriver.log'),
)
browser = webdriver.Firefox(**kw)
else:
......@@ -363,11 +361,11 @@ class FunctionalTestRunner:
# need to wait a bit more, because at the end of test ( testComplete ),
# updateSuiteWithResultOfPreviousTest is called by setTimeout. We want to
# wait for the last test (which is the last td) result table to be present
browser.switch_to_frame('testSuiteFrame')
browser.switch_to.frame('testSuiteFrame')
WebDriverWait(browser, 10).until(EC.presence_of_element_located((
By.XPATH, '//table/tbody/tr/td[last()]//table'
)))
browser.switch_to_default_content()
browser.switch_to.default_content()
self.execution_duration = round(time.time() - start_time, 2)
html_parser = etree.HTMLParser(recover=True)
iframe = etree.fromstring(
......
......@@ -31,8 +31,9 @@ import os
import sys
import imp
import re
import warnings
from zope.site.hooks import setSite
from zope.component.hooks import setSite
from zope.globalrequest import getRequest
from Acquisition import aq_base
from Testing import ZopeTestCase
......@@ -297,6 +298,9 @@ def runLiveTest(test_list, verbosity=1, stream=None, request_server_url=None, **
output.write("**Running Live Test:\n")
ZopeTestCase._print = output.write
with warnings.catch_warnings():
warnings.simplefilter(kw['warnings'])
# Test may login/logout with different users, so ensure that at the end the
# original SecurityManager is restored
from AccessControl.SecurityManagement import getSecurityManager, setSecurityManager
......
......@@ -37,7 +37,7 @@ from zope.globalrequest import getRequest
from zope.globalrequest import setRequest
import six
from zope.site.hooks import setSite
from zope.component.hooks import setSite
from Testing import ZopeTestCase
from Testing.makerequest import makerequest
......
......@@ -11,6 +11,7 @@ import shutil
import errno
import random
import transaction
import warnings
from glob import glob
......@@ -495,6 +496,17 @@ class DebugTestResult:
_print = sys.stderr.write
def setupWarnings():
if not sys.warnoptions:
warnings.simplefilter("default")
os.environ["PYTHONWARNINGS"] = "default"
warnings.filterwarnings(
'ignore',
message='(?s)Node name auto-generation is deprecated.*product-config CMFActivity.*'
)
def runUnitTestList(test_list, verbosity=1, debug=0, run_only=None):
if "zeo_client" in os.environ and "zeo_server" in os.environ:
_print("conflicting options: --zeo_client and --zeo_server\n")
......@@ -898,6 +910,8 @@ def main(argument_list=None):
elif opt == "--with_wendelin_core":
os.environ["with_wendelin_core"] = "1"
setupWarnings()
bt5_path_list += filter(None,
os.environ.get("erp5_tests_bt5_path", "").split(','))
valid_path_list = []
......
......@@ -273,16 +273,6 @@ class TestERP5Type(ERP5TypeTestCase, LogInterceptor):
temp_object = Products.ERP5Type.Document.newTempBase(self.portal, 'id')
self._test_temp_object_persistent(temp_object)
def test_warnings_redirected_to_event_log(self):
self._catch_log_errors()
self.addCleanup(self._ignore_log_errors)
warnings.warn('user warning')
self.assertEqual(self.logged[-1].name, 'UserWarning')
self.assertIn('Products/ERP5Type/tests/testERP5Type.py', self.logged[-1].message)
self.assertIn('user warning', self.logged[-1].message)
warnings.warn('user warning', DeprecationWarning)
self.assertEqual(self.logged[-1].name, 'DeprecationWarning')
def test_objectValues(self):
person = self.portal.person_module.newContent(portal_type='Person')
createZODBPythonScript(person, 'test_script', '', '')
......
from App.class_init import default__class_init__ as InitializeClass
from AccessControl.class_init import InitializeClass
from AccessControl import ClassSecurityInfo
try:
......
# -*- coding: utf-8 -*-
from __future__ import absolute_import
import six
from App.class_init import default__class_init__ as InitializeClass
from AccessControl.class_init import InitializeClass
import Acquisition
from Persistence import Persistent
from App.special_dtml import DTMLFile
......
......@@ -2,7 +2,7 @@ from __future__ import absolute_import
import six
import AccessControl
import OFS
from App.class_init import default__class_init__ as InitializeClass
from AccessControl.class_init import InitializeClass
from Acquisition import aq_base
from App.special_dtml import DTMLFile
from Persistence import Persistent
......
......@@ -10,7 +10,7 @@ from __future__ import absolute_import
import string
from AccessControl import ClassSecurityInfo
from App.class_init import default__class_init__ as InitializeClass
from AccessControl.class_init import InitializeClass
import FormValidationError, BasicForm
from . import StandardFields
......
......@@ -13,7 +13,7 @@
##############################################################################
from AccessControl.SecurityInfo import ClassSecurityInfo
from App.class_init import default__class_init__ as InitializeClass
from AccessControl.class_init import InitializeClass
from Products.HBTreeFolder2.HBTreeFolder2 import HBTreeFolder2Base
from Products.CMFCore.PortalFolder import PortalFolderBase
......
......@@ -24,7 +24,7 @@ from six.moves.urllib.parse import quote
from random import randint
from six.moves import xrange
from App.class_init import default__class_init__ as InitializeClass
from AccessControl.class_init import InitializeClass
from App.special_dtml import DTMLFile
from Persistence import Persistent, PersistentMapping
from Acquisition import aq_base
......
......@@ -22,7 +22,7 @@ from six.moves.urllib.parse import urlparse
from .itools.i18n import get_language_name, get_languages
# Import from Zope
from App.class_init import InitializeClass
from AccessControl.class_init import InitializeClass
from App.Management import Tabs
from AccessControl import ClassSecurityInfo
......
......@@ -22,7 +22,7 @@ from contextlib import contextmanager
# Import from Zope
from AccessControl import ClassSecurityInfo
from Acquisition import aq_parent
from App.class_init import InitializeClass
from AccessControl.class_init import InitializeClass
from OFS.Folder import Folder
from zLOG import LOG, ERROR, INFO, PROBLEM
from zope.interface import implementer
......
......@@ -42,7 +42,7 @@ import polib
# Import from Zope
from AccessControl import ClassSecurityInfo
from Acquisition import aq_base
from App.class_init import InitializeClass
from AccessControl.class_init import InitializeClass
from App.Dialogs import MessageDialog
from OFS.ObjectManager import ObjectManager
from OFS.SimpleItem import SimpleItem
......
......@@ -16,7 +16,7 @@ from six.moves.email_mime_multipart import MIMEMultipart
from six.moves.email_mime_text import MIMEText
from email.utils import make_msgid, formataddr, getaddresses
from App.class_init import default__class_init__ as InitializeClass
from AccessControl.class_init import InitializeClass
from App.Common import package_home
from .MTMultipart import MTMultipart
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
......
......@@ -7,7 +7,7 @@ from __future__ import absolute_import
from AccessControl import ClassSecurityInfo
from AccessControl import getSecurityManager
from App.class_init import default__class_init__ as InitializeClass
from AccessControl.class_init import InitializeClass
from Products.CMFCore.FSPageTemplate import FSPageTemplate
from Products.CMFCore.DirectoryView import registerFileExtension
from Products.CMFCore.DirectoryView import registerMetaType
......
......@@ -11,7 +11,7 @@ except ImportError: # six.PY3
from email.encoders import encode_base64
from six.moves.email_mime_base import MIMEBase
from six.moves.email_mime_multipart import MIMEMultipart
from App.class_init import default__class_init__ as InitializeClass
from AccessControl.class_init import InitializeClass
try:
from OFS.content_types import guess_content_type
except ImportError:
......
......@@ -10,7 +10,7 @@ import six
from AccessControl import ClassSecurityInfo
from AccessControl import getSecurityManager
from App.class_init import default__class_init__ as InitializeClass
from AccessControl.class_init import InitializeClass
from App.Common import package_home
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
from Products.PageTemplates.PageTemplate import PageTemplate
......
......@@ -24,7 +24,7 @@ else:
from Products.CMFCore.DirectoryView import addDirectoryViews
from Products.CMFCore.tests.base.testcase import FSDVTest
from AccessControl import ClassSecurityInfo
from App.class_init import default__class_init__ as InitializeClass
from AccessControl.class_init import InitializeClass
class DummyMember:
......
......@@ -5,7 +5,7 @@ from six.moves import UserDict
from zope.interface import implementer
from Products.PageTemplates.PageTemplateFile import PageTemplateFile
from App.class_init import default__class_init__ as InitializeClass
from AccessControl.class_init import InitializeClass
from Persistence import PersistentMapping
from persistent.list import PersistentList
from OFS.SimpleItem import SimpleItem
......
......@@ -6,14 +6,14 @@ from zope.interface import implementer
from AccessControl import ClassSecurityInfo
from Acquisition import aq_base
from App.class_init import default__class_init__ as InitializeClass
from AccessControl.class_init import InitializeClass
from OFS.Folder import Folder
from Persistence import PersistentMapping
from Products.CMFCore.ActionProviderBase import ActionProviderBase
from Products.CMFCore.permissions import ManagePortal, View
from Products.CMFCore.utils import registerToolInterface, UniqueObject
from Products.CMFCore.utils import getToolByName
from Products.MimetypesRegistry.common import MimeTypeException
from Products.MimetypesRegistry.interfaces import MimeTypeException
from Products.PageTemplates.PageTemplateFile import PageTemplateFile
from Products.PortalTransforms.data import datastream
......
......@@ -2,7 +2,7 @@ from zope.interface import implementer
from Products.PageTemplates.PageTemplateFile import PageTemplateFile
from Persistence import Persistent
from App.class_init import default__class_init__ as InitializeClass
from AccessControl.class_init import InitializeClass
from Acquisition import Implicit
from OFS.SimpleItem import Item
from OFS.role import RoleManager
......
......@@ -5,7 +5,7 @@ __version__ = '$Revision: 1.3 $'[11:-2]
import sys, time, threading
from DateTime import DateTime
from App.class_init import default__class_init__ as InitializeClass
from AccessControl.class_init import InitializeClass
from OFS.SimpleItem import SimpleItem
from OFS.PropertyManager import PropertyManager
......
......@@ -94,9 +94,11 @@ from MySQLdb import OperationalError, NotSupportedError, ProgrammingError, _mysq
import warnings
from contextlib import contextmanager
if six.PY2:
from contextlib import nested
@contextmanager
def nullcontext():
yield
else:
from contextlib import ExitStack as nested
from contextlib import nullcontext
from Products.ERP5Type.Timeout import TimeoutReachedError, getTimeLeft
MySQLdb_version_required = (0,9,2)
......@@ -582,7 +584,7 @@ class DB(TM):
name = m.group(2)
# Lock automatically unless src__ is True, because the caller may have
# already done it (in case that it plans to execute the returned query).
with (nested if src__ else self.lock)():
with (nullcontext if src__ else self.lock)():
try:
old_list, old_set, old_default = self._getTableSchema("`%s`" % name)
except ProgrammingError as e:
......
......@@ -21,7 +21,7 @@ from Persistence import Persistent, PersistentMapping
import Acquisition
import ExtensionClass
import OFS.History
from App.class_init import default__class_init__ as InitializeClass
from AccessControl.class_init import InitializeClass
from App.special_dtml import DTMLFile
from _thread import allocate_lock, get_ident
from OFS.Folder import Folder
......
......@@ -133,7 +133,7 @@ class SQLExpression(object):
raise ValueError('Unrecognized "limit" value: %r' % (limit, ))
else:
self.limit = (limit, )
if from_expression is not None:
if isinstance(from_expression, basestring):
warnings.warn("Providing a 'from_expression' is deprecated.",
DeprecationWarning)
self.from_expression = from_expression
......
......@@ -19,7 +19,7 @@ from Products.ERP5Type.Utils import ensure_list
from App.special_dtml import DTMLFile
from App.Dialogs import MessageDialog
from App.class_init import default__class_init__ as InitializeClass
from AccessControl.class_init import InitializeClass
from OFS.Folder import Folder
from DateTime import DateTime
......
......@@ -18,7 +18,7 @@ import six
from zope.interface import implementer
from AccessControl.SecurityInfo import ClassSecurityInfo
from App.class_init import InitializeClass
from AccessControl.class_init import InitializeClass
from App.Common import package_home
from App.config import getConfiguration
from App.ImageFile import ImageFile
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment