|
1 | 1 | import datetime |
2 | 2 | import faulthandler |
| 3 | +from importlib.util import find_spec |
3 | 4 | import unittest |
4 | 5 |
|
5 | 6 | faulthandler.enable() # to debug seg faults and timeouts |
6 | 7 |
|
7 | 8 | import cf |
8 | 9 |
|
9 | 10 |
|
| 11 | +# ESMF renamed its Python module to `esmpy` at ESMF version 8.4.0. Allow |
| 12 | +# either for now for backwards compatibility. |
| 13 | +esmpy_imported = False |
| 14 | +# Note: here only need esmpy for cf under-the-hood code, not in test |
| 15 | +# directly, so no need to actually import esmpy, just test it is there. |
| 16 | +if find_spec("esmpy") or find_spec("ESMF"): |
| 17 | + esmpy_imported = True |
| 18 | + |
| 19 | + |
10 | 20 | class RegridOperatorTest(unittest.TestCase): |
11 | | - src = cf.example_field(0) |
12 | | - dst = cf.example_field(1) |
13 | | - r = src.regrids(dst, "linear", return_operator=True) |
14 | 21 |
|
| 22 | + def setUp(self): |
| 23 | + src = cf.example_field(0) |
| 24 | + dst = cf.example_field(1) |
| 25 | + self.r = src.regrids(dst, "linear", return_operator=True) |
| 26 | + |
| 27 | + @unittest.skipUnless(esmpy_imported, "Requires esmpy/ESMF package.") |
15 | 28 | def test_RegridOperator_attributes(self): |
16 | 29 | self.assertEqual(self.r.coord_sys, "spherical") |
17 | 30 | self.assertEqual(self.r.method, "linear") |
@@ -39,6 +52,7 @@ def test_RegridOperator_attributes(self): |
39 | 52 | self.assertIsNone(self.r.dst_z) |
40 | 53 | self.assertFalse(self.r.ln_z) |
41 | 54 |
|
| 55 | + @unittest.skipUnless(esmpy_imported, "Requires esmpy/ESMF package.") |
42 | 56 | def test_RegridOperator_copy(self): |
43 | 57 | self.assertIsInstance(self.r.copy(), self.r.__class__) |
44 | 58 |
|
|
0 commit comments