Author: eudoxos
Date: 2009-08-04 20:12:39 +0200 (Tue, 04 Aug 2009)
New Revision: 1919

Added:
   trunk/py/tests/
   trunk/py/tests/__init__.py
   trunk/py/tests/wrapper.py
   trunk/scripts/regression-tests.py
Modified:
   trunk/py/SConscript
   trunk/py/yadeWrapper/yadeWrapper.cpp
Log:
1. Initial attempt at regression tests (only the python wrapper so far); run 
scripts/regression-tests.py
2. Fix a few bugs discovered that way :-)


Modified: trunk/py/SConscript
===================================================================
--- trunk/py/SConscript 2009-08-04 17:25:28 UTC (rev 1918)
+++ trunk/py/SConscript 2009-08-04 18:12:39 UTC (rev 1919)
@@ -31,6 +31,10 @@
                        ),
                
env.SharedLibrary('_customConverters',['yadeWrapper/customConverters.cpp'],SHLIBPREFIX='',LIBS=env['LIBS']+['boost_python_indexing_suite_v2']+linkPlugins(Split("BoundingVolumeEngineUnit
 GeometricalModelEngineUnit InteractingGeometryEngineUnit 
InteractionGeometryEngineUnit InteractionPhysicsEngineUnit 
PhysicalParametersEngineUnit PhysicalActionDamperUnit PhysicalActionApplierUnit 
ConstitutiveLaw")))
        ])
+       env.Install('$PREFIX/lib/yade$SUFFIX/py/yade/tests',[
+               env.File('__init__.py','tests'),
+               env.File('wrapper.py','tests')
+       ])
 
        # 3rd party modules:
        # ==================

Added: trunk/py/tests/__init__.py
===================================================================
--- trunk/py/tests/__init__.py  2009-08-04 17:25:28 UTC (rev 1918)
+++ trunk/py/tests/__init__.py  2009-08-04 18:12:39 UTC (rev 1919)
@@ -0,0 +1 @@
+# python knows by this file that this directory is an importable module

Added: trunk/py/tests/wrapper.py
===================================================================
--- trunk/py/tests/wrapper.py   2009-08-04 17:25:28 UTC (rev 1918)
+++ trunk/py/tests/wrapper.py   2009-08-04 18:12:39 UTC (rev 1919)
@@ -0,0 +1,67 @@
+import unittest
+from yade.wrapper import *
+
+# copied from PythonUI_rc, should be in some common place (utils? runtime?)
+def listChildClassesRecursive(base):
+       ret=set(O.childClasses(base)); ret2=set()
+       for bb in ret:
+               ret2|=listChildClassesRecursive(bb)
+       return ret | ret2
+
+
+rootClasses=set([
+       
'StandAloneEngine','DeusExMachina','GeometricalModel','InteractingGeometry','PhysicalParameters','BoundingVolume','InteractingGeometry','InteractionPhysics','FileGenerator',
+       
'BoundingVolumeEngineUnit','GeometricalModelEngineUnit','InteractingGeometryEngineUnit','InteractionGeometryEngineUnit','InteractionPhysicsEngineUnit','PhysicalParametersEngineUnit','PhysicalActionDamperUnit','PhysicalActionApplierUnit','ConstitutiveLaw',
+       
'BoundingVolumeMetaEngine','GeometricalModelMetaEngine','InteractingGeometryMetaEngine','InteractionGeometryMetaEngine','InteractionPhysicsMetaEngine','PhysicalParametersMetaEngine','PhysicalActionDamper','PhysicalActionApplier','ConstitutiveLawDispatcher'])
+allClasses=listChildClassesRecursive('Serializable')
+
+class TestObjectInstantiation(unittest.TestCase):
+       def setUp(self):
+               pass # no setup needed for tests here
+       def testSerializableCtors(self):
+               # correct instances created with Serializable('Foo') syntax
+               for r in rootClasses:
+                       obj=Serializable(r); self.assert_(obj.name==r,'Failed 
for '+r)
+       def testRootCtors(self):
+               # correct instances created with Foo() syntax
+               for r in rootClasses:
+                       obj=eval(r)(); self.assert_(obj.name==r,'Failed for '+r)
+       def testSerializableCtors_attrs_few(self):
+               # attributes passed when using the 
Serializable('Foo',attr1=value1,attr2=value2) syntax
+               gm=Serializable('GeometricalModel',wire=True); 
self.assert_(gm['wire']==True)
+       def testRootDerivedCtors(self):
+               # classes that are not root classes but derive from them can be 
instantiated by their name
+               for r in rootClasses:
+                       for c in listChildClassesRecursive(r):
+                               obj=eval(c)(); self.assert_(obj.name==c,'Failed 
for '+c)
+       def testRootDerivedCtors_attrs_few(self):
+               # attributes passed when using the 
Foo(attr1=value1,attr2=value2) syntax
+               gm=GeometricalModel(wire=True); self.assert_(gm['wire']==True)
+       def testNonderived_attrs_few(self):
+               # classes deriving just from Serializable can be instantiated 
by their name directly, including attributes
+               glds=GLDrawSphere(glutUse=True,glutSlices=24); 
self.assert_(glds.name=='GLDrawSphere')
+       def testDispatcherCtor(self):
+               # dispatchers take list of their functors in the ctor
+               # same functors are collapsed in one
+               
cld1=ConstitutiveLawDispatcher([Law2_Dem3Dof_Elastic_Elastic(),Law2_Dem3Dof_Elastic_Elastic()]);
 self.assert_(len(cld1.functors)==1)
+               # two different make two different, right?
+               
cld2=ConstitutiveLawDispatcher([Law2_Dem3Dof_Elastic_Elastic(),Law2_Dem3DofGeom_CpmPhys_Cpm()]);
 self.assert_(len(cld2.functors)==2)
+       def testInteractionDispatchersCtor(self):
+               # InteractionDispatchers takes 3 lists
+               
id=InteractionDispatchers([ef2_Facet_Sphere_Dem3DofGeom(),ef2_Sphere_Sphere_Dem3DofGeom()],[SimpleElasticRelationships()],[Law2_Dem3Dof_Elastic_Elastic()],)
+               self.assert_(len(id.geomDispatcher.functors)==2)
+               
self.assert_(id.geomDispatcher.name=='InteractionGeometryMetaEngine')
+               
self.assert_(id.physDispatcher.functors[0].name=='SimpleElasticRelationships')
+               
self.assert_(id.constLawDispatcher.functors[0].name=='Law2_Dem3Dof_Elastic_Elastic')
+       def testParallelEngineCtor(self):
+               pass
+       ## test what shold fail:
+       ## passing wrong EngineUnit type to a dispatcher
+       ## reading/writing non-existent attribute
+
+def run():
+       
suite=unittest.TestLoader().loadTestsFromTestCase(TestObjectInstantiation)
+       unittest.TextTestRunner(verbosity=2).run(suite)
+       
+
+               

Modified: trunk/py/yadeWrapper/yadeWrapper.cpp
===================================================================
--- trunk/py/yadeWrapper/yadeWrapper.cpp        2009-08-04 17:25:28 UTC (rev 
1918)
+++ trunk/py/yadeWrapper/yadeWrapper.cpp        2009-08-04 18:12:39 UTC (rev 
1919)
@@ -688,8 +688,8 @@
                
.add_property("execTime",&Engine_timingInfo_nsec_get,&Engine_timingInfo_nsec_set)
                
.add_property("execCount",&Engine_timingInfo_nExec_get,&Engine_timingInfo_nExec_set)
                .def_readonly("timingDeltas",&Engine::timingDeltas);
-       python::class_<StandAloneEngine,shared_ptr<StandAloneEngine>, 
python::bases<Engine>, 
noncopyable>("StandAloneEngine").def("__init__",python::raw_constructor(Serializable_ctor_kwAttrs<Engine>));
-       python::class_<DeusExMachina,shared_ptr<DeusExMachina>, 
python::bases<Engine>, 
noncopyable>("DeusExMachina").def("__init__",python::raw_constructor(Serializable_ctor_kwAttrs<Engine>));
+       python::class_<StandAloneEngine,shared_ptr<StandAloneEngine>, 
python::bases<Engine>, 
noncopyable>("StandAloneEngine").def("__init__",python::raw_constructor(Serializable_ctor_kwAttrs<StandAloneEngine>));
+       python::class_<DeusExMachina,shared_ptr<DeusExMachina>, 
python::bases<Engine>, 
noncopyable>("DeusExMachina").def("__init__",python::raw_constructor(Serializable_ctor_kwAttrs<DeusExMachina>));
        python::class_<EngineUnit, shared_ptr<EngineUnit>, 
python::bases<Serializable>, noncopyable >("EngineUnit",python::no_init)
                .def_readonly("timingDeltas",&EngineUnit::timingDeltas)
                .add_property("bases",&EngineUnit::getFunctorTypes);

Added: trunk/scripts/regression-tests.py
===================================================================
--- trunk/scripts/regression-tests.py   2009-08-04 17:25:28 UTC (rev 1918)
+++ trunk/scripts/regression-tests.py   2009-08-04 18:12:39 UTC (rev 1919)
@@ -0,0 +1,4 @@
+# Run regression tests
+# All of them should be enumerated here, so that we can run them at once.
+from yade.tests import wrapper # add module2,module3 as they become available
+wrapper.run()


_______________________________________________
Mailing list: https://launchpad.net/~yade-dev
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~yade-dev
More help   : https://help.launchpad.net/ListHelp
_______________________________________________
yade-dev mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/yade-dev

Reply via email to