[Zope3-checkins] CVS: Products3/demo/formatns/tests - __init__.py:1.1 test_formatns.py:1.1

Stephan Richter srichter at cosmos.phy.tufts.edu
Tue Sep 16 18:18:57 EDT 2003


Update of /cvs-repository/Products3/demo/formatns/tests
In directory cvs.zope.org:/tmp/cvs-serv14796/tests

Added Files:
	__init__.py test_formatns.py 
Log Message:
This is a demo product on how to develop your own TALES namespaces, which 
I imagine will be extremly useful. Furthermore, I think it is currently 
also the easiest way to extend Zope 3 in a very powerful way.

But please, do not misuse this feature!


=== Added File Products3/demo/formatns/tests/__init__.py ===


=== Added File Products3/demo/formatns/tests/test_formatns.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.
#
##############################################################################
"""Test TALES 'format' namespace.

$Id: test_formatns.py,v 1.1 2003/09/16 22:18:56 srichter Exp $
"""
import unittest
from datetime import datetime
from zope.publisher.browser import TestRequest
from zope.testing.doctestunit import DocTestSuite
from zopeproducts.demo.formatns import FormatTalesAPI

class Engine:
    vars = {'request': TestRequest()}

def getFormatNamespace(context):
    ns = FormatTalesAPI(context)
    ns.setEngine(Engine())
    return ns


def shortDate():
    """
    >>> ns = getFormatNamespace(datetime(2003, 9, 16, 16, 51, 01))
    >>> ns.shortDate()
    u'9/16/03'
    """
    
def mediumDate():
    """
    >>> ns = getFormatNamespace(datetime(2003, 9, 16, 16, 51, 01))
    >>> ns.mediumDate()
    u'Sep 16, 2003'
    """
    
def longDate():
    """
    >>> ns = getFormatNamespace(datetime(2003, 9, 16, 16, 51, 01))
    >>> ns.longDate()
    u'September 16, 2003'
    """

def fullDate():
    """
    >>> ns = getFormatNamespace(datetime(2003, 9, 16, 16, 51, 01))
    >>> ns.fullDate()
    u'Tuesday, September 16, 2003'
    """

def shortTime():
    """
    >>> ns = getFormatNamespace(datetime(2003, 9, 16, 16, 51, 01))
    >>> ns.shortTime()
    u'4:51 PM'
    """

def mediumTime():
    """
    >>> ns = getFormatNamespace(datetime(2003, 9, 16, 16, 51, 01))
    >>> ns.shortTime()
    u'4:51 PM'
    """

def longTime():
    """
    >>> ns = getFormatNamespace(datetime(2003, 9, 16, 16, 51, 01))
    >>> ns.shortTime()
    u'4:51 PM'
    """

def fullTime():
    """
    >>> ns = getFormatNamespace(datetime(2003, 9, 16, 16, 51, 01))
    >>> ns.shortTime()
    u'4:51 PM'
    """

def shortDateTime():
    """
    >>> ns = getFormatNamespace(datetime(2003, 9, 16, 16, 51, 01))
    >>> ns.shortDateTime()
    u'9/16/03 4:51 PM '
    """

def mediumDateTime():
    """
    >>> ns = getFormatNamespace(datetime(2003, 9, 16, 16, 51, 01))
    >>> ns.mediumDateTime()
    u'Sep 16, 2003 4:51:01 PM '
    """

def longDateTime():
    """
    >>> ns = getFormatNamespace(datetime(2003, 9, 16, 16, 51, 01))
    >>> ns.longDateTime()
    u'September 16, 2003 4:51:01 PM +000 '
    """

def fullDateTime():
    """
    >>> ns = getFormatNamespace(datetime(2003, 9, 16, 16, 51, 01))
    >>> ns.fullDateTime()
    u'Tuesday, September 16, 2003 4:51:01 PM +000 '
    """

def decimal():
    """
    >>> ns = getFormatNamespace(4.205)
    >>> ns.decimal()
    u'4.205'
    """

def percent():
    """
    >>> ns = getFormatNamespace(4412)
    >>> ns.percent()
    u'4,412%'
    """

def scientific():
    """
    >>> ns = getFormatNamespace(4421)
    >>> ns.scientific()
    u'4E3'
    """

def currency():
    """
    >>> ns = getFormatNamespace(4.205)
    >>> ns.currency()
    u'\\xa4 4.20'
    """

def test_suite():
    return DocTestSuite()

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




More information about the Zope3-Checkins mailing list