[cig-commits] r13199 - in short/3D/PyLith/trunk: pylith/utils unittests/libtests/utils unittests/pytests/bc unittests/pytests/faults unittests/pytests/feassemble unittests/pytests/materials unittests/pytests/meshio unittests/pytests/utils

brad at geodynamics.org brad at geodynamics.org
Thu Oct 30 20:55:49 PDT 2008


Author: brad
Date: 2008-10-30 20:55:49 -0700 (Thu, 30 Oct 2008)
New Revision: 13199

Modified:
   short/3D/PyLith/trunk/pylith/utils/EventLogger.py
   short/3D/PyLith/trunk/unittests/libtests/utils/TestEventLogger.cc
   short/3D/PyLith/trunk/unittests/libtests/utils/TestEventLogger.hh
   short/3D/PyLith/trunk/unittests/pytests/bc/TestAbsorbingDampers.py
   short/3D/PyLith/trunk/unittests/pytests/bc/TestNeumann.py
   short/3D/PyLith/trunk/unittests/pytests/faults/TestFaultCohesiveKin.py
   short/3D/PyLith/trunk/unittests/pytests/feassemble/TestElasticityExplicit.py
   short/3D/PyLith/trunk/unittests/pytests/feassemble/TestElasticityImplicit.py
   short/3D/PyLith/trunk/unittests/pytests/feassemble/TestQuadrature.py
   short/3D/PyLith/trunk/unittests/pytests/materials/TestMaterial.py
   short/3D/PyLith/trunk/unittests/pytests/meshio/TestCellFilterAvg.py
   short/3D/PyLith/trunk/unittests/pytests/utils/TestEventLogger.py
Log:
Added unit tests for stage logging. Fixed errors in Quadrature Python tests (add call to _configure()).

Modified: short/3D/PyLith/trunk/pylith/utils/EventLogger.py
===================================================================
--- short/3D/PyLith/trunk/pylith/utils/EventLogger.py	2008-10-30 20:51:43 UTC (rev 13198)
+++ short/3D/PyLith/trunk/pylith/utils/EventLogger.py	2008-10-31 03:55:49 UTC (rev 13199)
@@ -124,7 +124,7 @@
     Log stage begin.
     """
     assert(None != self.cppHandle)
-    self.cppHandle.stagePush(self.cppHandle.eventId(name))
+    self.cppHandle.stagePush(self.cppHandle.stageId(name))
     return
 
 

Modified: short/3D/PyLith/trunk/unittests/libtests/utils/TestEventLogger.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/utils/TestEventLogger.cc	2008-10-30 20:51:43 UTC (rev 13198)
+++ short/3D/PyLith/trunk/unittests/libtests/utils/TestEventLogger.cc	2008-10-31 03:55:49 UTC (rev 13199)
@@ -137,5 +137,89 @@
   logger.eventEnd(event);
 } // testEventLogging
 
+// ----------------------------------------------------------------------
+// Test registerStage().
+void
+pylith::utils::TestEventLogger::testRegisterStage(void)
+{ // testRegisterStage
+  EventLogger logger;
+  logger.className("my class");
+  logger.initialize();
 
+  const char* stages[] = { "stage A", "stage B", "stage C" };
+  const int numStages = 3;
+  int ids[numStages];
+
+  for (int i=0; i < numStages; ++i)
+    ids[i] = logger.registerStage(stages[i]);
+
+  int i = 0;
+  for (EventLogger::map_event_type::iterator s_iter=logger._stages.begin();
+       s_iter != logger._stages.end();
+       ++s_iter, ++i) {
+    CPPUNIT_ASSERT_EQUAL(std::string(stages[i]), s_iter->first);
+    CPPUNIT_ASSERT_EQUAL(ids[i], s_iter->second);
+  } // for
+} // testRegisterStage
+
+// ----------------------------------------------------------------------
+// Test stageId().
+void
+pylith::utils::TestEventLogger::testStageId(void)
+{ // testStageId
+  EventLogger logger;
+  logger.className("my class");
+  logger.initialize();
+
+  const char* stages[] = { "stage A", "stage B", "stage C" };
+  const int numStages = 3;
+
+  for (int i=0; i < numStages; ++i)
+    logger.registerStage(stages[i]);
+
+  const int order[] = { 1, 0, 2 };
+  int ids[numStages];
+  for (int i=0; i < numStages; ++i)
+    ids[order[i]] = logger.stageId(stages[order[i]]);
+
+  int i = 0;
+  for (EventLogger::map_event_type::iterator s_iter=logger._stages.begin();
+       s_iter != logger._stages.end();
+       ++s_iter, ++i)
+    CPPUNIT_ASSERT_EQUAL(s_iter->second, ids[i]);
+} // testStageId
+
+// ----------------------------------------------------------------------
+// Test statePush() and statePop().
+void
+pylith::utils::TestEventLogger::testStageLogging(void)
+{ // testStageLogging
+  EventLogger logger;
+  logger.className("my class");
+  logger.initialize();
+
+  const char* stages[] = { "stage A", "stage B", "stage C" };
+  const int numStages = 3;
+  int ids[numStages];
+
+  for (int i=0; i < numStages; ++i)
+    ids[i] = logger.registerStage(stages[i]);
+
+  int stage = ids[1];
+  logger.stagePush(stage);
+  logger.stagePop();
+
+  stage = ids[0];
+  logger.stagePush(stage);
+  logger.stagePop();
+
+  stage = ids[2];
+  logger.stagePush(stage);
+  int stage2 = ids[0];
+  logger.stagePush(stage2);
+  logger.stagePop();
+  logger.stagePop();
+} // testStageLogging
+
+
 // End of file 

Modified: short/3D/PyLith/trunk/unittests/libtests/utils/TestEventLogger.hh
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/utils/TestEventLogger.hh	2008-10-30 20:51:43 UTC (rev 13198)
+++ short/3D/PyLith/trunk/unittests/libtests/utils/TestEventLogger.hh	2008-10-31 03:55:49 UTC (rev 13199)
@@ -43,6 +43,9 @@
   CPPUNIT_TEST( testRegisterEvent );
   CPPUNIT_TEST( testEventId );
   CPPUNIT_TEST( testEventLogging );
+  CPPUNIT_TEST( testRegisterStage );
+  CPPUNIT_TEST( testStageId );
+  CPPUNIT_TEST( testStageLogging );
 
   CPPUNIT_TEST_SUITE_END();
 
@@ -67,6 +70,15 @@
   /// Test eventBegin() and eventEnd().
   void testEventLogging(void);
 
+  /// Test registerStage().
+  void testRegisterStage(void);
+
+  /// Test stageId().
+  void testStageId(void);
+
+  /// Test stagePush() and stagePop().
+  void testStageLogging(void);
+
 }; // class TestEventLogging
 
 #endif // pylith_utils_testeventlogger_hh

Modified: short/3D/PyLith/trunk/unittests/pytests/bc/TestAbsorbingDampers.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/bc/TestAbsorbingDampers.py	2008-10-30 20:51:43 UTC (rev 13198)
+++ short/3D/PyLith/trunk/unittests/pytests/bc/TestAbsorbingDampers.py	2008-10-31 03:55:49 UTC (rev 13199)
@@ -194,6 +194,7 @@
     cell.order = 1
     from pylith.feassemble.quadrature.Quadrature1Din2D import Quadrature1Din2D
     quadrature = Quadrature1Din2D()
+    quadrature._configure()
     quadrature.cell = cell
     bc.quadrature = quadrature
 

Modified: short/3D/PyLith/trunk/unittests/pytests/bc/TestNeumann.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/bc/TestNeumann.py	2008-10-30 20:51:43 UTC (rev 13198)
+++ short/3D/PyLith/trunk/unittests/pytests/bc/TestNeumann.py	2008-10-31 03:55:49 UTC (rev 13199)
@@ -191,6 +191,7 @@
     cell.order = 1
     from pylith.feassemble.quadrature.Quadrature1Din2D import Quadrature1Din2D
     quadrature = Quadrature1Din2D()
+    quadrature._configure()
     quadrature.cell = cell
     bc.quadrature = quadrature
 

Modified: short/3D/PyLith/trunk/unittests/pytests/faults/TestFaultCohesiveKin.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/faults/TestFaultCohesiveKin.py	2008-10-30 20:51:43 UTC (rev 13198)
+++ short/3D/PyLith/trunk/unittests/pytests/faults/TestFaultCohesiveKin.py	2008-10-31 03:55:49 UTC (rev 13199)
@@ -238,6 +238,7 @@
     cell.order = 1
     from pylith.feassemble.quadrature.Quadrature1Din2D import Quadrature1Din2D
     quadrature = Quadrature1Din2D()
+    quadrature._configure()
     quadrature.cell = cell
 
     # Setup earthquake source

Modified: short/3D/PyLith/trunk/unittests/pytests/feassemble/TestElasticityExplicit.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/feassemble/TestElasticityExplicit.py	2008-10-30 20:51:43 UTC (rev 13198)
+++ short/3D/PyLith/trunk/unittests/pytests/feassemble/TestElasticityExplicit.py	2008-10-31 03:55:49 UTC (rev 13199)
@@ -57,6 +57,7 @@
     cell.order = 1
     from pylith.feassemble.quadrature.Quadrature2D import Quadrature2D
     quadrature = Quadrature2D()
+    quadrature._configure()
     quadrature.cell = cell
     minJacobian = 4.0e-02;
     quadrature.minJacobian = minJacobian
@@ -238,6 +239,7 @@
     cell.order = 1
     from pylith.feassemble.quadrature.Quadrature2D import Quadrature2D
     quadrature = Quadrature2D()
+    quadrature._configure()
     quadrature.cell = cell
     
     from spatialdata.spatialdb.SimpleDB import SimpleDB

Modified: short/3D/PyLith/trunk/unittests/pytests/feassemble/TestElasticityImplicit.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/feassemble/TestElasticityImplicit.py	2008-10-30 20:51:43 UTC (rev 13198)
+++ short/3D/PyLith/trunk/unittests/pytests/feassemble/TestElasticityImplicit.py	2008-10-31 03:55:49 UTC (rev 13199)
@@ -57,6 +57,7 @@
     cell.order = 1
     from pylith.feassemble.quadrature.Quadrature2D import Quadrature2D
     quadrature = Quadrature2D()
+    quadrature._configure()
     quadrature.cell = cell
     minJacobian = 4.0e-02;
     quadrature.minJacobian = minJacobian
@@ -233,6 +234,7 @@
     cell.order = 1
     from pylith.feassemble.quadrature.Quadrature2D import Quadrature2D
     quadrature = Quadrature2D()
+    quadrature._configure()
     quadrature.cell = cell
     
     from spatialdata.spatialdb.SimpleDB import SimpleDB

Modified: short/3D/PyLith/trunk/unittests/pytests/feassemble/TestQuadrature.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/feassemble/TestQuadrature.py	2008-10-30 20:51:43 UTC (rev 13198)
+++ short/3D/PyLith/trunk/unittests/pytests/feassemble/TestQuadrature.py	2008-10-31 03:55:49 UTC (rev 13199)
@@ -91,6 +91,7 @@
       iQuad += 1
 
     quadrature = Quadrature1D()
+    quadrature._configure()
     quadrature.cell = cell
 
     quadrature.preinitialize()

Modified: short/3D/PyLith/trunk/unittests/pytests/materials/TestMaterial.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/materials/TestMaterial.py	2008-10-30 20:51:43 UTC (rev 13198)
+++ short/3D/PyLith/trunk/unittests/pytests/materials/TestMaterial.py	2008-10-31 03:55:49 UTC (rev 13199)
@@ -34,6 +34,7 @@
 
     from pylith.feassemble.quadrature.Quadrature1D import Quadrature1D
     quadrature = Quadrature1D()
+    quadrature._configure()
     from pylith.feassemble.FIATSimplex import FIATSimplex
     cell = FIATSimplex()
     cell.shape = "line"

Modified: short/3D/PyLith/trunk/unittests/pytests/meshio/TestCellFilterAvg.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/meshio/TestCellFilterAvg.py	2008-10-30 20:51:43 UTC (rev 13198)
+++ short/3D/PyLith/trunk/unittests/pytests/meshio/TestCellFilterAvg.py	2008-10-31 03:55:49 UTC (rev 13199)
@@ -46,6 +46,7 @@
     cell.order = 2
 
     quadrature = Quadrature1D()
+    quadrature._configure()
     quadrature.cell = cell
     quadrature.preinitialize()
     quadrature.initialize()

Modified: short/3D/PyLith/trunk/unittests/pytests/utils/TestEventLogger.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/utils/TestEventLogger.py	2008-10-30 20:51:43 UTC (rev 13198)
+++ short/3D/PyLith/trunk/unittests/pytests/utils/TestEventLogger.py	2008-10-31 03:55:49 UTC (rev 13199)
@@ -99,4 +99,47 @@
     return
 
 
+  def test_registerStage(self):
+    """
+    Test registerStage().
+    """
+    from pylith.utils.EventLogger import EventLogger
+    logger = EventLogger()
+    logger.setClassName("logging A")
+    logger.initialize()
+
+    stages = ["stage 1" , "stage 2" , "stage 3"]
+    id = {}
+    for stage in stages:
+      id[stage] = logger.registerStage(stage)
+    for stage in stages:
+      self.assertEqual(id[stage], logger.stageId(stage))
+    return
+
+
+  def test_stageLogging(self):
+    """
+    Test stagePush() and stagePop().
+    """
+    from pylith.utils.EventLogger import EventLogger
+    logger = EventLogger()
+    logger.setClassName("logging A")
+    logger.initialize()
+    stages = ["stage 1" , "stage 2" , "stage 3"]
+    for stage in stages:
+      logger.registerStage(stage)
+
+    logger.stagePush("stage 2")
+    logger.stagePop()
+
+    logger.stagePush("stage 1")
+    logger.stagePop()
+
+    logger.stagePush("stage 3")
+    logger.stagePush("stage 1")
+    logger.stagePop()
+    logger.stagePop()
+    return
+
+
 # End of file 



More information about the CIG-COMMITS mailing list