Skip to content

Commit

Permalink
Fixed warnings, use zope.app.zcmlfiles directly in ZCML files.
Browse files Browse the repository at this point in the history
  • Loading branch information
baijum committed Dec 23, 2006
1 parent 5a40146 commit f299852
Show file tree
Hide file tree
Showing 3 changed files with 215 additions and 3 deletions.
142 changes: 142 additions & 0 deletions codemodule/browser/tests.py
@@ -0,0 +1,142 @@
##############################################################################
#
# Copyright (c) 2004 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Tests for the Code Documentation Module
$Id$
"""
import os
import unittest
from zope.component.interfaces import IFactory
from zope.configuration import xmlconfig
from zope.interface import directlyProvides, implements
from zope.testing import doctest, doctestunit
from zope.traversing.interfaces import IContainmentRoot

import zope.app
import zope.app.appsetup.appsetup
from zope.app.renderer.rest import ReStructuredTextSourceFactory
from zope.app.renderer.rest import IReStructuredTextSource
from zope.app.renderer.rest import ReStructuredTextToHTMLRenderer
from zope.app.testing import placelesssetup, setup, ztapi

from zope.app.apidoc.interfaces import IDocumentationModule
from zope.app.apidoc.codemodule.interfaces import IAPIDocRootModule
from zope.app.apidoc.codemodule.codemodule import CodeModule
from zope.app.apidoc.zcmlmodule import ZCMLModule

# Just for loading purposes
import zope.app.apidoc.codemodule.browser.module
import zope.app.apidoc.codemodule.browser.class_
import zope.app.apidoc.codemodule.browser.function
import zope.app.apidoc.codemodule.browser.text
import zope.app.apidoc.codemodule.browser.zcml

def foo(cls, bar=1, *args):
"""This is the foo function."""
foo.deprecated = True

meta = '''
<configure
xmlns:meta="http://namespaces.zope.org/meta"
i18n_domain="zope">
<meta:provides feature="devmode" />
<include package="zope.app.zcmlfiles" file="meta.zcml" />
<include package="zope.app.apidoc" file="meta.zcml" />
<include package="zope.app.zcmlfiles" file="menus.zcml" />
</configure>
'''

def setUp(test):
test.globs['rootFolder'] = setup.placefulSetUp(True)

class RootModule(str):
implements(IAPIDocRootModule)
ztapi.provideUtility(IAPIDocRootModule, RootModule('zope'), "zope")

module = CodeModule()
module.__name__ = ''
directlyProvides(module, IContainmentRoot)
ztapi.provideUtility(IDocumentationModule, module, "Code")

module = ZCMLModule()
module.__name__ = ''
directlyProvides(module, IContainmentRoot)
ztapi.provideUtility(IDocumentationModule, module, "ZCML")

# Register Renderer Components
ztapi.provideUtility(IFactory, ReStructuredTextSourceFactory,
'zope.source.rest')
ztapi.browserView(IReStructuredTextSource, '',
ReStructuredTextToHTMLRenderer)
# Cheat and register the ReST factory for STX as well.
ztapi.provideUtility(IFactory, ReStructuredTextSourceFactory,
'zope.source.stx')

# Register ++apidoc++ namespace
from zope.app.apidoc.apidoc import apidocNamespace
from zope.traversing.interfaces import ITraversable
ztapi.provideAdapter(None, ITraversable, apidocNamespace, name="apidoc")
ztapi.provideView(None, None, ITraversable, "apidoc", apidocNamespace)

# Register ++apidoc++ namespace
from zope.traversing.namespace import view
from zope.traversing.interfaces import ITraversable
ztapi.provideAdapter(None, ITraversable, view, name="view")
ztapi.provideView(None, None, ITraversable, "view", view)

context = xmlconfig.string(meta)

# Fix up path for tests.
global old_context
old_context = zope.app.appsetup.appsetup.__config_context
zope.app.appsetup.appsetup.__config_context = context

# Fix up path for tests.
global old_source_file
old_source_file = zope.app.appsetup.appsetup.__config_source
zope.app.appsetup.appsetup.__config_source = os.path.join(
os.path.dirname(zope.app.zcmlfiles.__file__), 'meta.zcml')

# Register the index.html view for codemodule.class_.Class
from zope.publisher.browser import BrowserView
from zope.app.apidoc.codemodule.class_ import Class
from zope.app.apidoc.codemodule.browser.class_ import ClassDetails
class Details(ClassDetails, BrowserView):
pass
ztapi.browserView(Class, 'index.html', Details)


def tearDown(test):
setup.placefulTearDown()
global old_context, old_source_file
zope.app.appsetup.appsetup.__config_context = old_context
zope.app.appsetup.appsetup.__config_source = old_source_file


def test_suite():
return unittest.TestSuite((
doctest.DocFileSuite(
'README.txt',
setUp=setUp, tearDown=tearDown,
globs={'pprint': doctestunit.pprint},
optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS),
doctest.DocTestSuite(
'zope.app.apidoc.codemodule.browser.menu',
setUp=setUp, tearDown=tearDown,
globs={'pprint': doctestunit.pprint},
optionflags=doctest.NORMALIZE_WHITESPACE),
))

if __name__ == '__main__':
unittest.main(default="test_suite")
70 changes: 70 additions & 0 deletions codemodule/tests.py
@@ -0,0 +1,70 @@
##############################################################################
#
# Copyright (c) 2004 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Tests for the Code Documentation Module
$Id$
"""
import os
import unittest
from zope.configuration import xmlconfig
from zope.testing import doctest, doctestunit

import zope.app.appsetup.appsetup
from zope.app.testing import placelesssetup


def setUp(test):
placelesssetup.setUp()

meta = '''
<configure
xmlns:meta="http://namespaces.zope.org/meta"
i18n_domain="zope">
<meta:provides feature="devmode" />
<include package="zope.app.zcmlfiles" file="meta.zcml" />
<include package="zope.app.zcmlfiles" file="menus.zcml" />
</configure>
'''
xmlconfig.string(meta)

meta = os.path.join(os.path.dirname(zope.app.zcmlfiles.__file__), 'meta.zcml')
context = xmlconfig.file(meta, zope.app.zcmlfiles)
context.provideFeature('devmode')
meta = os.path.join(os.path.dirname(zope.app.apidoc.__file__), 'meta.zcml')
context = xmlconfig.file(meta, zope.app.apidoc, context)

# Fix up path for tests.
global old_context
old_context = zope.app.appsetup.appsetup.__config_context
zope.app.appsetup.appsetup.__config_context = context

def tearDown(test):
placelesssetup.tearDown()
global old_context
zope.app.appsetup.appsetup.__config_context = old_context


def test_suite():
return unittest.TestSuite((
doctest.DocFileSuite('README.txt',
setUp=setUp, tearDown=tearDown,
globs={'pprint': doctestunit.pprint},
optionflags=doctest.NORMALIZE_WHITESPACE),
doctest.DocFileSuite('directives.txt',
setUp=placelesssetup.setUp,
tearDown=placelesssetup.tearDown),
))

if __name__ == '__main__':
unittest.main(default="test_suite")
6 changes: 3 additions & 3 deletions zcmlmodule/tests.py
Expand Up @@ -31,7 +31,7 @@
from zope.app.apidoc.zcmlmodule import Namespace, Directive
from zope.app.apidoc.zcmlmodule import ZCMLModule
from zope.app.apidoc.tests import Root

import zope.app.zcmlfiles

def setUp(test):
placelesssetup.setUp()
Expand All @@ -40,13 +40,13 @@ def setUp(test):
ztapi.provideAdapter(None, IPhysicallyLocatable,
LocationPhysicallyLocatable)

config_file = os.path.join(os.path.dirname(zope.app.__file__), 'meta.zcml')
config_file = os.path.join(os.path.dirname(zope.app.zcmlfiles.__file__), 'meta.zcml')

# Fix up path for tests.
global old_context
old_context = zope.app.appsetup.appsetup.getConfigContext()
zope.app.appsetup.appsetup.__config_context = xmlconfig.file(
config_file, zope.app, execute=False)
config_file, zope.app.zcmlfiles, execute=False)

def tearDown(test):
placelesssetup.tearDown()
Expand Down

0 comments on commit f299852

Please sign in to comment.