[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/schemagen/tests - test_modulegen.py:1.2
Martijn Faassen
m.faassen@vet.uu.nl
Thu, 12 Dec 2002 04:17:47 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/schemagen/tests
In directory cvs.zope.org:/tmp/cvs-serv4472/tests
Modified Files:
test_modulegen.py
Log Message:
Added some tests of the generated class.
=== Zope3/lib/python/Zope/App/schemagen/tests/test_modulegen.py 1.1 => 1.2 ===
--- Zope3/lib/python/Zope/App/schemagen/tests/test_modulegen.py:1.1 Wed Dec 11 14:07:23 2002
+++ Zope3/lib/python/Zope/App/schemagen/tests/test_modulegen.py Thu Dec 12 04:17:46 2002
@@ -28,13 +28,15 @@
fields = []
- def test_generateModuleSource(self):
-
+ def setUp(self):
source = generateModuleSource('IFoo', self.fields, "Foo")
g = {}
exec source in g
del g['__builtins__'] # to ease inspection during debugging
- IFoo = g['IFoo']
+ self.g = g
+
+ def test_schema(self):
+ IFoo = self.g['IFoo']
fieldsorter = lambda x, y: cmp(x[1].order, y[1].order)
new_fields = getFields(IFoo).items()
@@ -45,15 +47,34 @@
# by execing generated module source again and then generating
# module source for the schema in that. This requires the arguments
# to fields (their properties) to be in their own schema order.
-
+
+ def test_class(self):
+ from Zope.Schema.FieldProperty import FieldProperty
+ IFoo = self.g['IFoo']
+ Foo = self.g['Foo']
+ self.assertEquals(Foo.__schema_version__, 0)
+ self.assertEquals(Foo.__implements__, IFoo)
+ for field_name, field in self.fields:
+ prop = getattr(Foo, field_name, None)
+ self.assert_(prop is not None)
+ self.assert_(type(prop) is FieldProperty)
+
+ def test_instance(self):
+ Foo = self.g['Foo']
+ foo = Foo()
+ for field_name, field in self.fields:
+ self.assertEquals(field.default, getattr(foo, field_name))
+
class GenerateModuleSourceTestsEmpty(GenerateModuleSourceTestsBase):
fields = []
class GenerateModuleSourceTests1(GenerateModuleSourceTestsBase):
fields = [('foo', Text(title=u"Foo")),
('bar', Int(title=u"Bar")),
- ('hoi', Float(title=u"Float"))]
-
+ ('hoi', Float(title=u"Float")),
+ ('dag', Int(title=u"Dag", default=42)),]
+
+
def test_suite():
return TestSuite(
(makeSuite(GenerateModuleSourceTestsEmpty),