Skip to content

Commit 9be68a3

Browse files
committed
update code to use Sofa.convention_status
1 parent 9db8cf9 commit 9be68a3

File tree

2 files changed

+19
-26
lines changed

2 files changed

+19
-26
lines changed

sofar/sofa.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -807,26 +807,17 @@ def upgrade_convention(self, target=None, verify='auto'):
807807

808808
# check input ---------------------------------------------------------
809809
self._reset_convention()
810+
status = self.convention_status
810811

811812
# get deprecations and information about Sofa object
812-
_, _, deprecations, upgrade = self._verification_rules()
813+
_, _, _, upgrade = self._verification_rules()
813814
convention_current = self.GLOBAL_SOFAConventions
814815
version_current = self.GLOBAL_SOFAConventionsVersion
815816
sofa_version_current = self.GLOBAL_Version
816817

817-
# check if convention is deprecated -----------------------------------
818-
is_deprecated = False
819-
820-
if convention_current in deprecations["GLOBAL:SOFAConventions"]:
821-
is_deprecated = True
822-
elif convention_current in upgrade:
823-
for from_to in upgrade[convention_current]["from_to"]:
824-
if version_current in from_to[0]:
825-
is_deprecated = True
826-
break
827-
828818
# check for upgrades --------------------------------------------------
829-
if is_deprecated:
819+
if status == 'deprecated':
820+
830821
# check if upgrade is available for this convention
831822
if convention_current not in upgrade:
832823
print((f"Convention {convention_current} v{version_current} is"
@@ -1027,6 +1018,7 @@ def verify(self, issue_handling="raise", mode="write"):
10271018
# ---------------------------------------------------------------------
10281019
# 0. update the convention
10291020
self._reset_convention()
1021+
status = self.convention_status
10301022

10311023
# ---------------------------------------------------------------------
10321024
# 1. check if the mandatory attributes are contained
@@ -1437,8 +1429,7 @@ def verify(self, issue_handling="raise", mode="write"):
14371429
# ---------------------------------------------------------------------
14381430
# 8. check deprecations
14391431
# (so far there are only deprecations for the convention)
1440-
if self.GLOBAL_SOFAConventions in \
1441-
deprecations["GLOBAL:SOFAConventions"]:
1432+
if status == 'deprecated':
14421433
convention = self.GLOBAL_SOFAConventions
14431434
msg = ("Detected deprecations:\n"
14441435
f"- GLOBAL_SOFAConventions is "
@@ -1451,7 +1442,7 @@ def verify(self, issue_handling="raise", mode="write"):
14511442
warning_msg += msg
14521443

14531444
# warn if preliminary conventions versions are used
1454-
if float(self.GLOBAL_SOFAConventionsVersion) < 1.0:
1445+
if status == 'preliminary':
14551446
warning_msg += (
14561447
"\n\nDetected preliminary conventions version "
14571448
f"{self.GLOBAL_SOFAConventionsVersion}:\n - Upgrade data to "

tests/test_io.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import numpy as np
1313
import numpy.testing as npt
1414
from netCDF4 import Dataset
15-
from packaging.version import parse
1615

1716

1817
def test_read_write_sofa():
@@ -166,18 +165,21 @@ def test_roundtrip(mandatory):
166165
for name, version in names_versions:
167166
print(f"Testing: {name} {version}")
168167

169-
# writing deprecated and proposed conventions is not tested
170-
if name in deprecations["GLOBAL:SOFAConventions"] or \
171-
parse(version) < parse('1.0'):
172-
sofa = sf.Sofa(name, mandatory, version, verify=False)
173-
# non stable conventions are not verified
174-
if parse(version) >= parse('1.0'):
175-
with pytest.warns(UserWarning, match="deprecations"):
168+
# create Sofa object without verification. Verification will be done
169+
# when writing below.
170+
sofa = sf.Sofa(name, mandatory, version, verify=False)
171+
status = sofa.convention_status
172+
173+
if status == 'preliminary':
174+
# don't test anything for preliminary conventions
175+
return
176+
elif status == 'deprecated':
177+
# don't test writing deprecated conventions
178+
with pytest.warns(UserWarning, match="deprecations"):
176179
sofa.verify(mode="read")
177-
else:
180+
elif status == 'current':
178181
# test full round-trip for other conventions
179182
file = os.path.join(temp_dir.name, name + ".sofa")
180-
sofa = sf.Sofa(name, mandatory, version)
181183
sf.write_sofa(file, sofa)
182184
sofa_r = sf.read_sofa(file)
183185
identical = sf.equals(sofa, sofa_r, verbose=True, exclude="DATE")

0 commit comments

Comments
 (0)