Skip to content
This repository has been archived by the owner on Dec 17, 2020. It is now read-only.

Commit

Permalink
Cleanup testing setup
Browse files Browse the repository at this point in the history
Move functional tests from ftests.py to tests.py
Removed the ftests.py because ftests files are not supported anymore
  • Loading branch information
projekt01 committed Apr 13, 2008
1 parent eb0555e commit 0d52e15
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 112 deletions.
3 changes: 2 additions & 1 deletion setup.py
Expand Up @@ -59,7 +59,6 @@ def read(*rnames):
'zope.app.pagetemplate',
'zope.app.securitypolicy',
'zope.app.testing',
'zope.publisher',
'zope.testing',
],
),
Expand All @@ -81,6 +80,8 @@ def read(*rnames):
'zope.i18nmessageid',
'zope.index',
'zope.interface',
'zope.publisher',
'zope.schema',
'zope.schema',
'zope.security',
'zope.traversing',
Expand Down
41 changes: 0 additions & 41 deletions src/z3c/contents/ftests.py

This file was deleted.

103 changes: 102 additions & 1 deletion src/z3c/contents/testing.py
Expand Up @@ -16,11 +16,36 @@
"""
__docformat__ = "reStructuredText"

import lxml
import zope.component
import zope.interface
from zope.publisher.interfaces.browser import IBrowserRequest
from zope.annotation.interfaces import IAnnotations
from zope.copypastemove import ContainerItemRenamer
from zope.copypastemove import ObjectMover
from zope.copypastemove import ObjectCopier
from zope.copypastemove import PrincipalClipboard
from zope.copypastemove.interfaces import IContainerItemRenamer
from zope.copypastemove.interfaces import IObjectMover
from zope.copypastemove.interfaces import IObjectCopier
from zope.copypastemove.interfaces import IPrincipalClipboard
from zope.index.text.interfaces import ISearchableText

from zope.app.container.interfaces import IContainer
from zope.app.container.interfaces import IContained
from zope.app.testing import functional
from zope.app.testing import setup

import z3c.macro.tales
import z3c.layer.ready2go
import z3c.table.testing
import z3c.contents.value


###############################################################################
#
# test component
#
###############################################################################

class IContentsTestBrowserLayer(z3c.layer.ready2go.IReady2GoBrowserLayer):
"""test layer."""
Expand Down Expand Up @@ -60,3 +85,79 @@ def __init__(self, content):

def getSearchableText(self):
return '%s %d' % (self.content.title, self.content.number)


###############################################################################
#
# testing helper
#
###############################################################################

def printElement(browser, xpath, multiple=False, serialize=True):
"""Print method to use with z3c.etestbrowser"""
result = [serialize and lxml.etree.tounicode(elem) or elem
for elem in browser.etree.xpath(xpath)]
if not multiple:
print result[0]
return
for elem in result:
print elem


class PrincipalAnnotations(dict):
zope.interface.implements(IAnnotations)
data = {}
def __new__(class_, context=None):
try:
annotations = class_.data[str(context)]
except KeyError:
annotations = dict.__new__(class_)
class_.data[str(context)] = annotations
return annotations
def __init__(self, context):
pass
def __repr__(self):
return "<%s.PrincipalAnnotations object>" % __name__


###############################################################################
#
# testing setup
#
###############################################################################

def setUp(test):
test.globs = {'root': setup.placefulSetUp(True)}

from zope.app.pagetemplate import metaconfigure
metaconfigure.registerType('macro', z3c.macro.tales.MacroExpression)

zope.component.provideAdapter(ObjectCopier, (IContained,), IObjectCopier)
zope.component.provideAdapter(ObjectMover, (IContained,), IObjectMover)
zope.component.provideAdapter(ContainerItemRenamer, (IContainer,),
IContainerItemRenamer)

zope.component.provideAdapter(PrincipalClipboard, (IAnnotations,),
IPrincipalClipboard)
# use None as principal
zope.component.provideAdapter(PrincipalAnnotations, (None,),
IAnnotations)

# dublin core stub adapter
zope.component.provideAdapter(z3c.table.testing.DublinCoreAdapterStub)

# value adapter
zope.component.provideAdapter(z3c.contents.value.SearchableValues)


def tearDown(test):
setup.placefulTearDown()


def doctestSetUp(test):
functional.FunctionalTestSetup().setUp()
test.globs['getRootFolder'] = functional.getRootFolder
test.globs['printElement'] = printElement

def doctestTearDown(test):
functional.FunctionalTestSetup().tearDown()
70 changes: 9 additions & 61 deletions src/z3c/contents/tests.py
Expand Up @@ -17,77 +17,25 @@
__docformat__ = "reStructuredText"

import unittest
import zope.component
import zope.interface
from zope.annotation.interfaces import IAnnotations
from zope.copypastemove import ContainerItemRenamer
from zope.copypastemove import ObjectMover
from zope.copypastemove import ObjectCopier
from zope.copypastemove import PrincipalClipboard
from zope.copypastemove.interfaces import IContainerItemRenamer
from zope.copypastemove.interfaces import IObjectMover
from zope.copypastemove.interfaces import IObjectCopier
from zope.copypastemove.interfaces import IPrincipalClipboard
from zope.testing import doctest
from zope.app.container.interfaces import IContainer
from zope.app.container.interfaces import IContained
from zope.app.testing import setup
from zope.app.testing import functional

from z3c.macro import tales
import z3c.table.testing
import z3c.contents.value
from z3c.contents import testing


class PrincipalAnnotations(dict):
zope.interface.implements(IAnnotations)
data = {}
def __new__(class_, context=None):
try:
annotations = class_.data[str(context)]
except KeyError:
annotations = dict.__new__(class_)
class_.data[str(context)] = annotations
return annotations
def __init__(self, context):
pass
def __repr__(self):
return "<%s.PrincipalAnnotations object>" % __name__


def setUp(test):
test.globs = {'root': setup.placefulSetUp(True)}

from zope.app.pagetemplate import metaconfigure
metaconfigure.registerType('macro', tales.MacroExpression)

zope.component.provideAdapter(ObjectCopier, (IContained,), IObjectCopier)
zope.component.provideAdapter(ObjectMover, (IContained,), IObjectMover)
zope.component.provideAdapter(ContainerItemRenamer, (IContainer,),
IContainerItemRenamer)

zope.component.provideAdapter(PrincipalClipboard, (IAnnotations,),
IPrincipalClipboard)
# use None as principal
zope.component.provideAdapter(PrincipalAnnotations, (None,),
IAnnotations)

# dublin core stub adapter
zope.component.provideAdapter(z3c.table.testing.DublinCoreAdapterStub)

# value adapter
zope.component.provideAdapter(z3c.contents.value.SearchableValues)


def tearDown(test):
setup.placefulTearDown()
functional.defineLayer('TestLayer', 'ftesting.zcml')


def test_suite():
docTest = functional.FunctionalDocFileSuite('BROWSER.txt',
setUp=testing.doctestSetUp, tearDown=testing.doctestTearDown,
optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS)
docTest.layer = TestLayer
return unittest.TestSuite((
doctest.DocFileSuite('README.txt',
setUp=setUp, tearDown=tearDown,
setUp=testing.setUp, tearDown=testing.tearDown,
optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
),
docTest,
))


Expand Down
15 changes: 7 additions & 8 deletions src/z3c/contents/value.py
Expand Up @@ -29,26 +29,25 @@
from z3c.contents import browser


def _search_helper(id, object, container, id_filters, object_filters, result):
def _search_helper(id, obj, container, id_filters, object_filters, result):
# check id filters if we get a match then return immediately
for id_filter in id_filters:
if id_filter.matches(id):
result.append(object)
result.append(obj)
return

# now check all object filters
for object_filter in object_filters:
if object_filter.matches(object):
result.append(object)
if object_filter.matches(obj):
result.append(obj)
return

# do we need to check sub containers?
if not IReadContainer.providedBy(object):
if not IReadContainer.providedBy(obj):
return

container = object
for id, object in container.items():
_search_helper(id, object, container, id_filters, object_filters, result)
for key, value in obj.items():
_search_helper(key, value, obj, id_filters, object_filters, result)


class SearchableTextFindFilter(object):
Expand Down

0 comments on commit 0d52e15

Please sign in to comment.