Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed warnings, use zope.app.zcmlfiles directly in ZCML files.
- Loading branch information
Showing
3 changed files
with
215 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters