[cig-commits] [commit] baagaard/feature-progress-monitor: Added unit test for ProgressMonitor. (bccef00)

cig_noreply at geodynamics.org cig_noreply at geodynamics.org
Sat Nov 1 11:11:16 PDT 2014


Repository : https://github.com/geodynamics/pylith

On branch  : baagaard/feature-progress-monitor
Link       : https://github.com/geodynamics/pylith/compare/1e9f9bb22bd082d9a8ba73fe25b0ed5b6f1900d8...bccef003e43d89b154c2df98adc0c5f572d679d0

>---------------------------------------------------------------

commit bccef003e43d89b154c2df98adc0c5f572d679d0
Author: Brad Aagaard <baagaard at usgs.gov>
Date:   Sat Nov 1 11:11:31 2014 -0700

    Added unit test for ProgressMonitor.


>---------------------------------------------------------------

bccef003e43d89b154c2df98adc0c5f572d679d0
 unittests/pytests/problems/TestProgressMonitor.py | 102 ++++++++++++++++++++++
 1 file changed, 102 insertions(+)

diff --git a/unittests/pytests/problems/TestProgressMonitor.py b/unittests/pytests/problems/TestProgressMonitor.py
new file mode 100644
index 0000000..50c623f
--- /dev/null
+++ b/unittests/pytests/problems/TestProgressMonitor.py
@@ -0,0 +1,102 @@
+#!/usr/bin/env python
+#
+# ======================================================================
+#
+# Brad T. Aagaard, U.S. Geological Survey
+# Charles A. Williams, GNS Science
+# Matthew G. Knepley, University of Chicago
+#
+# This code was developed as part of the Computational Infrastructure
+# for Geodynamics (http://geodynamics.org).
+#
+# Copyright (c) 2010-2014 University of California, Davis
+#
+# See COPYING for license information.
+#
+# ======================================================================
+#
+
+## @file unittests/pytests/problems/TestProgressMonitor.py
+
+## @brief Unit testing of ProgressMonitor object.
+
+import unittest
+from pylith.problems.ProgressMonitor import ProgressMonitor
+
+from pyre.units.time import year
+
+# ----------------------------------------------------------------------
+class TestProgressMonitor(unittest.TestCase):
+  """
+  Unit testing of ProgressMonitor object.
+  """
+
+  def setUp(self):
+    self.monitor = ProgressMonitor()
+    self.monitor._configure()
+    self.monitor.filename = "data/progress.txt"
+    return
+  
+
+  def test_constructor(self):
+    """
+    Test constructor.
+    """
+    monitor = ProgressMonitor()
+    monitor._configure()
+    return
+
+
+  def test_openclose(self):
+    """
+    Test open() and close().
+    """
+    import os
+    if os.path.exists(self.monitor.filename):
+        os.remove(self.monitor.filename)
+    self.monitor.open()
+    self.monitor.close()
+
+    self.assertTrue(os.path.isfile(self.monitor.filename))
+
+    return
+
+
+  def test_update(self):
+    """
+    Test update().
+    """
+    import os
+    self.monitor.open()
+
+    nlines = 1 # header
+    self.monitor.update(1.0*year, 0.0*year, 10.0*year); nlines += 1
+    self.monitor.update(1.5*year, 0.0*year, 10.0*year); nlines += 0
+    self.monitor.update(2.0*year, 0.0*year, 10.0*year); nlines += 1
+    self.monitor.update(4.0*year, 0.0*year, 10.0*year); nlines += 1
+    self.monitor.update(5.0*year, 0.0*year, 10.0*year); nlines += 1
+    self.monitor.update(6.0*year, 0.0*year, 10.0*year); nlines += 1
+    self.monitor.update(8.0*year, 0.0*year, 10.0*year); nlines += 1
+    self.monitor.update(9.0*year, 0.0*year, 10.0*year); nlines += 1
+
+    self.monitor.close()
+
+    self.assertTrue(os.path.isfile(self.monitor.filename))
+    fin = open(self.monitor.filename, "r")
+    lines = fin.readlines()
+    fin.close()
+    self.assertEqual(nlines, len(lines))
+    
+    return
+
+
+  def test_factory(self):
+    """
+    Test factory method.
+    """
+    from pylith.problems.ProgressMonitor import progress_monitor
+    m = progress_monitor()
+    return
+
+
+# End of file 



More information about the CIG-COMMITS mailing list