[cig-commits] [commit] baagaard/feature-output-station-names, baagaard/feature-progress-monitor, master: Added unit test for ProgressMonitor. (bccef00)
cig_noreply at geodynamics.org
cig_noreply at geodynamics.org
Wed Nov 5 15:47:43 PST 2014
Repository : https://github.com/geodynamics/pylith
On branches: baagaard/feature-output-station-names,baagaard/feature-progress-monitor,master
Link : https://github.com/geodynamics/pylith/compare/f33c75b19fd60eedb2a3405db76a1fee333bb1d7...5b6d812b1612809fea3bd331c4e5af98c25a536a
>---------------------------------------------------------------
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