Skip to content

Commit

Permalink
Generalized error messages for not implmented
Browse files Browse the repository at this point in the history
  • Loading branch information
dalmijn committed Feb 19, 2024
1 parent baae919 commit b2978ab
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 24 deletions.
6 changes: 4 additions & 2 deletions src/fiat/gis/crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

from osgeo import osr

from fiat.util import DD_NOT_IMPLEMENTED


def get_srs_repr(
srs: osr.SpatialReference,
) -> str:
"""_summary_."""
if srs is None:
raise ValueError("SRS can not be None.")
raise ValueError("'srs' can not be 'None'.")
_auth_c = srs.GetAuthorityCode(None)
_auth_n = srs.GetAuthorityName(None)

Expand All @@ -31,7 +33,7 @@ def __del__(self):
pass

def __eq__(self, other):
pass
raise NotImplementedError(DD_NOT_IMPLEMENTED)

@classmethod
def from_user_input(
Expand Down
36 changes: 20 additions & 16 deletions src/fiat/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@

from fiat.error import DriverNotFoundError
from fiat.util import (
DD_NEED_IMPLEMENTED,
DD_NOT_IMPLEMENTED,
GEOM_DRIVER_MAP,
GRID_DRIVER_MAP,
NEED_IMPLEMENTED,
NOT_IMPLEMENTED,
DummyLock,
_dtypes_from_string,
_dtypes_reversed,
Expand Down Expand Up @@ -121,7 +125,7 @@ def closed(self):

@abstractmethod
def flush(self):
raise NotImplementedError("Method needs to be implemented.")
raise NotImplementedError(NEED_IMPLEMENTED)


class _BaseHandler(metaclass=ABCMeta):
Expand All @@ -144,7 +148,7 @@ def __del__(self):

@abstractmethod
def __repr__(self):
raise NotImplementedError("Dunder method needs to be implemented.")
raise NotImplementedError(DD_NEED_IMPLEMENTED)

def __enter__(self):
return super().__enter__()
Expand All @@ -163,7 +167,7 @@ def __init__(self):

@abstractmethod
def __del__(self):
raise NotImplementedError("Dunder method needs to be implemented.")
raise NotImplementedError(DD_NEED_IMPLEMENTED)

def __repr__(self):
_mem_loc = f"{id(self):#018x}".upper()
Expand Down Expand Up @@ -775,7 +779,7 @@ def _write(
data : array
_description_
"""
raise NotImplementedError("Method not yet implemented")
raise NotImplementedError(NOT_IMPLEMENTED)

@_BaseIO._check_mode
def write_chunk(
Expand Down Expand Up @@ -1139,7 +1143,7 @@ def copy_layer(

def _get_layer(self, l_id):
"""_summary_."""
raise NotImplementedError("Method not yet implemented.")
raise NotImplementedError(NOT_IMPLEMENTED)

@_BaseIO._check_state
def get_srs(self):
Expand Down Expand Up @@ -1581,7 +1585,7 @@ def _write_array(
band: int,
):
"""_summary_."""
raise NotImplementedError("Method not yet implemented.")
raise NotImplementedError(NOT_IMPLEMENTED)


class _Table(_BaseStruct, metaclass=ABCMeta):
Expand Down Expand Up @@ -1638,7 +1642,7 @@ def __len__(self):

@abstractmethod
def __getitem__(self, key):
raise NotImplementedError("Dunder method needs to be implemented.")
raise NotImplementedError(DD_NEED_IMPLEMENTED)

# @abstractmethod
# def __iter__(self):
Expand Down Expand Up @@ -1712,10 +1716,10 @@ def __init__(
)

def __iter__(self):
raise NotImplementedError("Dunder method needs to be implemented.")
raise NotImplementedError(DD_NOT_IMPLEMENTED)

def __next__(self):
raise NotImplementedError("Dunder method needs to be implemented.")
raise NotImplementedError(DD_NOT_IMPLEMENTED)

def __getitem__(self, keys):
"""_summary_."""
Expand All @@ -1733,7 +1737,7 @@ def __setitem__(self, key, value):
self.data[key] = value

def __eq__(self, other):
raise NotImplementedError("Dunder method needs to be implemented.")
raise NotImplementedError(DD_NOT_IMPLEMENTED)

def __str__(self):
if len(self.columns) > 6:
Expand Down Expand Up @@ -1791,7 +1795,7 @@ def _build_from_dict(
data: dict,
):
"""_summary_."""
raise NotImplementedError("Method not yet implemented.")
raise NotImplementedError(NOT_IMPLEMENTED)

def _build_from_list(
self,
Expand All @@ -1802,11 +1806,11 @@ def _build_from_list(

def mean(self):
"""_summary_."""
raise NotImplementedError("Method not yet implemented.")
raise NotImplementedError(NOT_IMPLEMENTED)

def max(self):
"""_summary_."""
raise NotImplementedError("Method not yet implemented.")
raise NotImplementedError(NOT_IMPLEMENTED)

def upscale(
self,
Expand Down Expand Up @@ -1915,10 +1919,10 @@ def __init__(
)

def __iter__(self):
raise NotImplementedError("Dunder method needs to be implemented.")
raise NotImplementedError(DD_NOT_IMPLEMENTED)

def __next__(self):
raise NotImplementedError("Dunder method needs to be implemented.")
raise NotImplementedError(DD_NOT_IMPLEMENTED)

def __getitem__(
self,
Expand All @@ -1935,7 +1939,7 @@ def __getitem__(
return self.data.readline().strip()

def _build_lazy(self):
raise NotImplementedError("Method not yet implemented.")
raise NotImplementedError(NOT_IMPLEMENTED)

def get(
self,
Expand Down
8 changes: 5 additions & 3 deletions src/fiat/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from string import Formatter as StrFormatter
from warnings import warn

from fiat.util import NOT_IMPLEMENTED

DEFAULT_FMT = "{asctime:20s}{levelname:8s}{message}"
DEFAULT_TIME_FMT = "%Y-%m-%d %H:%M:%S"
STREAM_COUNT = 1
Expand Down Expand Up @@ -236,11 +238,11 @@ def close(self):

def emit(self):
"""_summary_."""
NotImplementedError("Method not yet implemented.")
NotImplementedError(NOT_IMPLEMENTED)

def flush(self):
"""_summary_."""
NotImplementedError("Method not yet implemented.")
NotImplementedError(NOT_IMPLEMENTED)

def format(
self,
Expand Down Expand Up @@ -768,7 +770,7 @@ def level(

def _direct(self, msg):
"""_summary_."""
raise NotImplementedError("Method not yet implemented.")
raise NotImplementedError(NOT_IMPLEMENTED)

@handle_log
def debug(self, msg: str):
Expand Down
6 changes: 3 additions & 3 deletions src/fiat/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from fiat.io import open_csv, open_grid
from fiat.log import spawn_logger
from fiat.models.calc import calc_rp_coef
from fiat.util import deter_dec
from fiat.util import NEED_IMPLEMENTED, deter_dec

logger = spawn_logger("fiat.model")

Expand Down Expand Up @@ -229,11 +229,11 @@ def _set_num_threads(
self,
):
"""_summary_."""
raise NotImplementedError("Method needs to be implemented.")
raise NotImplementedError(NEED_IMPLEMENTED)

@abstractmethod
def run(
self,
):
"""_summary_."""
raise NotImplementedError("Method needs to be implemented.")
raise NotImplementedError(NEED_IMPLEMENTED)
4 changes: 4 additions & 0 deletions src/fiat/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@
from osgeo import gdal

BLACKLIST = type, ModuleType, FunctionType
DD_NEED_IMPLEMENTED = "Dunder method needs to be implemented."
DD_NOT_IMPLEMENTED = "Dunder method not yet implemented."
FILE_ATTRIBUTE_HIDDEN = 0x02
NEWLINE_CHAR = os.linesep
NEED_IMPLEMENTED = "Method needs to be implemented."
NOT_IMPLEMENTED = "Method not yet implemented."


_dtypes = {
Expand Down

0 comments on commit b2978ab

Please sign in to comment.