use zope.testrunner for running all tests => additional Python3 fixes

This commit is contained in:
Helmut Merz 2024-09-28 10:30:30 +02:00
parent 74ce78dae9
commit 48a51c54b1
10 changed files with 75 additions and 147 deletions

View file

@ -1,29 +1,9 @@
#
# Copyright (c) 2006 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# loops.constraint.setup
"""
Automatic setup of a loops site for the constraint package.
$Id$
""" Automatic setup of a loops site for the constraint package.
"""
from zope.component import adapts
from zope.interface import implements, Interface
from loops.concept import Concept
from loops.constraint.interfaces import IStaticConstraint

View file

@ -2,8 +2,6 @@
loops - Linked Objects for Organization and Processing Services
===============================================================
($Id$)
>>> from zope import component
>>> from zope.traversing.api import getName
@ -28,13 +26,15 @@ Reading object information from an external source
>>> from loops.external.pyfunc import PyReader
>>> input = ("concept('myquery', u'My Query', 'query', viewName='mystuff.html',"
>>> input = ("concept('myquery', 'My Query', 'query', viewName='mystuff.html',"
... " options='option1\\noption2')")
>>> reader = PyReader()
>>> elements = reader.read(input)
>>> elements
[{'options': 'option1\noption2', 'type': 'query', 'name': 'myquery',
'viewName': 'mystuff.html', 'title': u'My Query'}]
[{'name': 'myquery', ...}]
[{'options': 'option1\noption2', 'type': 'query', 'name': 'myquery',
'viewName': 'mystuff.html', 'title': 'My Query'}]
Creating the corresponding objects
----------------------------------
@ -50,14 +50,14 @@ Creating the corresponding objects
>>> adMyquery = adapted(concepts['myquery'])
>>> adMyquery.viewName
u'mystuff.html'
'mystuff.html'
>>> adMyquery.options
[u'option1', u'option2']
['option1', 'option2']
Importing types
---------------
>>> input = ("type('mytype', u'My Type',"
>>> input = ("type('mytype', 'My Type',"
... " typeInterface='loops.expert.concept.IQueryConcept')")
>>> reader = PyReader()
>>> elements = reader.read(input)
@ -70,7 +70,7 @@ Importing types
Working with resources
----------------------
>>> input = ("resource('doc04.txt', u'Document 4', 'textdocument')\n"
>>> input = ("resource('doc04.txt', 'Document 4', 'textdocument')\n"
... "resourceRelation('myquery', 'doc04.txt', 'standard')")
>>> reader = PyReader()
>>> elements = reader.read(input)
@ -81,13 +81,13 @@ Working with resources
>>> loader.load(elements)
>>> sorted(resources)
[u'd001.txt', u'd002.txt', u'd003.txt', u'doc04.txt']
['d001.txt', 'd002.txt', 'd003.txt', 'doc04.txt']
Working with nodes
------------------
>>> input = ("node('home', u'Home', '', u'menu', body=u'Welcome')\n"
... "node('myquery', u'My Query', 'home', u'page', "
>>> input = ("node('home', 'Home', '', 'menu', body='Welcome')\n"
... "node('myquery', 'My Query', 'home', 'page', "
... " target='concepts/myquery')")
>>> reader = PyReader()
>>> elements = reader.read(input)
@ -105,12 +105,12 @@ registered.
>>> from loops.external import annotation
>>> input = """concept('myquery', u'My Query', 'query', viewName='mystuff.html',
>>> input = """concept('myquery', 'My Query', 'query', viewName='mystuff.html',
... options='option1\\noption2')[
... annotations(creators=(u'john',))]"""
... annotations(creators=('john',))]"""
>>> elements = reader.read(input)
>>> elements[0].subElements
[{'creators': (u'john',)}]
[{'creators': ('john',)}]
Loading the element with the sub-element stores the DC attributes.
@ -118,7 +118,7 @@ Loading the element with the sub-element stores the DC attributes.
>>> from zope.dublincore.interfaces import IZopeDublinCore
>>> dc = IZopeDublinCore(concepts['myquery'])
>>> dc.creators
(u'john',)
('john',)
Exporting loops Objects
@ -137,22 +137,23 @@ Writing object information to the external storage
--------------------------------------------------
>>> from loops.external.pyfunc import PyWriter
>>> from cStringIO import StringIO
>>> from io import StringIO
>>> output = StringIO()
>>> writer = PyWriter()
>>> writer.write(elements, output)
>>> print output.getvalue()
type(u'task', ...)...
type(u'country', u'Country', viewName=u'', typeInterface=u''..., options=u''...)...
type(u'query', u'Query', viewName=u'', typeInterface='loops.expert.concept.IQueryConcept'..., options=u''...)...
concept(u'myquery', u'My Query', u'query', options=u'option1\noption2',
viewName=u'mystuff.html'...)...
child(u'projects', u'customer', u'standard')...
resource(u'doc04.txt', u'Document 4', u'textdocument', contentType=u'')...
resourceRelation(u'myquery', u'doc04.txt', u'standard')
node(u'home', u'Home', '', u'menu')
node(u'myquery', u'My Query', u'home', u'page', target=u'concepts/myquery')...
>>> print(output.getvalue())
type('task', ...)...
type('country', 'Country', viewName='', typeInterface=''..., options=''...)...
type('query', 'Query', viewName='', typeInterface='loops.expert.concept.IQueryConcept'..., options=''...)...
concept('myquery', 'My Query', 'query', options='option1\noption2',
viewName='mystuff.html'...)...
child('projects', 'customer', 'standard')...
resource('doc04.txt', 'Document 4', 'textdocument', contentType='')...
resourceRelation('myquery', 'doc04.txt', 'standard')
node('home', 'Home', '', 'menu')
node('myquery', 'My Query', 'home', 'page', target='concepts/myquery')...
Writing sub-elements
-------------------
@ -160,7 +161,7 @@ Writing sub-elements
Let's first set up a sequence with one element containing
two sub-elements.
>>> input = """concept('myquery', u'My Query', 'query', viewName='mystuff.html')[
>>> input = """concept('myquery', 'My Query', 'query', viewName='mystuff.html')[
... annotations(creators='john'),
... annotations(modified='2007-08-12')]"""
>>> elements = reader.read(input)
@ -169,8 +170,8 @@ two sub-elements.
Writing this sequence reproduces the import format.
>>> print output.getvalue()
concept('myquery', u'My Query', 'query', viewName='mystuff.html')[
>>> print(output.getvalue())
concept('myquery', 'My Query', 'query', viewName='mystuff.html')[
annotations(creators='john'),
annotations(modified='2007-08-12')]...
@ -184,12 +185,13 @@ corresponding extractor adapter.
>>> extractor = Extractor(loopsRoot, os.path.join(dataDirectory, 'export'))
>>> PyWriter().write(extractor.extract(), output)
>>> print output.getvalue()
type(u'task', ...)...
type(u'country', u'Country', viewName=u'', typeInterface=u''..., options=u''...)...
concept(u'myquery', u'My Query', u'query', options=u'option1\noption2',
viewName=u'mystuff.html')[
annotations(creators=(u'john',))]...
>>> print(output.getvalue())
type('task', ...)...
type('country', 'Country', viewName='', typeInterface=''..., options=''...)...
concept('myquery', 'My Query', 'query', options='option1\noption2',
viewName='mystuff.html')[
annotations(creators=('john',))]...
Extracting selected parts of the concept map
--------------------------------------------
@ -202,17 +204,17 @@ Extracting selected parts of the concept map
>>> output = StringIO()
>>> writer.write(elements, output)
>>> print output.getvalue()
type(u'customer', u'Customer', viewName=u'', typeInterface=u''..., options=u''...)
concept(u'cust1', u'Customer 1', u'customer')
concept(u'cust2', u'Customer 2', u'customer')
concept(u'cust3', u'Customer 3', u'customer')
resource(u'd001.txt', u'Doc 001', u'textdocument', contentType=u'')
resource(u'd003.txt', u'Doc 003', u'textdocument', contentType=u'')
resource(u'd002.txt', u'Doc 002', u'textdocument', contentType=u'')
resourceRelation(u'cust1', u'd001.txt', u'standard')
resourceRelation(u'cust1', u'd003.txt', u'standard')
resourceRelation(u'cust3', u'd002.txt', u'standard')
>>> print(output.getvalue())
type('customer', 'Customer', ...)
concept('cust1', 'Customer 1', 'customer')
concept('cust2', 'Customer 2', 'customer')
concept('cust3', 'Customer 3', 'customer')
resource('d001.txt', 'Doc 001', 'textdocument', contentType='')
resource('d003.txt', 'Doc 003', 'textdocument', contentType='')
resource('d002.txt', 'Doc 002', 'textdocument', contentType='')
resourceRelation('cust1', 'd001.txt', 'standard')
resourceRelation('cust1', 'd003.txt', 'standard')
resourceRelation('cust3', 'd002.txt', 'standard')
The Export/Import View

View file

@ -1,31 +1,13 @@
#
# Copyright (c) 2013 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# loops.external.browser
"""
view class(es) for import/export.
""" view class(es) for import/export.
"""
from cStringIO import StringIO
from io import StringIO
import os
import time
from zope import component
from zope.interface import Interface, implements
from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
from zope.browserpage.viewpagetemplatefile import ViewPageTemplateFile
from zope.cachedescriptors.property import Lazy
from zope.security.proxy import removeSecurityProxy
from zope.traversing.api import getName, getPath, traverse

View file

@ -179,10 +179,10 @@ class ResourceElement(Element):
def processExport(self, extractor):
content = self.pop('data', '')
fileFlags = 'wb'
if (self.get('contentType', '').startswith('text/')
and isinstance(content, unicode)):
content = content.encode('UTF-8')
if self.get('contentType', '').startswith('text/'):
fileFlags = 'wt'
elif isinstance(content, str):
content = content.encode('UTF-8')
directory = extractor.resourceDirectory
if not os.path.exists(directory):
os.makedirs(directory)

View file

@ -1,25 +1,6 @@
#
# Copyright (c) 2008 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# loops.integrator.content.base
"""
Access to external objects.
$Id$
""" Access to external objects.
"""
import os, re
@ -27,7 +8,7 @@ import os, re
from zope import component
from zope.cachedescriptors.property import Lazy
from zope.component import adapts
from zope.interface import implements
from zope.interface import implementer
from cybertools.integrator.interfaces import IContainerFactory
from loops.common import AdapterBase, adapted
@ -39,11 +20,11 @@ from loops.type import TypeInterfaceSourceList
TypeInterfaceSourceList.typeInterfaces += (IExternalAccess,)
@implementer(IExternalAccess)
class ExternalAccess(AdapterBase):
""" A concept adapter for accessing external collection.
"""
implements(IExternalAccess)
adapts(IConcept)
_contextAttributes = list(IExternalAccess) + list(IConcept)

View file

@ -1,6 +1,4 @@
"""
$Id$
"""
# loops.organize.browser
# make sure actions get registered
import party
from loops.organize import party

View file

@ -1,23 +1,6 @@
#
# Copyright (c) 2012 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# loops.organize.job.browser
"""
Definition of view classes and other browser related stuff for job management.
""" Definition of view classes and other browser related stuff for job management.
"""
from logging import getLogger
@ -57,7 +40,7 @@ class Executor(object):
name=name)
if manager is None:
msg = "Job manager '%s' not found." % name
self.logger.warn(msg)
self.logger.warning(msg)
output.append(msg)
else:
manager = removeSecurityProxy(manager)

View file

@ -430,6 +430,8 @@ class DocumentAdapter(ResourceAdapterBase):
_adapterAttributes = ResourceAdapterBase._adapterAttributes + ('data',)
def setData(self, data):
if isinstance(data, bytes):
data = data.decode('UTF-8')
self.context._data = data.replace('\r', '')
self.context._size = len(data)
def getData(self): return self.context._data

View file

@ -11,7 +11,7 @@ from zope.catalog.catalog import Catalog
from zope.catalog.interfaces import ICatalog
from zope.catalog.field import FieldIndex
from zope.catalog.text import TextIndex
from zope.container.interfaces import IObjectRemovedEvent
from zope.lifecycleevent.interfaces import IObjectRemovedEvent
from zope.dublincore.annotatableadapter import ZDCAnnotatableAdapter
from zope.dublincore.interfaces import IZopeDublinCore
from zope.principalregistry.principalregistry import principalRegistry

View file

@ -31,13 +31,13 @@ dependencies = [
]
[project.optional-dependencies]
test = ["pytest"]
test = ["zope.testrunner"]
[tool.setuptools]
packages = ["loops"]
[tool.pytest.ini_options]
addopts = "-vv"
python_files = "test_standard.py" # default: run only `standard` tests
#[tool.pytest.ini_options]
#addopts = "-vv"
#python_files = "test_standard.py" # default: run only `standard` tests
# use .pytest.ini file with `python_files = test_*.py` to run all tests