[Zope3-checkins] CVS: Zope3/src/zope/app/utilities/tests - test_interface.py:1.2 test_schemautilitypersistence.py:1.2 unitfixtures.py:1.2

Sidnei da Silva sidnei at x3ng.com.br
Wed Oct 8 09:10:13 EDT 2003


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

Added Files:
	test_interface.py test_schemautilitypersistence.py 
	unitfixtures.py 
Log Message:
Merging schema-utility-persistence and schema-utility-struct-failure branches. Still get a failing test, which I commented out for now.

=== Zope3/src/zope/app/utilities/tests/test_interface.py 1.1 => 1.2 ===
--- /dev/null	Wed Oct  8 09:10:13 2003
+++ Zope3/src/zope/app/utilities/tests/test_interface.py	Wed Oct  8 09:10:11 2003
@@ -0,0 +1,53 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+
+import unittest
+from zope.app.utilities.tests.unitfixtures import *  # hehehe
+from zope.interface.interface import Attribute
+from zope.interface.tests.test_interface import InterfaceTests as BaseTest
+from zope.app.tests import setup
+
+class InterfaceTests(BaseTest):
+
+    def setUp(self):
+        setup.placefulSetUp()
+
+    def tearDown(self):
+        setup.placefulTearDown()
+
+class _I1(Schema):
+
+    def f11(): pass
+    def f12(): pass
+    f12.optional = 1
+
+_I1.addField('a1', Attribute("This is an attribute"))
+
+class _I1_(_I1): pass
+class _I1__(_I1_): pass
+
+class _I2(_I1__):
+    def f21(): pass
+    def f22(): pass
+    f23 = f22
+
+
+def test_suite():
+    return unittest.makeSuite(InterfaceTests)
+
+def main():
+    unittest.TextTestRunner().run(test_suite())
+
+if __name__=="__main__":
+    main()


=== Zope3/src/zope/app/utilities/tests/test_schemautilitypersistence.py 1.1 => 1.2 ===
--- /dev/null	Wed Oct  8 09:10:13 2003
+++ Zope3/src/zope/app/utilities/tests/test_schemautilitypersistence.py	Wed Oct  8 09:10:11 2003
@@ -0,0 +1,108 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""Tests for Schema Utility Persistence
+
+$Id$
+"""
+
+import unittest
+
+from persistence.tests.test_persistence import PersistentTest, DM
+from persistence.wrapper import Struct
+from zope.app.utilities.schema import SchemaUtility
+from zope.schema import Text, getFieldsInOrder
+from zope.app.tests import setup
+
+class PSchema(SchemaUtility):
+
+    def __init__(self):
+        super(PSchema, self).__init__()
+        self.x = 0
+        self.setName('PSchema')
+
+    def inc(self):
+        self.x += 1
+
+class PersistentSchemaUtilityTest(PersistentTest):
+
+    klass = PSchema
+
+    def setUp(self):
+        PersistentTest.setUp(self)
+        setup.placefulSetUp(self)
+
+    def testState(self):
+        pass
+
+#     def testAddField(self):
+#         f = Text(title=u'alpha')
+#         p = self.klass()
+#         p._p_oid = '\0\0\0\0\0\0hi'
+#         dm = DM()
+#         p._p_jar = dm
+#         self.assertEqual(p._p_changed, 0)
+#         self.assertEqual(dm.called, 0)
+#         p.addField('alpha', f)
+#         self.assertEqual(p._p_changed, 1)
+#         self.assertEqual(dm.called, 1)
+
+#     def testRemoveField(self):
+#         f = Text(title=u'alpha')
+#         p = self.klass()
+#         p._p_oid = '\0\0\0\0\0\0hi'
+#         dm = DM()
+#         p._p_jar = dm
+#         self.assertEqual(p._p_changed, 0)
+#         self.assertEqual(dm.called, 0)
+#         p.addField('alpha', f)
+#         self.assertEqual(p._p_changed, 1)
+#         self.assertEqual(dm.called, 1)
+#         p._p_changed = 0
+#         self.assertEqual(p._p_changed, 0)
+#         self.assertEqual(dm.called, 1)
+#         p.removeField('alpha')
+#         self.assertEqual(p._p_changed, 1)
+#         self.assertEqual(dm.called, 2)
+
+#     def testChangeField(self):
+#         f = Text(title=u'alpha')
+#         p = self.klass()
+#         p._p_oid = '\0\0\0\0\0\0hi'
+#         dm = DM()
+#         p._p_jar = dm
+#         self.assertEqual(p._p_changed, 0)
+#         self.assertEqual(dm.called, 0)
+#         p.addField('alpha', f)
+#         self.assertEqual(p._p_changed, 1)
+#         self.assertEqual(dm.called, 1)
+#         p._p_changed = 0
+#         self.assertEqual(p._p_changed, 0)
+#         self.assertEqual(dm.called, 1)
+#         field = p['alpha']
+#         field.title = u'Beta'
+#         self.assertEqual(f._p_changed, 1)
+#         self.assertEqual(p._p_changed, 1)
+#         self.assertEqual(dm.called, 2)
+
+    def tearDown(self):
+        PersistentTest.tearDown(self)
+        setup.placefulTearDown()
+
+def test_suite():
+    suite = unittest.TestSuite()
+    suite.addTest(unittest.makeSuite(PersistentSchemaUtilityTest))
+    return suite
+
+if __name__ == '__main__':
+    unittest.main()


=== Zope3/src/zope/app/utilities/tests/unitfixtures.py 1.1 => 1.2 ===
--- /dev/null	Wed Oct  8 09:10:13 2003
+++ Zope3/src/zope/app/utilities/tests/unitfixtures.py	Wed Oct  8 09:10:11 2003
@@ -0,0 +1,123 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+from zope.app.utilities.schema import SchemaUtility
+from zope.interface.interface import Attribute
+from zope.app.event.tests.placelesssetup import PlacelessSetup
+# Setup EventPublication service.
+PlacelessSetup().setUp()
+
+Schema = SchemaUtility()
+Schema.setName('Schema')
+
+class mytest(Schema):
+    pass
+
+class C:
+    def m1(self, a, b):
+        "return 1"
+        return 1
+
+    def m2(self, a, b):
+        "return 2"
+        return 2
+
+# testInstancesOfClassImplements
+
+
+
+
+#  YAGNI IC=Interface.impliedInterface(C)
+class IC(Schema):
+    def m1(a, b):
+        "return 1"
+
+    def m2(a, b):
+        "return 2"
+
+
+
+C.__implements__=IC
+
+class I1(Schema):
+    def ma():
+        "blah"
+
+class I2(I1): pass
+
+class I3(Schema): pass
+
+class I4(Schema): pass
+
+class A(I1.deferred()):
+    __implements__=I1
+
+class B:
+    __implements__=I2, I3
+
+class D(A, B): pass
+
+class E(A, B):
+    __implements__ = A.__implements__, C.__implements__
+
+
+class FooInterface(Schema):
+    """ This is an Abstract Base Class """
+
+    def aMethod(foo, bar, bingo):
+        """ This is aMethod """
+
+    def anotherMethod(foo=6, bar="where you get sloshed", bingo=(1,3,)):
+        """ This is anotherMethod """
+
+    def wammy(zip, *argues):
+        """ yadda yadda """
+
+    def useless(**keywords):
+        """ useless code is fun! """
+
+FooInterface.addField('foobar', Attribute("fuzzed over beyond all recognition"))
+
+class Foo:
+    """ A concrete class """
+
+    __implements__ = FooInterface,
+
+    foobar = "yeah"
+
+    def aMethod(self, foo, bar, bingo):
+        """ This is aMethod """
+        return "barf!"
+
+    def anotherMethod(self, foo=6, bar="where you get sloshed", bingo=(1,3,)):
+        """ This is anotherMethod """
+        return "barf!"
+
+    def wammy(self, zip, *argues):
+        """ yadda yadda """
+        return "barf!"
+
+    def useless(self, **keywords):
+        """ useless code is fun! """
+        return "barf!"
+
+foo_instance = Foo()
+
+class Blah:
+    pass
+
+new = Schema.__class__
+FunInterface = new('FunInterface')
+BarInterface = new('BarInterface', [FunInterface])
+BobInterface = new('BobInterface')
+BazInterface = new('BazInterface', [BobInterface, BarInterface])




More information about the Zope3-Checkins mailing list