[Zope3-checkins] CVS: Zope3/src/zope/app/renderer/tests - __init__.py:1.1 renderer.zcml:1.1 test_directives.py:1.1 test_plaintext.py:1.1 test_rest.py:1.1 test_stx.py:1.1

Stephan Richter srichter@cosmos.phy.tufts.edu
Thu, 31 Jul 2003 13:59:49 -0400


Update of /cvs-repository/Zope3/src/zope/app/renderer/tests
In directory cvs.zope.org:/tmp/cvs-serv10168/renderer/tests

Added Files:
	__init__.py renderer.zcml test_directives.py test_plaintext.py 
	test_rest.py test_stx.py 
Log Message:
First checkin of the ZWiki Renderer package into the core. The renderer
package can convert some sort of code to a particular presentation. Examples
include ReST --> HTML or Plain Text to HTML. However, it could be also used
to convert Python code --> Pretty HTML Python code and so on. 

To Do:

- Make a vocabulary, so that it is easier to list all the available source 
  types in an HTML form.

- Update Wiki code. (This actually already done...)



=== Added File Zope3/src/zope/app/renderer/tests/__init__.py ===


=== Added File Zope3/src/zope/app/renderer/tests/renderer.zcml ===
<configure xmlns="http://namespaces.zope.org/zope"
           xmlns:meta="http://namespaces.zope.org/meta"
           xmlns:renderer="http://namespaces.zope.org/renderer">

  <include package="zope.app.renderer" file="meta.zcml"/>

  <renderer:sourcetype 
      title="Test Text" 
      interface=".tests.test_directives.ITestSource"
      class=".tests.test_directives.TestSource"/>

  <renderer:renderer
      sourceType=".tests.test_directives.ITestSource"
      for="zope.publisher.interfaces.browser.IBrowserPresentation" 
      factory=".tests.test_directives.TestRenderer" />
 

</configure>

  


=== Added File Zope3/src/zope/app/renderer/tests/test_directives.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""Test the wiki ZCML namespace directives.

$Id: test_directives.py,v 1.1 2003/07/31 17:59:41 srichter Exp $
"""
import os
import unittest

from cStringIO import StringIO

from zope.interface import Interface, implements
from zope.component import getView
from zope.component.tests.placelesssetup import PlacelessSetup
from zope.configuration import xmlconfig, tests
from zope.publisher.browser import BrowserView, TestRequest

import zope.app.renderer
from zope.app.renderer.sourcetype import SourceTypes


class ITestSource(Interface):
    pass

class TestSource(unicode):
    implements(ITestSource)
    

class TestRenderer(BrowserView):
    __used_for__ = ITestSource


class DirectivesTest(PlacelessSetup, unittest.TestCase):

    def setUp(self):
        PlacelessSetup.setUp(self)
        self.context = xmlconfig.file("simple.zcml", tests)

    def test_sourcetype(self):
        self.assertEqual(SourceTypes.getAllTitles(), [])
        self.context = xmlconfig.file("tests/renderer.zcml", zope.app.renderer)
        self.assertEqual(SourceTypes.getAllTitles(), ['Test Text'])
        self.assertEqual(
            SourceTypes.get('Test Text'),
            zope.app.renderer.tests.test_directives.ITestSource)
        
        obj = SourceTypes.createObject('Test Text', 'Source')
        self.assertEqual(
            getView(obj, None, TestRequest()).__class__,
            zope.app.renderer.tests.test_directives.TestRenderer)


def test_suite():
    return unittest.TestSuite((
        unittest.makeSuite(DirectivesTest),
        ))

if __name__ == '__main__':
    unittest.main()


=== Added File Zope3/src/zope/app/renderer/tests/test_plaintext.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""Plain Text Tests - PlainText Source, HTML Renderer

$Id: test_plaintext.py,v 1.1 2003/07/31 17:59:41 srichter Exp $
"""
import unittest

from zope.publisher.browser import TestRequest

from zope.app.interfaces.renderer import IPlainTextSource, IHTMLRenderer
from zope.app.renderer.plaintext import \
     PlainTextSource, PlainTextToHTMLRenderer


class PlainTextTest(unittest.TestCase):

    def setUp(self):
        self._source = PlainTextSource(u'This is source.')

    def test_Interface(self):
        self.failUnless(IPlainTextSource.isImplementedBy(self._source))

    def test_createComment(self):
        self.assertEqual(comment,
                         self._source.createComment('This is a Comment.', 2,
                                                    'srichter',
                                                    '04/12/2003 12:00:00'))
        self.assertEqual(first_comment,
                         self._source.createComment('This is a Comment.', 1,
                                                    'srichter',
                                                    '04/12/2003 12:00:00'))


class HTMLRendererTest(unittest.TestCase):

    def setUp(self):
        self._source = PlainTextSource(u'This is source.\n')
        self._renderer = PlainTextToHTMLRenderer(self._source, TestRequest())

    def test_Interface(self):
        self.failUnless(IHTMLRenderer.isImplementedBy(self._renderer))

    def test_render(self):
        self.assertEqual('This is source.<br/>\n', self._renderer.render(None))
        comment = self._source.createComment('This is a Comment.', 1,
                                             'srichter',
                                             '04/12/2003 12:00:00')
        self._renderer.context = PlainTextSource(self._source+comment)

        self.assertEqual(rendered_source_comment, self._renderer.render(None))
        

comment = '''

Comment #2 by srichter (04/12/2003 12:00:00)
This is a Comment.'''

first_comment = '''
----------

Comment #1 by srichter (04/12/2003 12:00:00)
This is a Comment.'''

rendered_source_comment = '''This is source.<br/>
<br/>
<hr class="comments" size="1" NOSHADE>
<br/>
Comment #1 by srichter (04/12/2003 12:00:00)<br/>
This is a Comment.'''

    
def test_suite():
    return unittest.TestSuite((
        unittest.makeSuite(PlainTextTest),
        unittest.makeSuite(HTMLRendererTest),
        ))

if __name__ == '__main__':
    unittest.main()


=== Added File Zope3/src/zope/app/renderer/tests/test_rest.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""Structured Text Tests - StructuredText Source, HTML Renderer

$Id: test_rest.py,v 1.1 2003/07/31 17:59:41 srichter Exp $
"""
import unittest

from zope.publisher.browser import TestRequest

from zope.app.interfaces.renderer import \
     IReStructuredTextSource, IHTMLRenderer
from zope.app.renderer.rest import \
     ReStructuredTextSource, ReStructuredTextToHTMLRenderer


class ReStructuredTextTest(unittest.TestCase):

    def setUp(self):
        self._source = ReStructuredTextSource(u'This\n is source.')

    def test_Interface(self):
        self.failUnless(IReStructuredTextSource.isImplementedBy(self._source))

    def test_createComment(self):
        self.assertEqual(comment,
                         self._source.createComment('This is a Comment.', 2,
                                                    'srichter',
                                                    '04/12/2003 12:00:00'))
        self.assertEqual(first_comment,
                         self._source.createComment('This is a Comment.', 1,
                                                    'srichter',
                                                    '04/12/2003 12:00:00'))


class HTMLRendererTest(unittest.TestCase):

    def setUp(self):
        self._source = ReStructuredTextSource(u'This is source.\n')
        self._renderer = ReStructuredTextToHTMLRenderer(self._source,
                                                        TestRequest())

    def test_Interface(self):
        self.failUnless(IHTMLRenderer.isImplementedBy(self._renderer))

    def test_render(self):
        self.assertEqual('<div class="document">\nThis is source.</div>\n',
                         self._renderer.render(None))
        comment = self._source.createComment('This is a Comment.', 1,
                                             'srichter',
                                             '04/12/2003 12:00:00')
        self._renderer.context = ReStructuredTextSource(self._source+comment)

        self.assertEqual(rendered_source_comment, self._renderer.render(None))


comment = '''

Comment #2 by **srichter** (04/12/2003 12:00:00)

This is a Comment.'''

first_comment = '''
----------

Comment #1 by **srichter** (04/12/2003 12:00:00)

This is a Comment.'''

rendered_source_comment = '''<div class="document">\n<p>This is source.</p>
<hr />
<p>Comment #1 by <strong>srichter</strong> (04/12/2003 12:00:00)</p>
<p>This is a Comment.</p>
</div>
'''


def test_suite():
    return unittest.TestSuite((
        unittest.makeSuite(ReStructuredTextTest),
        unittest.makeSuite(HTMLRendererTest),
        ))

if __name__ == '__main__':
    unittest.main()


=== Added File Zope3/src/zope/app/renderer/tests/test_stx.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""Structured Text Tests - StructuredText Source, HTML Renderer

$Id: test_stx.py,v 1.1 2003/07/31 17:59:41 srichter Exp $
"""
import unittest

from zope.publisher.browser import TestRequest

try:
    from zope.app.interfaces.renderer import \
         IStructuredTextSource, IHTMLRenderer
    from zope.app.renderer.stx import \
         StructuredTextSource, StructuredTextToHTMLRenderer
except ImportError:
    pass

class StructuredTextTest(unittest.TestCase):

    def setUp(self):
        self._source = StructuredTextSource(u'This\n is source.')

    def test_Interface(self):
        self.failUnless(IStructuredTextSource.isImplementedBy(self._source))

    def test_createComment(self):
        self.assertEqual(comment,
                         self._source.createComment('This is a Comment.', 2,
                                                    'srichter',
                                                    '04/12/2003 12:00:00'))
        self.assertEqual(first_comment,
                         self._source.createComment('This is a Comment.', 1,
                                                    'srichter',
                                                    '04/12/2003 12:00:00'))


class HTMLRendererTest(unittest.TestCase):

    def setUp(self):
        self._source = StructuredTextSource(u'This is source.\n')
        self._renderer = StructuredTextToHTMLRenderer(self._source,
                                                      TestRequest())

    def test_Interface(self):
        self.failUnless(IHTMLRenderer.isImplementedBy(self._renderer))

    def test_render(self):
        self.assertEqual('<p>This is source.</p>\n',
                         self._renderer.render(None))
        comment = self._source.createComment('This is a Comment.', 1,
                                             'srichter',
                                             '04/12/2003 12:00:00')
        self._renderer.context = StructuredTextSource(self._source+comment)

        self.assertEqual(rendered_source_comment, self._renderer.render(None))
        

comment = '''

Comment #2 by **srichter** (04/12/2003 12:00:00)

This is a Comment.'''

first_comment = '''

----------

Comment #1 by **srichter** (04/12/2003 12:00:00)

This is a Comment.'''

rendered_source_comment = '''<p>This is source.</p>
<hr class="comments" size="1" NOSHADE>
<p>Comment #1 by <strong>srichter</strong> (04/12/2003 12:00:00)</p>
<p>This is a Comment.</p>
'''

    
def test_suite():
    suite = unittest.TestSuite()
    try:
        import StructuredText
    except ImportError:
        pass
    else:
        suite.addTest(unittest.makeSuite(StructuredTextTest))
        suite.addTest(unittest.makeSuite(HTMLRendererTest))
    return suite

if __name__ == '__main__':
    unittest.main()