Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

CLIMATE-958 Disable Pydap for Python 2 build, activate for Python 3 build #516

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
language: python
python:
- "2.7"
- "3.4"
- "3.5"
- "3.6"
notifications:
email: false
install:
Expand Down
1 change: 0 additions & 1 deletion deps_py2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ basemap
netcdf4
h5py
bottle
Pydap
lxml
python-dateutil
mock
Expand Down
1 change: 1 addition & 0 deletions deps_py3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ scipy
matplotlib
basemap
netcdf4
Pydap
h5py
bottle
python-dateutil
Expand Down
14 changes: 10 additions & 4 deletions ocw/dataset_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,22 @@ def __init__(self, *loader_opts):
'podaac': podaac.extract_l4_granule
}

# Exclude esgf and dap for python 3 until they are compatible
# Exclude esgf for python > 2.7.x. until it is compatible
try:
import ocw.data_source.esgf as esgf
import ocw.data_source.dap as dap
self._source_loaders['dap'] = dap.load
self._source_loaders['esgf'] = esgf.load_dataset
except ImportError:
warnings.warn('dap and esgf loaders missing. If these are needed, '
warnings.warn('esgf loader missing. If this is needed, '
'fallback to python 2.7.x.')

# Exclude dap for python < 3.5 until it is compatible
try:
import ocw.data_source.dap as dap
self._source_loaders['dap'] = dap.load
except ImportError:
warnings.warn('dap loaders missing. If this is needed, '
'upgrade to python >=3.5.x.')

def add_source_loader(self, loader_name, loader_func):
'''
Add a custom source loader.
Expand Down
15 changes: 13 additions & 2 deletions ocw/tests/test_dap.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@

import unittest
import datetime as dt
import ocw.data_source.dap as dap
try:
import ocw.data_source.dap as dap
except ImportError:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good @lewismc 🎆
This will probably solve the problem

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any tests that need such skipping, let me know about it. I can work on it then

warnings.warn('dap loaders missing. If this is needed, upgrade to python >=3.5.x.')
import platform
from ocw.dataset import Dataset


@unittest.skipIf(platform.python_version() < (3.5), "Pydap not supported in Python < 3.5")
class TestDap(unittest.TestCase):

@classmethod
Expand Down Expand Up @@ -49,25 +53,32 @@ def setUpClass(cls):
cls.name2 = 'foo2'
cls.dataset2 = dap.load(cls.url2, 'scale_factor', name=cls.name)'''

@unittest.skipIf(platform.python_version() < (3.5), "Pydap not supported in Python < 3.5")
def test_dataset_is_returned(self):
self.assertTrue(isinstance(self.dataset, Dataset))

@unittest.skipIf(platform.python_version() < (3.5), "Pydap not supported in Python < 3.5")
def test_correct_lat_shape(self):
self.assertEquals(len(self.dataset.lats), 29)

@unittest.skipIf(platform.python_version() < (3.5), "Pydap not supported in Python < 3.5")
def test_correct_lon_shape(self):
self.assertEquals(len(self.dataset.lons), 26)

@unittest.skipIf(platform.python_version() < (3.5), "Pydap not supported in Python < 3.5")
def test_correct_time_shape(self):
self.assertEquals(len(self.dataset.times), 1)

@unittest.skipIf(platform.python_version() < (3.5), "Pydap not supported in Python < 3.5")
def test_valid_date_conversion(self):
start = dt.datetime(2006, 6, 7, 12)
self.assertTrue(start == self.dataset.times[0])

@unittest.skipIf(platform.python_version() < (3.5), "Pydap not supported in Python < 3.5")
def test_custom_dataset_name(self):
self.assertEquals(self.dataset.name, self.name)

@unittest.skipIf(platform.python_version() < (3.5), "Pydap not supported in Python < 3.5")
def test_dataset_origin(self):
self.assertEquals(self.dataset.origin['source'], 'dap')
self.assertEquals(self.dataset.origin['url'], self.url)
Expand Down
2 changes: 1 addition & 1 deletion ocw/tests/test_podaac.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import datetime as dt
from ocw.dataset import Dataset


@unittest.skip("CLIMATE-959 Remove ocw.tests.test_podaac.TestPodaacDataSource from tests until service is more reliable")
class TestPodaacDataSource(unittest.TestCase):

@classmethod
Expand Down