Ticket 738: Add python3 support
authorAnders Henja <anders@henjab.se>
Fri, 30 Mar 2018 19:37:24 +0000 (21:37 +0200)
committerAnders Henja <anders@henjab.se>
Fri, 30 Mar 2018 19:37:24 +0000 (21:37 +0200)
lib/wrwp.c
pywrwp/pywrwp.c
pywrwp/pywrwp.h
test/pytest/WrwpTest.py
tools/run_python_script.sh

index 141965a..82ac958 100644 (file)
@@ -363,7 +363,7 @@ VerticalProfile_t* Wrwp_generate(Wrwp_t* self, PolarVolume_t* inobj, const char*
   double gain, offset, nodata, undetect, val;
   double d, h;
   double alpha, beta, gamma, vvel, vdir, vstd, zsum, zmean, zstd;
-  double centerOfLayer, u_wnd_comp, v_wnd_comp, vdir_rad;
+  double centerOfLayer=0.0, u_wnd_comp=0.0, v_wnd_comp=0.0, vdir_rad=0.0;
   int ysize = 0, yindex = 0;
   int countAcceptedScans = 0; /* counter for accepted scans i.e. scans with elangle >= selected
                                  minimum elevatiuon angle and not being set as malfunc */
index ad998c9..d6bf7cd 100644 (file)
@@ -21,6 +21,7 @@ along with baltrad-wrwp.  If not, see <http://www.gnu.org/licenses/>.
  * @author Anders Henja, SMHI
  * @date 2013-09-17
  */
+#include "pywrwp_compat.h"
 #include <Python.h>
 #include <math.h>
 #include <stdio.h>
@@ -190,65 +191,58 @@ static struct PyMethodDef _pywrwp_methods[] =
  * Returns the specified attribute in the wrwp generator
  * @param[in] self - the wrwp generator
  */
-static PyObject* _pywrwp_getattr(PyWrwp* self, char* name)
+static PyObject* _pywrwp_getattro(PyWrwp* self, PyObject* name)
 {
-  PyObject* res = NULL;
-  if (strcmp("dz", name) == 0) {
+  if (PY_COMPARE_STRING_WITH_ATTRO_NAME("dz", name) == 0) {
     return PyInt_FromLong(Wrwp_getDZ(self->wrwp));
-  } else if (strcmp("hmax", name) == 0) {
+  } else if (PY_COMPARE_STRING_WITH_ATTRO_NAME("hmax", name) == 0) {
     return PyInt_FromLong(Wrwp_getHMAX(self->wrwp));
-  } else if (strcmp("dmin", name) == 0) {
+  } else if (PY_COMPARE_STRING_WITH_ATTRO_NAME("dmin", name) == 0) {
     return PyInt_FromLong(Wrwp_getDMIN(self->wrwp));
-  } else if (strcmp("dmax", name) == 0) {
+  } else if (PY_COMPARE_STRING_WITH_ATTRO_NAME("dmax", name) == 0) {
     return PyInt_FromLong(Wrwp_getDMAX(self->wrwp));
-  } else if (strcmp("emin", name) == 0) {
+  } else if (PY_COMPARE_STRING_WITH_ATTRO_NAME("emin", name) == 0) {
     return PyFloat_FromDouble(Wrwp_getEMIN(self->wrwp));
-  } else if (strcmp("vmin", name) == 0) {
+  } else if (PY_COMPARE_STRING_WITH_ATTRO_NAME("vmin", name) == 0) {
     return PyFloat_FromDouble(Wrwp_getVMIN(self->wrwp));
   }
-  res = Py_FindMethod(_pywrwp_methods, (PyObject*) self, name);
-  if (res)
-    return res;
-
-  PyErr_Clear();
-  PyErr_SetString(PyExc_AttributeError, name);
-  return NULL;
+  return PyObject_GenericGetAttr((PyObject*)self, name);
 }
 
 /**
  * Returns the specified attribute in the wrwp generator
  */
-static int _pywrwp_setattr(PyWrwp* self, char* name, PyObject* val)
+static int _pywrwp_setattro(PyWrwp* self, PyObject* name, PyObject* val)
 {
   int result = -1;
   if (name == NULL) {
     goto done;
   }
-  if (strcmp("dz", name) == 0) {
+  if (PY_COMPARE_STRING_WITH_ATTRO_NAME("dz", name) == 0) {
     if (PyInt_Check(val)) {
       Wrwp_setDZ(self->wrwp, PyInt_AsLong(val));
     } else {
       raiseException_gotoTag(done, PyExc_TypeError, "dz must be an integer");
     }
-  } else if (strcmp("hmax", name) == 0) {
+  } else if (PY_COMPARE_STRING_WITH_ATTRO_NAME("hmax", name) == 0) {
     if (PyInt_Check(val)) {
       Wrwp_setHMAX(self->wrwp, PyInt_AsLong(val));
     } else {
       raiseException_gotoTag(done, PyExc_TypeError, "hmax must be an integer");
     }
-  } else if (strcmp("dmin", name) == 0) {
+  } else if (PY_COMPARE_STRING_WITH_ATTRO_NAME("dmin", name) == 0) {
     if (PyInt_Check(val)) {
       Wrwp_setDMIN(self->wrwp, PyInt_AsLong(val));
     } else {
       raiseException_gotoTag(done, PyExc_TypeError, "dmin must be an integer");
     }
-  } else if (strcmp("dmax", name) == 0) {
+  } else if (PY_COMPARE_STRING_WITH_ATTRO_NAME("dmax", name) == 0) {
     if (PyInt_Check(val)) {
       Wrwp_setDMAX(self->wrwp, PyInt_AsLong(val));
     } else {
       raiseException_gotoTag(done, PyExc_TypeError, "dmax must be an integer");
     }
-  } else if (strcmp("emin", name) == 0) {
+  } else if (PY_COMPARE_STRING_WITH_ATTRO_NAME("emin", name) == 0) {
     if (PyFloat_Check(val)) {
       Wrwp_setEMIN(self->wrwp, PyFloat_AsDouble(val));
     } else if (PyInt_Check(val)) {
@@ -256,7 +250,7 @@ static int _pywrwp_setattr(PyWrwp* self, char* name, PyObject* val)
     } else {
       raiseException_gotoTag(done, PyExc_TypeError, "emin must be an integer or a float");
     }
-  } else if (strcmp("vmin", name) == 0) {
+  } else if (PY_COMPARE_STRING_WITH_ATTRO_NAME("vmin", name) == 0) {
     if (PyFloat_Check(val)) {
       Wrwp_setVMIN(self->wrwp, PyFloat_AsDouble(val));
     } else if (PyInt_Check(val)) {
@@ -275,21 +269,47 @@ done:
 /*@{ Type definitions */
 PyTypeObject PyWrwp_Type =
 {
-  PyObject_HEAD_INIT(NULL)0, /*ob_size*/
+  PyVarObject_HEAD_INIT(NULL, 0) /*ob_size*/
   "WrwpCore", /*tp_name*/
   sizeof(PyWrwp), /*tp_size*/
   0, /*tp_itemsize*/
   /* methods */
   (destructor)_pywrwp_dealloc, /*tp_dealloc*/
   0, /*tp_print*/
-  (getattrfunc)_pywrwp_getattr, /*tp_getattr*/
-  (setattrfunc)_pywrwp_setattr, /*tp_setattr*/
-  0, /*tp_compare*/
-  0, /*tp_repr*/
-  0, /*tp_as_number */
+  (getattrfunc)0,               /*tp_getattr*/
+  (setattrfunc)0,               /*tp_setattr*/
+  0,                            /*tp_compare*/
+  0,                            /*tp_repr*/
+  0,                            /*tp_as_number */
   0,
-  0, /*tp_as_mapping */
-  0 /*tp_hash*/
+  0,                            /*tp_as_mapping */
+  0,                            /*tp_hash*/
+  (ternaryfunc)0,               /*tp_call*/
+  (reprfunc)0,                  /*tp_str*/
+  (getattrofunc)_pywrwp_getattro, /*tp_getattro*/
+  (setattrofunc)_pywrwp_setattro, /*tp_setattro*/
+  0,                            /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT, /*tp_flags*/
+  0,                            /*tp_doc*/
+  (traverseproc)0,              /*tp_traverse*/
+  (inquiry)0,                   /*tp_clear*/
+  0,                            /*tp_richcompare*/
+  0,                            /*tp_weaklistoffset*/
+  0,                            /*tp_iter*/
+  0,                            /*tp_iternext*/
+  _pywrwp_methods,              /*tp_methods*/
+  0,                            /*tp_members*/
+  0,                            /*tp_getset*/
+  0,                            /*tp_base*/
+  0,                            /*tp_dict*/
+  0,                            /*tp_descr_get*/
+  0,                            /*tp_descr_set*/
+  0,                            /*tp_dictoffset*/
+  0,                            /*tp_init*/
+  0,                            /*tp_alloc*/
+  0,                            /*tp_new*/
+  0,                            /*tp_free*/
+  0,                            /*tp_is_gc*/
 };
 
 /*@} End of Type definitions */
@@ -303,37 +323,39 @@ static PyMethodDef functions[] = {
   {NULL,NULL} /*Sentinel*/
 };
 
-PyMODINIT_FUNC
-init_wrwp(void)
+MOD_INIT(_wrwp)
 {
   PyObject *module=NULL,*dictionary=NULL;
   static void *PyWrwp_API[PyWrwp_API_pointers];
   PyObject *c_api_object = NULL;
-  PyWrwp_Type.ob_type = &PyType_Type;
 
-  module = Py_InitModule("_wrwp", functions);
+  MOD_INIT_SETUP_TYPE(PyWrwp_Type, &PyType_Type);
+
+  MOD_INIT_VERIFY_TYPE_READY(&PyWrwp_Type);
+
+  MOD_INIT_DEF(module, "_wrwp", NULL/*doc*/, functions);
   if (module == NULL) {
-    return;
+    return MOD_INIT_ERROR;
   }
+
   PyWrwp_API[PyWrwp_Type_NUM] = (void*)&PyWrwp_Type;
   PyWrwp_API[PyWrwp_GetNative_NUM] = (void *)PyWrwp_GetNative;
   PyWrwp_API[PyWrwp_New_NUM] = (void*)PyWrwp_New;
 
-  c_api_object = PyCObject_FromVoidPtr((void *)PyWrwp_API, NULL);
-
-  if (c_api_object != NULL) {
-    PyModule_AddObject(module, "_C_API", c_api_object);
-  }
-
+  c_api_object = PyCapsule_New(PyWrwp_API, PyWrwp_CAPSULE_NAME, NULL);
   dictionary = PyModule_GetDict(module);
-  ErrorObject = PyString_FromString("_wrwp.error");
+  PyDict_SetItemString(dictionary, "_C_API", c_api_object);
+
+  ErrorObject = PyErr_NewException("_wrwp.error", NULL, NULL);
   if (ErrorObject == NULL || PyDict_SetItemString(dictionary, "error", ErrorObject) != 0) {
     Py_FatalError("Can't define _wrwp.error");
+    return MOD_INIT_ERROR;
   }
 
   import_array();
   import_pypolarvolume();
   import_pyverticalprofile();
   PYRAVE_DEBUG_INITIALIZE;
+  return MOD_INIT_SUCCESS(module);
 }
 /*@} End of Module setup */
index 7660742..b787c68 100644 (file)
@@ -47,6 +47,8 @@ typedef struct {
 
 #define PyWrwp_API_pointers 3                 /**< total number of C API pointers */
 
+#define PyWrwp_CAPSULE_NAME "_wrwp._C_API"
+
 #ifdef PYWRWP_MODULE
 /** declared in pywrwp module */
 extern PyTypeObject PyWrwp_Type;
@@ -83,37 +85,18 @@ static void **PyWrwp_API;
  * Checks if the object is a python wrwp generator.
  */
 #define PyWrwp_Check(op) \
-   ((op)->ob_type == (PyTypeObject *)PyWrwp_API[PyWrwp_Type_NUM])
+    (Py_TYPE(op) == &PyWrwp_Type)
+
+
+#define PyWrwp_Type (*(PyTypeObject*)PyWrwp_API[PyWrwp_Type_NUM])
 
 /**
  * Imports the PyWrwp module (like import _wrwp in python).
  */
-static int
-import_pywrwp(void)
-{
-  PyObject *module;
-  PyObject *c_api_object;
-
-  module = PyImport_ImportModule("_wrwp");
-  if (module == NULL) {
-    return -1;
-  }
-
-  c_api_object = PyObject_GetAttrString(module, "_C_API");
-  if (c_api_object == NULL) {
-    Py_DECREF(module);
-    return -1;
-  }
-  if (PyCObject_Check(c_api_object)) {
-    PyWrwp_API = (void **)PyCObject_AsVoidPtr(c_api_object);
-  }
-  Py_DECREF(c_api_object);
-  Py_DECREF(module);
-  return 0;
-}
+#define import_pywrwp() \
+    PyWrwp_API = (void **)PyCapsule_Import(PyWrwp_CAPSULE_NAME, 1);
 
 #endif
 
 
-
 #endif /* PYWRWP_H */
index d53d01f..8c43ae9 100644 (file)
@@ -43,71 +43,71 @@ class WrwpTest(unittest.TestCase):
 
   def test_new(self):
     obj = _wrwp.new()
-    self.assertNotEqual(-1, string.find(`type(obj)`, "WrwpCore"))
+    self.assertNotEqual(-1, str(type(obj)).find("WrwpCore"))
 
   def test_dz(self):
     obj = _wrwp.new()
-    self.assertEquals(200, obj.dz)
+    self.assertEqual(200, obj.dz)
     obj.dz = 100
-    self.assertEquals(100, obj.dz)
+    self.assertEqual(100, obj.dz)
     try:
       obj.dz = 200.0
       self.fail("Expected TypeError")
-    except TypeError, e:
+    except TypeError:
       pass
-    self.assertEquals(100, obj.dz)
+    self.assertEqual(100, obj.dz)
 
   def test_hmax(self):
     obj = _wrwp.new()
-    self.assertEquals(12000, obj.hmax)
+    self.assertEqual(12000, obj.hmax)
     obj.hmax = 100
-    self.assertEquals(100, obj.hmax)
+    self.assertEqual(100, obj.hmax)
     try:
       obj.hmax = 200.0
       self.fail("Expected TypeError")
-    except TypeError, e:
+    except TypeError:
       pass
-    self.assertEquals(100, obj.hmax)
+    self.assertEqual(100, obj.hmax)
 
   def test_dmin(self):
     obj = _wrwp.new()
-    self.assertEquals(4000, obj.dmin)
+    self.assertEqual(4000, obj.dmin)
     obj.dmin = 100
-    self.assertEquals(100, obj.dmin)
+    self.assertEqual(100, obj.dmin)
     try:
       obj.dmin = 200.0
       self.fail("Expected TypeError")
-    except TypeError, e:
+    except TypeError:
       pass
-    self.assertEquals(100, obj.dmin)
+    self.assertEqual(100, obj.dmin)
     
   def test_dmax(self):
     obj = _wrwp.new()
-    self.assertEquals(40000, obj.dmax)
+    self.assertEqual(40000, obj.dmax)
     obj.dmax = 100
-    self.assertEquals(100, obj.dmax)
+    self.assertEqual(100, obj.dmax)
     try:
       obj.dmax = 200.0
       self.fail("Expected TypeError")
-    except TypeError, e:
+    except TypeError:
       pass
-    self.assertEquals(100, obj.dmax)
+    self.assertEqual(100, obj.dmax)
 
   def test_emin(self):
     obj = _wrwp.new()
-    self.assertAlmostEquals(2.5, obj.emin, 4)
+    self.assertAlmostEqual(2.5, obj.emin, 4)
     obj.emin = 3.5
-    self.assertAlmostEquals(3.5, obj.emin, 4)
+    self.assertAlmostEqual(3.5, obj.emin, 4)
     obj.emin = 4
-    self.assertAlmostEquals(4.0, obj.emin, 4)
+    self.assertAlmostEqual(4.0, obj.emin, 4)
 
   def test_vmin(self):
     obj = _wrwp.new()
-    self.assertAlmostEquals(2.0, obj.vmin, 4)
+    self.assertAlmostEqual(2.0, obj.vmin, 4)
     obj.vmin = 3.5
-    self.assertAlmostEquals(3.5, obj.vmin, 4)
+    self.assertAlmostEqual(3.5, obj.vmin, 4)
     obj.vmin = 4
-    self.assertAlmostEquals(4.0, obj.vmin, 4)
+    self.assertAlmostEqual(4.0, obj.vmin, 4)
   
   def test_generate(self):
     pvol = _raveio.open(self.FIXTURE).object
@@ -122,29 +122,29 @@ class WrwpTest(unittest.TestCase):
     hght = vp.getHGHT()
     nv = vp.getNV()
     
-    self.assertEquals(1, uwnd.xsize)
-    self.assertEquals(10, uwnd.ysize)
-    self.assertEquals("UWND", uwnd.getAttribute("what/quantity"))
+    self.assertEqual(1, uwnd.xsize)
+    self.assertEqual(10, uwnd.ysize)
+    self.assertEqual("UWND", uwnd.getAttribute("what/quantity"))
 
-    self.assertEquals(1, vwnd.xsize)
-    self.assertEquals(10, vwnd.ysize)
-    self.assertEquals("VWND", vwnd.getAttribute("what/quantity"))
+    self.assertEqual(1, vwnd.xsize)
+    self.assertEqual(10, vwnd.ysize)
+    self.assertEqual("VWND", vwnd.getAttribute("what/quantity"))
 
-    self.assertEquals(1, hght.xsize)
-    self.assertEquals(10, hght.ysize)
-    self.assertEquals("HGHT", hght.getAttribute("what/quantity"))
+    self.assertEqual(1, hght.xsize)
+    self.assertEqual(10, hght.ysize)
+    self.assertEqual("HGHT", hght.getAttribute("what/quantity"))
     
-    self.assertEquals(1, nv.xsize)
-    self.assertEquals(10, nv.ysize)
-    self.assertEquals("n", nv.getAttribute("what/quantity"))
-
-    self.assertEquals(10,vp.getLevels())
-    self.assertEquals(200, vp.interval)
-    self.assertEquals(0, vp.minheight)
-    self.assertEquals(2000, vp.maxheight)
-    self.assertEquals(pvol.source, vp.source)
-    self.assertEquals(pvol.date, vp.date)
-    self.assertEquals(pvol.time, vp.time)
+    self.assertEqual(1, nv.xsize)
+    self.assertEqual(10, nv.ysize)
+    self.assertEqual("n", nv.getAttribute("what/quantity"))
+
+    self.assertEqual(10,vp.getLevels())
+    self.assertEqual(200, vp.interval)
+    self.assertEqual(0, vp.minheight)
+    self.assertEqual(2000, vp.maxheight)
+    self.assertEqual(pvol.source, vp.source)
+    self.assertEqual(pvol.date, vp.date)
+    self.assertEqual(pvol.time, vp.time)
     
   def X_test_generate_2(self):
     pvol = _raveio.open(self.FIXTURE).object
@@ -171,50 +171,50 @@ class WrwpTest(unittest.TestCase):
     hght = vp.getHGHT()
     nv = vp.getNV()
 
-    self.assertEquals(1, uwnd.xsize)
-    self.assertEquals(10, uwnd.ysize)
-    self.assertEquals("UWND", uwnd.getAttribute("what/quantity"))
-
-    self.assertEquals(1, vwnd.xsize)
-    self.assertEquals(10, vwnd.ysize)
-    self.assertEquals("VWND", vwnd.getAttribute("what/quantity"))
-
-    self.assertEquals(1, hght.xsize)
-    self.assertEquals(10, hght.ysize)
-    self.assertEquals("HGHT", hght.getAttribute("what/quantity"))
-
-    self.assertEquals(1, nv.xsize)
-    self.assertEquals(10, nv.ysize)
-    self.assertEquals("n", nv.getAttribute("what/quantity"))
-
-    self.assertEquals(10, vp.getLevels())
-    self.assertEquals(200, vp.interval)
-    self.assertEquals(0, vp.minheight)
-    self.assertEquals(2000, vp.maxheight)
-    self.assertEquals(pvol.source, vp.source)
-    self.assertEquals(pvol.date, vp.date)
-    self.assertEquals(pvol.time, vp.time)
+    self.assertEqual(1, uwnd.xsize)
+    self.assertEqual(10, uwnd.ysize)
+    self.assertEqual("UWND", uwnd.getAttribute("what/quantity"))
+
+    self.assertEqual(1, vwnd.xsize)
+    self.assertEqual(10, vwnd.ysize)
+    self.assertEqual("VWND", vwnd.getAttribute("what/quantity"))
+
+    self.assertEqual(1, hght.xsize)
+    self.assertEqual(10, hght.ysize)
+    self.assertEqual("HGHT", hght.getAttribute("what/quantity"))
+
+    self.assertEqual(1, nv.xsize)
+    self.assertEqual(10, nv.ysize)
+    self.assertEqual("n", nv.getAttribute("what/quantity"))
+
+    self.assertEqual(10, vp.getLevels())
+    self.assertEqual(200, vp.interval)
+    self.assertEqual(0, vp.minheight)
+    self.assertEqual(2000, vp.maxheight)
+    self.assertEqual(pvol.source, vp.source)
+    self.assertEqual(pvol.date, vp.date)
+    self.assertEqual(pvol.time, vp.time)
     
-    self.assertEquals(900, vp.getAttribute("how/lowprf"))
-    self.assertEquals(1200, vp.getAttribute("how/highprf"))
+    self.assertEqual(900, vp.getAttribute("how/lowprf"))
+    self.assertEqual(1200, vp.getAttribute("how/highprf"))
     self.assertAlmostEqual(0.61, vp.getAttribute("how/pulsewidth"), 4)
     self.assertAlmostEqual(5.35, vp.getAttribute("how/wavelength"), 4)
     self.assertAlmostEqual(0.8, vp.getAttribute("how/RXbandwidth"), 4)
     self.assertAlmostEqual(3.1, vp.getAttribute("how/RXlossH"), 4)
     self.assertAlmostEqual(1.9, vp.getAttribute("how/TXlossH"), 4)
     self.assertAlmostEqual(44.9, vp.getAttribute("how/antgainH"), 4)
-    self.assertEquals("AVERAGE", vp.getAttribute("how/azmethod"))
-    self.assertEquals("AVERAGE", vp.getAttribute("how/binmethod"))
-    self.assertEquals("False", vp.getAttribute("how/malfunc"))
+    self.assertEqual("AVERAGE", vp.getAttribute("how/azmethod"))
+    self.assertEqual("AVERAGE", vp.getAttribute("how/binmethod"))
+    self.assertEqual("False", vp.getAttribute("how/malfunc"))
     self.assertAlmostEqual(277.4, vp.getAttribute("how/nomTXpower"), 4)
-    self.assertEquals("b94 3dd 000 000 000:", vp.getAttribute("how/radar_msg"), 4)
+    self.assertEqual("b94 3dd 000 000 000:", vp.getAttribute("how/radar_msg"), 4)
     self.assertAlmostEqual(73.101, vp.getAttribute("how/radconstH"), 4)
     self.assertAlmostEqual(0.2, vp.getAttribute("how/radomelossH"), 4)
     self.assertAlmostEqual(2.0, vp.getAttribute("how/rpm"), 4)
-    self.assertEquals("PARTEC2", vp.getAttribute("how/software"))
-    self.assertEquals("ERIC", vp.getAttribute("how/system"))
-    self.assertEquals(4.0, vp.getAttribute("how/minrange"))
-    self.assertEquals(40.0, vp.getAttribute("how/maxrange"))
+    self.assertEqual("PARTEC2", vp.getAttribute("how/software"))
+    self.assertEqual("ERIC", vp.getAttribute("how/system"))
+    self.assertEqual(4.0, vp.getAttribute("how/minrange"))
+    self.assertEqual(40.0, vp.getAttribute("how/maxrange"))
 
     robj = _raveio.new()
     robj.object = vp
@@ -237,49 +237,49 @@ class WrwpTest(unittest.TestCase):
       hght = vp.getHGHT()
       nv = vp.getNV()
 
-      self.assertEquals(1, uwnd.xsize)
-      self.assertEquals(60, uwnd.ysize)
-      self.assertEquals("UWND", uwnd.getAttribute("what/quantity"))
-
-      self.assertEquals(1, vwnd.xsize)
-      self.assertEquals(60, vwnd.ysize)
-      self.assertEquals("VWND", vwnd.getAttribute("what/quantity"))
-
-      self.assertEquals(1, hght.xsize)
-      self.assertEquals(60, hght.ysize)
-      self.assertEquals("HGHT", hght.getAttribute("what/quantity"))
-
-      self.assertEquals(1, nv.xsize)
-      self.assertEquals(60, nv.ysize)
-      self.assertEquals("n", nv.getAttribute("what/quantity"))
-
-      self.assertEquals(60, vp.getLevels())
-      self.assertEquals(200, vp.interval)
-      self.assertEquals(0, vp.minheight)
-      self.assertEquals(12000, vp.maxheight)
-      self.assertEquals(pvol.source, vp.source)
-      self.assertEquals(pvol.date, vp.date)
-      self.assertEquals(pvol.time, vp.time)
+      self.assertEqual(1, uwnd.xsize)
+      self.assertEqual(60, uwnd.ysize)
+      self.assertEqual("UWND", uwnd.getAttribute("what/quantity"))
+
+      self.assertEqual(1, vwnd.xsize)
+      self.assertEqual(60, vwnd.ysize)
+      self.assertEqual("VWND", vwnd.getAttribute("what/quantity"))
+
+      self.assertEqual(1, hght.xsize)
+      self.assertEqual(60, hght.ysize)
+      self.assertEqual("HGHT", hght.getAttribute("what/quantity"))
+
+      self.assertEqual(1, nv.xsize)
+      self.assertEqual(60, nv.ysize)
+      self.assertEqual("n", nv.getAttribute("what/quantity"))
+
+      self.assertEqual(60, vp.getLevels())
+      self.assertEqual(200, vp.interval)
+      self.assertEqual(0, vp.minheight)
+      self.assertEqual(12000, vp.maxheight)
+      self.assertEqual(pvol.source, vp.source)
+      self.assertEqual(pvol.date, vp.date)
+      self.assertEqual(pvol.time, vp.time)
     
-      self.assertEquals(450, vp.getAttribute("how/lowprf"))
-      self.assertEquals(600, vp.getAttribute("how/highprf"))
+      self.assertEqual(450, vp.getAttribute("how/lowprf"))
+      self.assertEqual(600, vp.getAttribute("how/highprf"))
       self.assertAlmostEqual(0.5, vp.getAttribute("how/pulsewidth"), 4)
       self.assertAlmostEqual(5.348660945892334, vp.getAttribute("how/wavelength"), 4)
       self.assertAlmostEqual(2.5, vp.getAttribute("how/RXbandwidth"), 4)
       self.assertAlmostEqual(1.600000023841858, vp.getAttribute("how/RXlossH"), 4)
       self.assertAlmostEqual(2.3000001907348633, vp.getAttribute("how/TXlossH"), 4)
       self.assertAlmostEqual(44.290000915527344, vp.getAttribute("how/antgainH"), 4)
-      self.assertEquals("AVERAGE", vp.getAttribute("how/azmethod"))
-      self.assertEquals("AVERAGE", vp.getAttribute("how/binmethod"))
-      self.assertEquals("False", vp.getAttribute("how/malfunc"))
+      self.assertEqual("AVERAGE", vp.getAttribute("how/azmethod"))
+      self.assertEqual("AVERAGE", vp.getAttribute("how/binmethod"))
+      self.assertEqual("False", vp.getAttribute("how/malfunc"))
       self.assertAlmostEqual(270.0, vp.getAttribute("how/nomTXpower"), 4)
-      self.assertEquals("", vp.getAttribute("how/radar_msg"), 4)
+      self.assertEqual("", vp.getAttribute("how/radar_msg"), 4)
       self.assertAlmostEqual(71.4227294921875, vp.getAttribute("how/radconstH"), 4)
       self.assertAlmostEqual(3.0, vp.getAttribute("how/rpm"), 4)
-      self.assertEquals("EDGE", vp.getAttribute("how/software"))
-      self.assertEquals("EECDWSR-2501C-SDP", vp.getAttribute("how/system"))
-      self.assertEquals(4.0, vp.getAttribute("how/minrange"))
-      self.assertEquals(40.0, vp.getAttribute("how/maxrange"))
+      self.assertEqual("EDGE", vp.getAttribute("how/software"))
+      self.assertEqual("EECDWSR-2501C-SDP", vp.getAttribute("how/system"))
+      self.assertEqual(4.0, vp.getAttribute("how/minrange"))
+      self.assertEqual(40.0, vp.getAttribute("how/maxrange"))
 
       robj = _raveio.new()
       robj.object = vp
@@ -287,7 +287,7 @@ class WrwpTest(unittest.TestCase):
     except:
       exceptionTest = True
 
-    self.assertEquals(True, exceptionTest)
+    self.assertEqual(True, exceptionTest)
 
 if __name__ == "__main__":
   unittest.main()
index 53a3660..b410382 100755 (executable)
@@ -25,6 +25,12 @@ RESULT=0
 RAVE_ROOT_DIR=`fgrep RAVE_ROOT_DIR "${DEF_MK_FILE}" | sed -e"s/\(RAVE_ROOT_DIR=[ \t]*\)//"`
 RAVE_ROOT_MKFILE="$RAVE_ROOT_DIR/mkf/def.mk"
 
+# Identify python version
+PYTHON_BIN=`fgrep PYTHON_BIN "${RAVE_ROOT_MKFILE}" | sed -e "s/\(PYTHON_BIN=[ \t]*\)//"`
+if [ "$PYTHON_BIN" = "" ]; then
+  PYTHON_BIN=python
+fi
+
 # HLHDFS MKF FILE
 HLHDF_MKFFILE=`fgrep HLHDF_HLDEF_MK_FILE "${RAVE_ROOT_MKFILE}" | sed -e"s/\(HLHDF_HLDEF_MK_FILE=[ \t]*\)//"`
 
@@ -34,7 +40,7 @@ HDF5_LDPATH=`fgrep HDF5_LIBDIR "${HLHDF_MKFFILE}" | sed -e"s/\(HDF5_LIBDIR=[ \t]
 # Get HLHDFs libpath from raves mkf file
 HLHDF_LDPATH=`fgrep HLHDF_LIB_DIR "${RAVE_ROOT_MKFILE}" | sed -e"s/\(HLHDF_LIB_DIR=[ \t]*\)//"`
 
-BNAME=`python -c 'from distutils import util; import sys; print "lib.%s-%s" % (util.get_platform(), sys.version[0:3])'`
+BNAME=`$PYTHON_BIN -c 'from distutils import util; import sys; print("lib.%s-%s" % (util.get_platform(), sys.version[0:3]))'`
 
 RBPATH="${SCRIPTPATH}/../pywrwp"
 RAVE_LDPATH="${RAVE_ROOT_DIR}/lib"
@@ -80,9 +86,9 @@ NARGS=$#
 PYSCRIPT=
 DIRNAME=
 if [ $NARGS -eq 1 ]; then
-  PYSCRIPT=`python -c "import os;print os.path.abspath(\"$1\")"`
+  PYSCRIPT=`$PYTHON_BIN -c "import os;print(os.path.abspath(\"$1\"))"`
 elif [ $NARGS -eq 2 ]; then
-  PYSCRIPT=`python -c "import os;print os.path.abspath(\"$1\")"`
+  PYSCRIPT=`$PYTHON_BIN -c "import os;print(os.path.abspath(\"$1\"))"`
   DIRNAME="$2"
 elif [ $NARGS -eq 0 ]; then
   # Do nothing
@@ -99,9 +105,9 @@ fi
 
 if [ "$PYSCRIPT" != "" ]; then
   #valgrind --leak-check=full --show-reachable=yes 
-  python "$PYSCRIPT"
+  $PYTHON_BIN "$PYSCRIPT"
 else
-  python
+  $PYTHON_BIN
 fi
 
 VAL=$?