diff --git a/lib/iris/__init__.py b/lib/iris/__init__.py index 88c66aa336..77fd7cda5a 100644 --- a/lib/iris/__init__.py +++ b/lib/iris/__init__.py @@ -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 ' diff --git a/lib/iris/config.py b/lib/iris/config.py index 2bb82924a2..298d4d47f4 100644 --- a/lib/iris/config.py +++ b/lib/iris/config.py @@ -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" @@ -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')) diff --git a/lib/iris/tests/unit/test_sample_data_path.py b/lib/iris/tests/unit/test_sample_data_path.py index 2c7d45d71d..a941543151 100644 --- a/lib/iris/tests/unit/test_sample_data_path.py +++ b/lib/iris/tests/unit/test_sample_data_path.py @@ -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. # @@ -31,7 +31,6 @@ import mock from iris import sample_data_path -from iris._deprecation import IrisDeprecation def _temp_file(sample_dir): @@ -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__':