Skip to content
Merged
3 changes: 3 additions & 0 deletions cf/test/test_Field.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import atexit
import datetime
import faulthandler
from importlib.util import find_spec
import itertools
import os
import re
Expand Down Expand Up @@ -1152,6 +1153,8 @@ def test_Field_insert_dimension(self):
with self.assertRaises(ValueError):
f.insert_dimension(1, "qwerty")

@unittest.skipUnless(
find_spec("matplotlib"), "matplotlib required but not installed")
def test_Field_indices(self):
f = cf.read(self.filename)[0]

Expand Down
20 changes: 17 additions & 3 deletions cf/test/test_RegridOperator.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
import datetime
import faulthandler
from importlib.util import find_spec
import unittest

faulthandler.enable() # to debug seg faults and timeouts

import cf


# ESMF renamed its Python module to `esmpy` at ESMF version 8.4.0. Allow
# either for now for backwards compatibility.
esmpy_imported = False
# Note: here only need esmpy for cf under-the-hood code, not in test
# directly, so no need to actually import esmpy, just test it is there.
if find_spec("esmpy") or find_spec("ESMF"):
esmpy_imported = True


class RegridOperatorTest(unittest.TestCase):
src = cf.example_field(0)
dst = cf.example_field(1)
r = src.regrids(dst, "linear", return_operator=True)

def setUp(self):
src = cf.example_field(0)
dst = cf.example_field(1)
self.r = src.regrids(dst, "linear", return_operator=True)

@unittest.skipUnless(esmpy_imported, "Requires esmpy/ESMF package.")
def test_RegridOperator_attributes(self):
self.assertEqual(self.r.coord_sys, "spherical")
self.assertEqual(self.r.method, "linear")
Expand Down Expand Up @@ -39,6 +52,7 @@ def test_RegridOperator_attributes(self):
self.assertIsNone(self.r.dst_z)
self.assertFalse(self.r.ln_z)

@unittest.skipUnless(esmpy_imported, "Requires esmpy/ESMF package.")
def test_RegridOperator_copy(self):
self.assertIsInstance(self.r.copy(), self.r.__class__)

Expand Down
7 changes: 7 additions & 0 deletions cf/test/test_read_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import inspect
import os
import shutil
import shutil
import subprocess
import tempfile
import unittest
Expand Down Expand Up @@ -642,6 +643,8 @@ def test_read_write_unlimited(self):
self.assertTrue(domain_axes["domainaxis0"].nc_is_unlimited())
self.assertTrue(domain_axes["domainaxis2"].nc_is_unlimited())

@unittest.skipUnless(
shutil.which("ncdump"), "ncdump required - install nco")
def test_read_CDL(self):
subprocess.run(
" ".join(["ncdump", self.filename, ">", tmpfile]),
Expand Down Expand Up @@ -703,6 +706,8 @@ def test_read_CDL(self):
with self.assertRaises(Exception):
cf.read("test_read_write.py")

@unittest.skipUnless(
shutil.which("ncdump"), "ncdump required - install nco")
def test_read_cdl_string(self):
"""Test the cf.read 'cdl_string' keyword."""
f = cf.read("example_field_0.nc")[0]
Expand Down Expand Up @@ -876,6 +881,8 @@ def test_read_url(self):
f = cf.read(remote)
self.assertEqual(len(f), 1)

@unittest.skipUnless(
shutil.which("ncdump"), "ncdump required - install nco")
def test_read_dataset_type(self):
"""Test the cf.read 'dataset_type' keyword."""
# netCDF dataset
Expand Down
10 changes: 5 additions & 5 deletions cf/test/test_regrid_featureType.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@
atol = 2e-12
rtol = 0

meshloc = {
"face": esmpy.MeshLoc.ELEMENT,
"node": esmpy.MeshLoc.NODE,
}


def esmpy_regrid(coord_sys, method, src, dst, **kwargs):
"""Helper function that regrids one dimension of Field data using
Expand All @@ -53,6 +48,11 @@ def esmpy_regrid(coord_sys, method, src, dst, **kwargs):
Regridded numpy masked array.

"""
meshloc = {
"face": esmpy.MeshLoc.ELEMENT,
"node": esmpy.MeshLoc.NODE,
}

esmpy_regrid = cf.regrid.regrid(
coord_sys,
src,
Expand Down
10 changes: 5 additions & 5 deletions cf/test/test_regrid_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@
atol = 2e-12
rtol = 0

meshloc = {
"face": esmpy.MeshLoc.ELEMENT,
"node": esmpy.MeshLoc.NODE,
}


def esmpy_regrid(coord_sys, method, src, dst, **kwargs):
"""Helper function that regrids one dimension of Field data using
Expand All @@ -56,6 +51,11 @@ def esmpy_regrid(coord_sys, method, src, dst, **kwargs):
Regridded numpy masked array.

"""
meshloc = {
"face": esmpy.MeshLoc.ELEMENT,
"node": esmpy.MeshLoc.NODE,
}

esmpy_regrid = cf.regrid.regrid(
coord_sys,
src,
Expand Down
7 changes: 5 additions & 2 deletions cf/test/test_style.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import datetime
import faulthandler
from importlib.util import find_spec
import os
import unittest

import pycodestyle

faulthandler.enable() # to debug seg faults and timeouts

import cf
Expand All @@ -31,7 +30,11 @@ def setUp(self):
for path in non_cf_python_files
]

@unittest.skipUnless(
find_spec("pycodestyle"), "pycodestyle required but not installed")
def test_pep8_compliance(self):
import pycodestyle

pep8_check = pycodestyle.StyleGuide()

# Directories to skip in the recursive walk of the directory:
Expand Down