Skip to content
This repository has been archived by the owner on Jan 21, 2021. It is now read-only.

Commit

Permalink
Fixed a couple functional tests.
Browse files Browse the repository at this point in the history
Tried to remove the service terminology from the code as much as 
possible.
  • Loading branch information
strichter committed Jan 12, 2005
1 parent 6aa947f commit 1f12a0a
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions tests/test_interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
##############################################################################
#
# Copyright (c) 2003 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.
#
##############################################################################
"""Interfaces as Utilities Tests
$Id$
"""
__docformat__ = 'restructuredtext'

import unittest

from transaction import get_transaction

from ZODB.tests.util import DB
from zodbcode.module import ManagedRegistry

from zope.interface import Interface, implements
from zope.app.interface import PersistentInterface

# TODO: for some reason changing this code to use implements() does not
# work. This is due to a bug that is supposed to be fixed after X3.0.
code = """\
from zope.interface import Interface
class IFoo(Interface):
pass
# This must be a classobj
class Foo:
__implemented__ = IFoo
aFoo = Foo()
"""

class PersistentInterfaceTest(unittest.TestCase):

def setUp(self):
self.db = DB()
self.root = self.db.open().root()
self.registry = ManagedRegistry()
self.root["registry"] = self.registry
get_transaction().commit()

def tearDown(self):
get_transaction().abort() # just in case

def test_creation(self):
class IFoo(PersistentInterface):
pass

class Foo(object):
implements(IFoo)

self.assert_(IFoo.providedBy(Foo()))
self.assertEqual(IFoo._p_oid, None)

def test_patch(self):
self.registry.newModule("imodule", code)
get_transaction().commit()
imodule = self.registry.findModule("imodule")

# test for a pickling bug
self.assertEqual(imodule.Foo.__implemented__, imodule.IFoo)

self.assert_(imodule.IFoo.providedBy(imodule.aFoo))
# the conversion should not affect Interface
self.assert_(imodule.Interface is Interface)


def test_suite():
return unittest.makeSuite(PersistentInterfaceTest)

0 comments on commit 1f12a0a

Please sign in to comment.