From 22c49f4ab0bc8ef3cfa2a0863e4c794870afc97c Mon Sep 17 00:00:00 2001 From: Bouwe Andela Date: Thu, 30 Jan 2020 21:43:40 +0100 Subject: [PATCH 1/2] Remove no longer required dependencies --- setup.py | 3 --- tests/__init__.py | 2 +- .../cmor/_fixes/cmip5/test_gfdl_esm2g.py | 11 ++++++----- tests/integration/test_recipe.py | 2 +- tests/unit/cmor/test_fix.py | 3 +-- tests/unit/preprocessor/_mapping/test_mapping.py | 3 ++- .../preprocessor/_regrid/test__stock_cube.py | 2 +- .../preprocessor/_regrid/test_extract_levels.py | 2 +- tests/unit/preprocessor/_regrid/test_regrid.py | 2 +- .../_regrid_esmpy/test_regrid_esmpy.py | 16 +++++++++++----- .../test_weighting_landsea_fraction.py | 2 +- 11 files changed, 26 insertions(+), 22 deletions(-) diff --git a/setup.py b/setup.py index c34a06005f..3397270f3b 100755 --- a/setup.py +++ b/setup.py @@ -47,9 +47,6 @@ # Test dependencies # Execute 'python setup.py test' to run tests 'test': [ - 'easytest', - 'mock', - 'nose', 'pytest>=3.9', 'pytest-cov', 'pytest-env', diff --git a/tests/__init__.py b/tests/__init__.py index 961e111934..1f64f708a9 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -4,8 +4,8 @@ """ import unittest from functools import wraps +from unittest import mock -import mock import numpy as np diff --git a/tests/integration/cmor/_fixes/cmip5/test_gfdl_esm2g.py b/tests/integration/cmor/_fixes/cmip5/test_gfdl_esm2g.py index 9e04694dfe..6332ad9312 100644 --- a/tests/integration/cmor/_fixes/cmip5/test_gfdl_esm2g.py +++ b/tests/integration/cmor/_fixes/cmip5/test_gfdl_esm2g.py @@ -1,15 +1,16 @@ """Tests for fixes of GFDL-ESM2G (CMIP5).""" import unittest +from unittest import mock import iris -from iris.cube import Cube -import mock import pytest from cf_units import Unit +from iris.cube import Cube + +from esmvalcore.cmor._fixes.cmip5.gfdl_esm2g import (AllVars, Areacello, Co2, + FgCo2, Usi, Vsi, + _get_and_remove) from esmvalcore.cmor.fix import Fix -from esmvalcore.cmor._fixes.cmip5.gfdl_esm2g import (_get_and_remove, AllVars, - Co2, FgCo2, Usi, Vsi, - Areacello) CUBE_1 = iris.cube.Cube([1.0], long_name='to_be_rm') CUBE_2 = iris.cube.Cube([1.0], long_name='not_to_be_rm') diff --git a/tests/integration/test_recipe.py b/tests/integration/test_recipe.py index 10eff20596..cff40fcef8 100644 --- a/tests/integration/test_recipe.py +++ b/tests/integration/test_recipe.py @@ -2,11 +2,11 @@ from pathlib import Path from pprint import pformat from textwrap import dedent +from unittest.mock import create_autospec import iris import pytest import yaml -from mock import create_autospec import esmvalcore from esmvalcore._recipe import TASKSEP, read_recipe_file diff --git a/tests/unit/cmor/test_fix.py b/tests/unit/cmor/test_fix.py index a449c822b2..a51f23b8ce 100644 --- a/tests/unit/cmor/test_fix.py +++ b/tests/unit/cmor/test_fix.py @@ -1,8 +1,7 @@ """Unit tests for the variable_info module.""" import unittest - -import mock +from unittest import mock from esmvalcore.cmor.fix import Fix, fix_data, fix_file, fix_metadata diff --git a/tests/unit/preprocessor/_mapping/test_mapping.py b/tests/unit/preprocessor/_mapping/test_mapping.py index adfca6a52e..dc838b3a54 100644 --- a/tests/unit/preprocessor/_mapping/test_mapping.py +++ b/tests/unit/preprocessor/_mapping/test_mapping.py @@ -1,7 +1,8 @@ """Unit tests for the esmvalcore.preprocessor._mapping module.""" +from unittest import mock + import cf_units import iris -import mock import numpy as np import tests diff --git a/tests/unit/preprocessor/_regrid/test__stock_cube.py b/tests/unit/preprocessor/_regrid/test__stock_cube.py index 42af553e70..ccf88a58ef 100644 --- a/tests/unit/preprocessor/_regrid/test__stock_cube.py +++ b/tests/unit/preprocessor/_regrid/test__stock_cube.py @@ -5,9 +5,9 @@ """ import unittest +from unittest import mock import iris -import mock import numpy as np import tests diff --git a/tests/unit/preprocessor/_regrid/test_extract_levels.py b/tests/unit/preprocessor/_regrid/test_extract_levels.py index d5f64bbc66..f37a79c2ab 100644 --- a/tests/unit/preprocessor/_regrid/test_extract_levels.py +++ b/tests/unit/preprocessor/_regrid/test_extract_levels.py @@ -1,9 +1,9 @@ """Unit tests for :func:`esmvalcore.preprocessor.regrid.extract_levels`.""" import unittest +from unittest import mock import iris -import mock import numpy as np from numpy import ma diff --git a/tests/unit/preprocessor/_regrid/test_regrid.py b/tests/unit/preprocessor/_regrid/test_regrid.py index f1f4473313..b1f951fb55 100644 --- a/tests/unit/preprocessor/_regrid/test_regrid.py +++ b/tests/unit/preprocessor/_regrid/test_regrid.py @@ -4,9 +4,9 @@ """ import unittest +from unittest import mock import iris -import mock import tests from esmvalcore.preprocessor import regrid diff --git a/tests/unit/preprocessor/_regrid_esmpy/test_regrid_esmpy.py b/tests/unit/preprocessor/_regrid_esmpy/test_regrid_esmpy.py index 0fa0cab352..6ea392e8fa 100644 --- a/tests/unit/preprocessor/_regrid_esmpy/test_regrid_esmpy.py +++ b/tests/unit/preprocessor/_regrid_esmpy/test_regrid_esmpy.py @@ -1,15 +1,21 @@ """Unit tests for the esmvalcore.preprocessor._regrid_esmpy module.""" +from unittest import mock + import cf_units import iris -import mock import numpy as np from iris.exceptions import CoordinateNotFoundError import tests -from esmvalcore.preprocessor._regrid_esmpy import ( - build_regridder, build_regridder_2d, coords_iris_to_esmpy, - cube_to_empty_field, get_grid, get_grid_representant, - get_grid_representants, get_representant, is_lon_circular, regrid) +from esmvalcore.preprocessor._regrid_esmpy import (build_regridder, + build_regridder_2d, + coords_iris_to_esmpy, + cube_to_empty_field, + get_grid, + get_grid_representant, + get_grid_representants, + get_representant, + is_lon_circular, regrid) def identity(*args, **kwargs): diff --git a/tests/unit/preprocessor/_weighting/test_weighting_landsea_fraction.py b/tests/unit/preprocessor/_weighting/test_weighting_landsea_fraction.py index 61cba37a8a..44618046e5 100644 --- a/tests/unit/preprocessor/_weighting/test_weighting_landsea_fraction.py +++ b/tests/unit/preprocessor/_weighting/test_weighting_landsea_fraction.py @@ -1,8 +1,8 @@ """Unit tests for :mod:`esmvalcore.preprocessor._weighting`.""" from collections import OrderedDict +from unittest import mock import iris -import mock import numpy as np import pytest from cf_units import Unit From e836a5975516bed72536c5dae935804282b76375 Mon Sep 17 00:00:00 2001 From: Bouwe Andela Date: Thu, 30 Jan 2020 23:33:11 +0100 Subject: [PATCH 2/2] Fix some warnings --- esmvalcore/preprocessor/__init__.py | 2 +- esmvalcore/preprocessor/_mapping.py | 2 +- esmvalcore/preprocessor/_regrid.py | 9 +++++---- setup.cfg | 1 - .../integration/cmor/_fixes/cmip6/test_ipsl_cm6a_lr.py | 4 ++-- tests/integration/preprocessor/_io/test_load.py | 2 +- tests/unit/preprocessor/_derive/test_uajet.py | 10 ++++++++-- tests/unit/preprocessor/_regrid/test__stock_cube.py | 8 ++++---- tests/unit/preprocessor/_time/test_time.py | 2 ++ tests/unit/preprocessor/_units/test_convert_units.py | 2 +- 10 files changed, 25 insertions(+), 17 deletions(-) diff --git a/esmvalcore/preprocessor/__init__.py b/esmvalcore/preprocessor/__init__.py index 2438dfb876..6a6a74de97 100644 --- a/esmvalcore/preprocessor/__init__.py +++ b/esmvalcore/preprocessor/__init__.py @@ -119,7 +119,7 @@ def _get_itype(step): """Get the input type of a preprocessor function.""" function = globals()[step] - itype = inspect.getargspec(function).args[0] + itype = inspect.getfullargspec(function).args[0] return itype diff --git a/esmvalcore/preprocessor/_mapping.py b/esmvalcore/preprocessor/_mapping.py index bd8bb8085d..801eca15f9 100644 --- a/esmvalcore/preprocessor/_mapping.py +++ b/esmvalcore/preprocessor/_mapping.py @@ -15,7 +15,7 @@ def _is_single_item(testee): We count string types as 'single', also. """ return (isinstance(testee, str) - or not isinstance(testee, collections.Iterable)) + or not isinstance(testee, collections.abc.Iterable)) def _as_list_of_coords(cube, names_or_coords): diff --git a/esmvalcore/preprocessor/_regrid.py b/esmvalcore/preprocessor/_regrid.py index 58a96491d4..bf24c4c738 100644 --- a/esmvalcore/preprocessor/_regrid.py +++ b/esmvalcore/preprocessor/_regrid.py @@ -130,16 +130,17 @@ def _stock_cube(spec, lat_offset=True, lon_offset=True): # Construct the latitude coordinate, with bounds. if lat_offset: latdata = np.linspace(_LAT_MIN + mid_dlat, _LAT_MAX - mid_dlat, - _LAT_RANGE / dlat) + int(_LAT_RANGE / dlat)) else: - latdata = np.linspace(_LAT_MIN, _LAT_MAX, _LAT_RANGE / dlat + 1) + latdata = np.linspace(_LAT_MIN, _LAT_MAX, int(_LAT_RANGE / dlat) + 1) # Construct the longitude coordinat, with bounds. if lon_offset: londata = np.linspace(_LON_MIN + mid_dlon, _LON_MAX - mid_dlon, - _LON_RANGE / dlon) + int(_LON_RANGE / dlon)) else: - londata = np.linspace(_LON_MIN, _LON_MAX - dlon, _LON_RANGE / dlon) + londata = np.linspace(_LON_MIN, _LON_MAX - dlon, + int(_LON_RANGE / dlon)) lats = iris.coords.DimCoord( latdata, diff --git a/setup.cfg b/setup.cfg index 0e231e0aa1..03b80cc0cc 100644 --- a/setup.cfg +++ b/setup.cfg @@ -16,7 +16,6 @@ addopts = --cov-report=term --cov-report=xml:test-reports/coverage.xml --cov-report=html:test-reports/coverage_html - --junit-xml=test-reports/report.xml --html=test-reports/report.html env = MPLBACKEND = Agg diff --git a/tests/integration/cmor/_fixes/cmip6/test_ipsl_cm6a_lr.py b/tests/integration/cmor/_fixes/cmip6/test_ipsl_cm6a_lr.py index 266ae2d9f3..82416a77c8 100644 --- a/tests/integration/cmor/_fixes/cmip6/test_ipsl_cm6a_lr.py +++ b/tests/integration/cmor/_fixes/cmip6/test_ipsl_cm6a_lr.py @@ -36,8 +36,8 @@ def test_fix_metadata_ocean_var(self): self.assertEqual(len(cubes), 1) cube = cubes[0] - self.assertEquals(cube.coord('latitude').var_name, 'lat') - self.assertEquals(cube.coord('longitude').var_name, 'lon') + self.assertEqual(cube.coord('latitude').var_name, 'lat') + self.assertEqual(cube.coord('longitude').var_name, 'lon') self.cube.coord('cell_area') def test_fix_data_other_var(self): diff --git a/tests/integration/preprocessor/_io/test_load.py b/tests/integration/preprocessor/_io/test_load.py index b178981a96..eb62c97541 100644 --- a/tests/integration/preprocessor/_io/test_load.py +++ b/tests/integration/preprocessor/_io/test_load.py @@ -79,4 +79,4 @@ def test_callback_fix_lat_units(self): self.assertTrue((cube.data == np.array([1, 2])).all()) self.assertTrue((cube.coord('latitude').points == np.array([1, 2])).all()) - self.assertEquals(cube.coord('latitude').units, 'degrees_north') + self.assertEqual(cube.coord('latitude').units, 'degrees_north') diff --git a/tests/unit/preprocessor/_derive/test_uajet.py b/tests/unit/preprocessor/_derive/test_uajet.py index fc4b53c0ff..64aba89619 100644 --- a/tests/unit/preprocessor/_derive/test_uajet.py +++ b/tests/unit/preprocessor/_derive/test_uajet.py @@ -3,12 +3,18 @@ import numpy as np import pytest -import esmvalcore.preprocessor._derive.uajet as uajet +from esmvalcore.preprocessor._derive import uajet TIME_COORD = iris.coords.DimCoord([1.0, 2.0, 3.0], standard_name='time') LEV_COORD = iris.coords.DimCoord([80000.0, 83000.0, 87000.0], standard_name='air_pressure') -LON_COORD = iris.coords.DimCoord([0.0, 90.0, 180.0, 240.0, 360.0], +LON_COORD = iris.coords.DimCoord([0.0, 90.0, 180.0, 270.0], + bounds=[ + [-45., 45.], + [45., 135.], + [135., 225.], + [225., 315.], + ], standard_name='longitude') diff --git a/tests/unit/preprocessor/_regrid/test__stock_cube.py b/tests/unit/preprocessor/_regrid/test__stock_cube.py index ccf88a58ef..2eb688d7b8 100644 --- a/tests/unit/preprocessor/_regrid/test__stock_cube.py +++ b/tests/unit/preprocessor/_regrid/test__stock_cube.py @@ -23,14 +23,14 @@ def _check(self, dx, dy, lat_off=True, lon_off=True): mid_dx, mid_dy = dx / 2, dy / 2 if lat_off and lon_off: expected_lat_points = np.linspace( - _LAT_MIN + mid_dy, _LAT_MAX - mid_dy, _LAT_RANGE / dy) + _LAT_MIN + mid_dy, _LAT_MAX - mid_dy, int(_LAT_RANGE / dy)) expected_lon_points = np.linspace( - _LON_MIN + mid_dx, _LON_MAX - mid_dx, _LON_RANGE / dx) + _LON_MIN + mid_dx, _LON_MAX - mid_dx, int(_LON_RANGE / dx)) else: expected_lat_points = np.linspace(_LAT_MIN, _LAT_MAX, - _LAT_RANGE / dy + 1) + int(_LAT_RANGE / dy) + 1) expected_lon_points = np.linspace(_LON_MIN, _LON_MAX - dx, - _LON_RANGE / dx) + int(_LON_RANGE / dx)) # Check the stock cube coordinates. self.assertEqual(self.mock_DimCoord.call_count, 2) diff --git a/tests/unit/preprocessor/_time/test_time.py b/tests/unit/preprocessor/_time/test_time.py index 510eeb84de..116b739a20 100644 --- a/tests/unit/preprocessor/_time/test_time.py +++ b/tests/unit/preprocessor/_time/test_time.py @@ -105,6 +105,8 @@ def test_extract_time_no_slice(self): def test_extract_time_one_time(self): """Test extract_time with one time step.""" cube = _create_sample_cube() + cube.coord('time').guess_bounds() + cube.remove_coord('month_number') cube = cube.collapsed('time', iris.analysis.MEAN) sliced = extract_time(cube, 1950, 1, 1, 1952, 12, 31) assert_array_equal(np.array([360.]), sliced.coord('time').points) diff --git a/tests/unit/preprocessor/_units/test_convert_units.py b/tests/unit/preprocessor/_units/test_convert_units.py index 404e64b5d0..38629a1eac 100644 --- a/tests/unit/preprocessor/_units/test_convert_units.py +++ b/tests/unit/preprocessor/_units/test_convert_units.py @@ -40,7 +40,7 @@ def test_convert_compatible_units(self): result = convert_units(self.arr, 'degC') expected_data = np.array([[-273.15, -272.15], [-271.15, -270.15]]) expected_units = cf_units.Unit('degC') - self.assertEquals(result.units, expected_units) + self.assertEqual(result.units, expected_units) self.assertArrayEqual(result.data, expected_data)