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
8 changes: 7 additions & 1 deletion lib/iris/coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

"""

from abc import ABCMeta
from abc import ABCMeta, abstractmethod
from collections import namedtuple
from collections.abc import Iterator
import copy
from functools import wraps
from itertools import chain, zip_longest
import operator
import warnings
Expand Down Expand Up @@ -1282,6 +1283,7 @@ class Coord(_DimensionalMetadata):

"""

@abstractmethod
def __init__(
self,
points,
Expand Down Expand Up @@ -2565,6 +2567,10 @@ class AuxCoord(Coord):

"""

@wraps(Coord.__init__, assigned=("__doc__",), updated=())
Copy link
Member

@bjlittle bjlittle Nov 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

# Logically, :class:`Coord` is an abstract class and all actual coords must
# be members of some concrete subclass, i.e. an :class:`AuxCoord` or
# a :class:`DimCoord`.
Expand Down
20 changes: 10 additions & 10 deletions lib/iris/tests/unit/coords/test_CellMethod.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import iris.tests as tests

from iris._cube_coord_common import CFVariableMixin
from iris.coords import CellMethod, Coord
from iris.coords import CellMethod, AuxCoord


class Test(tests.IrisTest):
Expand All @@ -27,38 +27,38 @@ def _check(self, token, coord, default=False):

def test_coord_standard_name(self):
token = "air_temperature"
coord = Coord(1, standard_name=token)
coord = AuxCoord(1, standard_name=token)
self._check(token, coord)

def test_coord_long_name(self):
token = "long_name"
coord = Coord(1, long_name=token)
coord = AuxCoord(1, long_name=token)
self._check(token, coord)

def test_coord_long_name_default(self):
token = "long name" # includes space
coord = Coord(1, long_name=token)
coord = AuxCoord(1, long_name=token)
self._check(token, coord, default=True)

def test_coord_var_name(self):
token = "var_name"
coord = Coord(1, var_name=token)
coord = AuxCoord(1, var_name=token)
self._check(token, coord)

def test_coord_var_name_fail(self):
token = "var name" # includes space
emsg = "is not a valid NetCDF variable name"
with self.assertRaisesRegex(ValueError, emsg):
Coord(1, var_name=token)
AuxCoord(1, var_name=token)

def test_coord_stash(self):
token = "stash"
coord = Coord(1, attributes=dict(STASH=token))
coord = AuxCoord(1, attributes=dict(STASH=token))
self._check(token, coord)

def test_coord_stash_default(self):
token = "_stash" # includes leading underscore
coord = Coord(1, attributes=dict(STASH=token))
coord = AuxCoord(1, attributes=dict(STASH=token))
self._check(token, coord, default=True)

def test_string(self):
Expand All @@ -75,14 +75,14 @@ def test_string_default(self):

def test_mixture(self):
token = "air_temperature"
coord = Coord(1, standard_name=token)
coord = AuxCoord(1, standard_name=token)
result = CellMethod(self.method, coords=[coord, token])
expected = "{}: {}, {}".format(self.method, token, token)
self.assertEqual(str(result), expected)

def test_mixture_default(self):
token = "air temperature" # includes space
coord = Coord(1, long_name=token)
coord = AuxCoord(1, long_name=token)
result = CellMethod(self.method, coords=[coord, token])
expected = "{}: unknown, unknown".format(self.method, token, token)
self.assertEqual(str(result), expected)
Expand Down
10 changes: 10 additions & 0 deletions lib/iris/tests/unit/coords/test_Coord.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,5 +1010,15 @@ def test_remove_bounds(self):
self.assertFalse(coord.climatological)


class Test_Coord_is_abstract(tests.IrisTest):
def test_instantiate_fail(self):
emsg = (
"Can't instantiate abstract class Coord with abstract"
" methods __init__"
)
with self.assertRaisesRegex(TypeError, emsg):
_ = Coord(points=[0, 1])


if __name__ == "__main__":
tests.main()