From 43e343a60d6cf2a7d89a57a0c5bca364d991e492 Mon Sep 17 00:00:00 2001
From: jlaura <jlaura@asu.edu>
Date: Thu, 13 Jun 2019 08:46:55 -0700
Subject: [PATCH] Fixes failing tests (#113)

* Fixes failing tests

* removes python 3.5 support

* Skips conda upload if a PR
---
 .travis.yml                    | 10 ++++++----
 environment.yml                |  6 +++---
 plio/io/io_gdal.py             |  2 ++
 plio/io/io_yaml.py             |  2 +-
 plio/io/tests/test_io_gdal.py  | 26 ++++++++++++++------------
 plio/io/tests/test_metadata.py |  3 ++-
 plio/utils/log.py              |  2 +-
 7 files changed, 29 insertions(+), 22 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 96bf55c..6f5b18e 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -10,11 +10,10 @@ os:
   - osx
 
 env:
-  - PYTHON_VERSION=3.5 HAS_GDAL=true
   - PYTHON_VERSION=3.6 HAS_GDAL=true
-  - PYTHON_VERSION=3.5 HAS_GDAL=false
   - PYTHON_VERSION=3.6 HAS_GDAL=false
-
+  - PYTHON_VERSION=3.7 HAS_GDAL=true
+  - PYTHON_VERSION=3.7 HAS_GDAL=false
 before_install:
   # We do this conditionally because it saves us some downloading if the
   # version is the same.
@@ -56,7 +55,10 @@ after_success:
   - conda config --set anaconda_upload no
   - conda build recipe -q
   - builddir=(`conda build recipe --output`)
-  - anaconda -t="$CONDA_UPLOAD_TOKEN" upload $builddir --label dev --force;
+  - |
+    if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
+      anaconda -t="$CONDA_UPLOAD_TOKEN" upload $builddir --force;
+    fi
 
   # Docs to gh-pages
   - source activate test  # Reactivate the env to have all deps installed.
diff --git a/environment.yml b/environment.yml
index 653b307..908f061 100644
--- a/environment.yml
+++ b/environment.yml
@@ -3,8 +3,8 @@ channels:
   - conda-forge
   - usgs-astrogeology
 dependencies:
-  - libgdal 
-  - gdal 
+  - libgdal < 3 
+  - gdal < 3 
   - numpy 
   - pyproj 
   - h5py 
@@ -22,4 +22,4 @@ dependencies:
   - pytest-cov 
   - sh 
   - coveralls 
-  - nbsphinx
\ No newline at end of file
+  - nbsphinx
diff --git a/plio/io/io_gdal.py b/plio/io/io_gdal.py
index 9573c0f..5fa66a5 100644
--- a/plio/io/io_gdal.py
+++ b/plio/io/io_gdal.py
@@ -191,6 +191,7 @@ class GeoDataset(object):
 
     @property
     def forward_affine(self):
+        print(self.geotransform)
         self._fa = affine.Affine.from_gdal(*self.geotransform)
         return self._fa
 
@@ -460,6 +461,7 @@ class GeoDataset(object):
                    (Latitude, Longitude) corresponding to the given (x,y).
 
         """
+
         lon, lat = self.forward_affine * (x,y)
         lon, lat, _ = self.coordinate_transformation.TransformPoint(lon, lat)
         return lat, lon
diff --git a/plio/io/io_yaml.py b/plio/io/io_yaml.py
index 59d1a70..a3c8001 100644
--- a/plio/io/io_yaml.py
+++ b/plio/io/io_yaml.py
@@ -17,7 +17,7 @@ def read_yaml(inputfile):
     """
     try:
         with open(inputfile, 'r') as f:
-            ydict = yaml.load(f)
+            ydict = yaml.safe_load(f)
     except:  # pragma: no cover
         raise IOError('Unable to load YAML file.')
     return ydict
diff --git a/plio/io/tests/test_io_gdal.py b/plio/io/tests/test_io_gdal.py
index 5bb1991..0423ca3 100644
--- a/plio/io/tests/test_io_gdal.py
+++ b/plio/io/tests/test_io_gdal.py
@@ -62,7 +62,9 @@ class TestMercator(unittest.TestCase):
     def test_spheroid(self):
         sphere = self.dataset.spheroid
         self.assertAlmostEqual(sphere[0], 3396190.0, 6)
-        self.assertEqual(self.dataset.spheroid, (3396190.0, 3376200.0, 169.8944472236118))
+        self.assertAlmostEqual(self.dataset.spheroid[0], 3396190.0)
+        self.assertAlmostEqual(self.dataset.spheroid[1], 3376200.0)
+        self.assertAlmostEqual(self.dataset.spheroid[2], 169.8944472236118)
         self.assertAlmostEqual(sphere[1], 3376200.0, 6)
         self.assertAlmostEqual(sphere[2], 169.8944472236118, 6)
 
@@ -225,17 +227,17 @@ class TestWriter(unittest.TestCase):
             UNIT["Meter",1.0]]"""
         io_gdal.array_to_raster(self.arr, 'test.tif', projection=wktsrs)
         expected_srs = """PROJCS["Moon2000_Mercator180",
-            GEOGCS["GCS_Moon_2000",
-                DATUM["Moon_2000",
-                    SPHEROID["Moon_2000_IAU_IAG",1737400,0]],
-                PRIMEM["Reference_Meridian",0],
-                UNIT["Degree",0.017453292519943295]],
-            PROJECTION["Mercator_2SP"],
-            PARAMETER["central_meridian",180],
-            PARAMETER["false_easting",0],
-            PARAMETER["false_northing",0],
-            PARAMETER["standard_parallel_1",0],
-            UNIT["Meter",1]]"""
+    GEOGCS["GCS_Moon_2000",
+        DATUM["Moon_2000",
+            SPHEROID["Moon_2000_IAU_IAG",1737400,0]],
+        PRIMEM["Reference_Meridian",0],
+        UNIT["Degree",0.017453292519943295]],
+    PROJECTION["Mercator_2SP"],
+    PARAMETER["central_meridian",180],
+    PARAMETER["false_easting",0],
+    PARAMETER["false_northing",0],
+    PARAMETER["standard_parallel_1",0],
+    UNIT["Meter",1]]"""
         dataset = io_gdal.GeoDataset('test.tif')
         test_srs = dataset.spatial_reference.__str__()
         self.assertEqual(test_srs.split(), expected_srs.split())
diff --git a/plio/io/tests/test_metadata.py b/plio/io/tests/test_metadata.py
index df63a00..6eef483 100644
--- a/plio/io/tests/test_metadata.py
+++ b/plio/io/tests/test_metadata.py
@@ -52,7 +52,8 @@ def test_export_to_proj4(srs_mars):
     Check that proj4 is not supporting Moon2000_Mercator
     """
     proj4 = srs_mars.ExportToProj4()
-    assert proj4 == '+proj=merc +lon_0=180 +lat_ts=0 +x_0=0 +y_0=0 +a=1737400 +b=1737400 +units=m +no_defs '
+    for element in '+proj=merc +lon_0=180 +lat_ts=0 +x_0=0 +y_0=0 +a=1737400 +b=1737400 +units=m +no_defs'.split():
+        assert element in proj4
 
 @pytest.mark.skipif(gdal is None, reason="GDAL not installed")
 def test_scale_factor(srs_mars):
diff --git a/plio/utils/log.py b/plio/utils/log.py
index b578eae..162d010 100644
--- a/plio/utils/log.py
+++ b/plio/utils/log.py
@@ -32,7 +32,7 @@ def setup_logging(path=get_path('logging.json'),
                 config = json.load(f)
             elif logtype == '.yaml':
                 import yaml
-                config = yaml.load(f.read())
+                config = yaml.safe_load(f.read())
         logging.config.dictConfig(config)
     else:
         logging.basicConfig(level=level)
-- 
GitLab