[cig-commits] r4108 - in cs/spatialdata-0.1/trunk: libsrc/utils modulesrc/utils spatialdata/utils tests/pytests/utils

baagaard at geodynamics.org baagaard at geodynamics.org
Tue Jul 25 20:58:56 PDT 2006


Author: baagaard
Date: 2006-07-25 20:58:56 -0700 (Tue, 25 Jul 2006)
New Revision: 4108

Added:
   cs/spatialdata-0.1/trunk/tests/pytests/utils/TestPointsStream.py
Modified:
   cs/spatialdata-0.1/trunk/libsrc/utils/PointsStream.icc
   cs/spatialdata-0.1/trunk/modulesrc/utils/utils.pyxe
   cs/spatialdata-0.1/trunk/spatialdata/utils/PointsStream.py
Log:
Started work on pytests for utils stuff. Still need to add TestChangeCoordSys.

Modified: cs/spatialdata-0.1/trunk/libsrc/utils/PointsStream.icc
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/utils/PointsStream.icc	2006-07-26 03:30:43 UTC (rev 4107)
+++ cs/spatialdata-0.1/trunk/libsrc/utils/PointsStream.icc	2006-07-26 03:58:56 UTC (rev 4108)
@@ -15,48 +15,56 @@
 #else
 
 // Set name of file for input/output.
+inline
 void
 spatialdata::utils::PointsStream::filename(const char* filename) {
   _filename = filename;
 }
 
 // Get name of file for input/output.
+inline
 const char*
 spatialdata::utils::PointsStream::filename(void) const {
   return _filename.c_str();
 }
 
 // Set comment flag.
+inline
 void
 spatialdata::utils::PointsStream::commentFlag(const char* flag) {
   _commentFlag = flag;
 }
 
 // Get comment flag.
+inline
 const char*
 spatialdata::utils::PointsStream::commentFlag(void) const {
   return _commentFlag.c_str();
 }
 
 // Set field width.
+inline
 void
 spatialdata::utils::PointsStream::fieldWidth(const int width) {
   _fieldWidth = width;
 }
 
 // Get field width.
+inline
 int
 spatialdata::utils::PointsStream::fieldWidth(void) const {
   return _fieldWidth;
 }
 
 // Set precision.
+inline
 void
 spatialdata::utils::PointsStream::precision(const int value) {
   _precision = value;
 }
 
 // Get precision.
+inline
 int
 spatialdata::utils::PointsStream::precision(void) const {
   return _precision;

Modified: cs/spatialdata-0.1/trunk/modulesrc/utils/utils.pyxe
===================================================================
--- cs/spatialdata-0.1/trunk/modulesrc/utils/utils.pyxe	2006-07-26 03:30:43 UTC (rev 4107)
+++ cs/spatialdata-0.1/trunk/modulesrc/utils/utils.pyxe	2006-07-26 03:58:56 UTC (rev 4108)
@@ -39,11 +39,33 @@
     """
     Constructor.
     """
-    self._handle = self._createHandle()
+    self.handle = self._createHandle()
     self.thisptr = NULL
     self.name = "spatialdata_utils_PointsStream"
     return
 
+  property filename:
+    def __set__(self, filename):
+      """
+      Set name of file.
+      """
+      # create shim for method 'filename'
+      #embed{ void PointsStream_filename_set(void* pObj, char* filename)
+      ((spatialdata::utils::PointsStream*) pObj)->filename(filename);
+      #}embed
+      PointsStream_filename_set(self.thisptr, filename)
+
+    def __get__(self):
+      """
+      Get name of file.
+      """
+      # create shim for method 'filename'
+      #embed{ char* PointsStream_filename_get(void* pObj)
+      return (char*) ((spatialdata::utils::PointsStream*) pObj)->filename();
+      #}embed
+      return PointsStream_filename_get(self.thisptr)
+
+
   property commentFlag:
     def __set__(self, flag):
       """

Modified: cs/spatialdata-0.1/trunk/spatialdata/utils/PointsStream.py
===================================================================
--- cs/spatialdata-0.1/trunk/spatialdata/utils/PointsStream.py	2006-07-26 03:30:43 UTC (rev 4107)
+++ cs/spatialdata-0.1/trunk/spatialdata/utils/PointsStream.py	2006-07-26 03:58:56 UTC (rev 4108)
@@ -44,7 +44,7 @@
     import pyre.inventory
 
     commentFlag = pyre.inventory.str("comment_flag", default="#")
-    commentFlags.meta['tip'] = "String identifying comment."
+    commentFlag.meta['tip'] = "String identifying comment."
 
     fieldWidth = pyre.inventory.int("field_width", default=14)
     fieldWidth.meta['tip'] = "Width of field for coordinates."

Added: cs/spatialdata-0.1/trunk/tests/pytests/utils/TestPointsStream.py
===================================================================
--- cs/spatialdata-0.1/trunk/tests/pytests/utils/TestPointsStream.py	2006-07-26 03:30:43 UTC (rev 4107)
+++ cs/spatialdata-0.1/trunk/tests/pytests/utils/TestPointsStream.py	2006-07-26 03:58:56 UTC (rev 4108)
@@ -0,0 +1,75 @@
+#!/usr/bin/env python
+#
+# ======================================================================
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# {LicenseText}
+#
+# ======================================================================
+#
+
+import unittest
+
+import numpy
+from spatialdata.utils.PointsStream import PointsStream
+
+class TestPointsStream(unittest.TestCase):
+
+
+  def test_filename(self):
+    filename = "one"
+    s = PointsStream()
+    s.filename = filename
+    self.assertEqual(filename, s.filename)
+    return
+
+
+  def test_commentFlag(self):
+    flag = "%"
+    s = PointsStream()
+    s.commentFlag = flag
+    self.assertEqual(flag, s.commentFlag)
+    return
+
+
+  def test_fieldWidth(self):
+    fieldWidth = 6
+    s = PointsStream()
+    s.fieldWidth = fieldWidth
+    self.assertEqual(fieldWidth, s.fieldWidth)
+    return
+
+
+  def test_precision(self):
+    precision = 3
+    s = PointsStream()
+    s.precision = precision
+    self.assertEqual(precision, s.precision)
+    return
+
+  
+  def test_writeread(self):
+    pointsE = numpy.array([ [1.0, 2.0, 3.0],
+                            [1.1, 2.1, 3.1],
+                            [1.2, 2.2, 3.2] ],
+                          numpy.Float64)
+
+    filename = "tmp.txt"
+    s = PointsStream()
+    print "AA"
+    s.write(pointsE)
+    print "BB"
+    
+    points = s.read()
+    print "CC"
+    self.assertEqual(len(pointsE.shape), len(points.shape))
+    for dE,d in zip(pointsE.shape, points.shape):
+      self.assertEqual(dE, d)
+    for vE,v in zip(numpy.reshape(pointsE, -1), numpy.reshape(points, -1)):
+      self.assertAlmostEqual(vE, v, 6)
+    return
+
+
+# End of file 



More information about the cig-commits mailing list