Skip to content
Merged
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
7 changes: 2 additions & 5 deletions lib/iris/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,11 +454,8 @@ def sample_data_path(*path_to_join):
if iris_sample_data is not None:
target = os.path.join(iris_sample_data.path, target)
else:
wmsg = ("iris.config.SAMPLE_DATA_DIR was deprecated in v1.10.0 and "
"will be removed in a future Iris release. Install the "
"'iris_sample_data' package.")
warn_deprecated(wmsg)
target = os.path.join(iris.config.SAMPLE_DATA_DIR, target)
raise ImportError("Please install the 'iris_sample_data' package to "
"access sample data.")
if not glob.glob(target):
raise ValueError('Sample data file(s) at {!r} not found.\n'
'NB. This function is only for locating files in the '
Expand Down
13 changes: 0 additions & 13 deletions lib/iris/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@

----------

.. py:data:: iris.config.SAMPLE_DATA_DIR

Local directory where sample data exists. Defaults to "sample_data"
sub-directory of the Iris package install directory. The sample data
directory supports the Iris gallery. Directory contents accessed via
:func:`iris.sample_data_path`.

.. deprecated:: 1.10

.. py:data:: iris.config.TEST_DATA_DIR

Local directory where test data exists. Defaults to "test_data"
Expand Down Expand Up @@ -123,10 +114,6 @@ def get_dir_option(section, option, default=None):
_RESOURCE_SECTION = 'Resources'


SAMPLE_DATA_DIR = get_dir_option(
_RESOURCE_SECTION, 'sample_data_dir',
default=os.path.join(os.path.dirname(__file__), 'sample_data'))

TEST_DATA_DIR = get_dir_option(_RESOURCE_SECTION, 'test_data_dir',
default=os.path.join(os.path.dirname(__file__),
'test_data'))
Expand Down
66 changes: 25 additions & 41 deletions lib/iris/tests/unit/test_sample_data_path.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# (C) British Crown Copyright 2016, Met Office
# (C) British Crown Copyright 2016 - 2017, Met Office
#
# This file is part of Iris.
#
Expand Down Expand Up @@ -31,7 +31,6 @@
import mock

from iris import sample_data_path
from iris._deprecation import IrisDeprecation


def _temp_file(sample_dir):
Expand Down Expand Up @@ -61,57 +60,42 @@ def test_call(self):
result = sample_data_path(os.path.basename(sample_file))
self.assertEqual(result, sample_file)


class TestConfig(tests.IrisTest):
def setUp(self):
# Force iris_sample_data to be unavailable.
self.patch('iris.iris_sample_data', None)
# All of our tests are going to run with SAMPLE_DATA_DIR
# redirected to a temporary directory.
self.sample_dir = tempfile.mkdtemp()
patcher = mock.patch('iris.config.SAMPLE_DATA_DIR', self.sample_dir)
patcher.start()
self.addCleanup(patcher.stop)

def tearDown(self):
shutil.rmtree(self.sample_dir)

def test_file_ok(self):
sample_path = _temp_file(self.sample_dir)
result = sample_data_path(os.path.basename(sample_path))
self.assertEqual(result, sample_path)

def test_file_not_found(self):
with self.assertRaisesRegexp(ValueError, 'Sample data .* not found'):
sample_data_path('foo')
with mock.patch('iris_sample_data.path', self.sample_dir):
with self.assertRaisesRegexp(ValueError,
'Sample data .* not found'):
sample_data_path('foo')

def test_file_absolute(self):
with self.assertRaisesRegexp(ValueError, 'Absolute path'):
sample_data_path(os.path.abspath('foo'))
with mock.patch('iris_sample_data.path', self.sample_dir):
with self.assertRaisesRegexp(ValueError, 'Absolute path'):
sample_data_path(os.path.abspath('foo'))

def test_glob_ok(self):
sample_path = _temp_file(self.sample_dir)
sample_glob = '?' + os.path.basename(sample_path)[1:]
result = sample_data_path(sample_glob)
self.assertEqual(result, os.path.join(self.sample_dir, sample_glob))
with mock.patch('iris_sample_data.path', self.sample_dir):
result = sample_data_path(sample_glob)
self.assertEqual(result, os.path.join(self.sample_dir,
sample_glob))

def test_glob_not_found(self):
with self.assertRaisesRegexp(ValueError, 'Sample data .* not found'):
sample_data_path('foo.*')
with mock.patch('iris_sample_data.path', self.sample_dir):
with self.assertRaisesRegexp(ValueError,
'Sample data .* not found'):
sample_data_path('foo.*')

def test_glob_absolute(self):
with self.assertRaisesRegexp(ValueError, 'Absolute path'):
sample_data_path(os.path.abspath('foo.*'))
with mock.patch('iris_sample_data.path', self.sample_dir):
with self.assertRaisesRegexp(ValueError, 'Absolute path'):
sample_data_path(os.path.abspath('foo.*'))

def test_warn_deprecated(self):
sample_path = _temp_file(self.sample_dir)
with mock.patch('warnings.warn') as warn:
sample_data_path(os.path.basename(sample_path))
self.assertEqual(warn.call_count, 1)
(warn_msg, warn_exception), _ = warn.call_args
msg = 'iris.config.SAMPLE_DATA_DIR was deprecated'
self.assertTrue(warn_msg.startswith(msg))
self.assertEqual(warn_exception, IrisDeprecation)

class TestIrisSampleDataMissing(tests.IrisTest):
def test_no_iris_sample_data(self):
self.patch('iris.iris_sample_data', None)
with self.assertRaisesRegexp(ImportError, 'Please install'):
sample_data_path('')


if __name__ == '__main__':
Expand Down