Skip to content

Commit

Permalink
modifications for new gimli, standard-names
Browse files Browse the repository at this point in the history
  • Loading branch information
mcflugen committed Mar 3, 2024
1 parent 4448d91 commit 813328c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
7 changes: 4 additions & 3 deletions src/bmi_tester/_tests/stage_1/info_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import warnings

import pytest
import standard_names
from standard_names.standardname import StandardName
from standard_names.standardname import is_valid_name


def test_get_component_name(initialized_bmi):
Expand All @@ -15,8 +16,8 @@ def test_get_component_name(initialized_bmi):
def test_var_names(var_name):
"""Test var names are valid."""
assert isinstance(var_name, str)
if standard_names.is_valid_name(var_name):
standard_names.StandardName(var_name)
if is_valid_name(var_name):
StandardName(var_name)
else:
warnings.warn(f"not a valid standard name: {var_name}", stacklevel=2)

Expand Down
17 changes: 10 additions & 7 deletions src/bmi_tester/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
from collections.abc import Sequence

try:
import gimli
from gimli._udunits2 import UdunitsError
from gimli.errors import IncompatibleUnitsError
from gimli.errors import UnitNameError
from gimli.units import units
except ImportError:
WITH_GIMLI_UNITS = False
SECONDS = None
else:
WITH_GIMLI_UNITS = True
SECONDS = gimli.units.Unit("s")
SECONDS = units.Unit("s")

import pytest

Expand Down Expand Up @@ -57,21 +60,21 @@ def check_bmi(

def check_unit_is_valid(unit):
try:
gimli.units.Unit(unit)
except gimli.UnitNameError:
units.Unit(unit)
except (UnitNameError, UdunitsError):
return False
else:
return True


def check_unit_is_time(unit):
try:
gimli.units.Unit(unit).to(SECONDS)
except gimli.IncompatibleUnitsError:
units.Unit(unit).to(SECONDS)
except (IncompatibleUnitsError, UdunitsError):
return False
else:
return True


def check_unit_is_dimensionless(unit):
return gimli.units.Unit(unit).is_dimensionless
return units.Unit(unit).is_dimensionless

0 comments on commit 813328c

Please sign in to comment.