[Zope-Checkins] CVS: Zope3/lib/python/Zope/ComponentArchitecture/tests - testSkins.py:1.1.2.1

Jim Fulton jim@zope.com
Sun, 6 Jan 2002 18:43:42 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/ComponentArchitecture/tests
In directory cvs.zope.org:/tmp/cvs-serv9153/tests

Added Files:
      Tag: Zope-3x-branch
	testSkins.py 
Log Message:
Separated ViewService implementation into separate module and added
skin support.


=== Added File Zope3/lib/python/Zope/ComponentArchitecture/tests/testSkins.py ===
##############################################################################
#
# Copyright (c) 2001 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
# 
##############################################################################

import unittest, sys

from Zope.ComponentArchitecture import defineSkin, provideView, getView, _clear
from Interface import Interface

class Test(unittest.TestCase):

    def tearDown(self):
        _clear()

    def testSkin(self):
        class I1(Interface): pass
        class I2(Interface): pass

        class C1:
            __implements__ = I2
            __used_for__ = I1
            def __init__(self, o): self._context=o
        class C2(C1): pass
        class C3(C1): pass

        class O: __implements__ = I1

        provideView(I1, 'test', I2, C1)
        self.assertEqual(getView(O(), 'test', I2).__class__, C1) 
        defineSkin('foo', ('foo', ''))
        self.assertEqual(getView(O(), 'test', I2, skin='foo').__class__, C1) 
        provideView(None, 'test', I2, C2)
        self.assertEqual(getView(O(), 'test', I2, skin='foo').__class__, C1) 
        provideView(None, 'test', I2, C2, layer='foo')
        self.assertEqual(getView(O(), 'test', I2, skin='foo').__class__, C2) 
        provideView(I1, 'test', I2, C3, layer='foo')
        self.assertEqual(getView(O(), 'test', I2, skin='foo').__class__, C3) 
        

def test_suite():
    loader=unittest.TestLoader()
    return loader.loadTestsFromTestCase(Test)

if __name__=='__main__':
    unittest.TextTestRunner().run(test_suite())