Skip to content

Commit

Permalink
add __str__ method to dss_type (#46)
Browse files Browse the repository at this point in the history
* add __str__ method to dss_type

other houskeeping

* cleanup

* oops
  • Loading branch information
ktarbet authored Aug 28, 2024
1 parent 7a8e6e8 commit f8a5381
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = hecdss
version = 0.1.15
version = 0.1.16
author = Hydrologic Engineering Center
author_email [email protected]
description = Python wrapper for the HEC-DSS file database C library.
Expand Down
6 changes: 3 additions & 3 deletions src/hecdss/cwms_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def pathname_to_cwms_tsid(path, dss_type="", duration="0", strict=False):
return tsid

@staticmethod
def cwms_ts_id_to_pathname(ts_id: str) -> str:
def cwms_ts_id_to_dss_path(ts_id: str) -> DssPath:
"""
convert cwms time-series id to a dss path
example input:
Expand Down Expand Up @@ -153,7 +153,7 @@ def _convert_dss_interval_to_cwms_interval(dss_interval: str):


@staticmethod
def dss_data_type_from_cwms_tsid(cwms_tsid):
def dss_data_type_from_cwms_tsid(cwms_tsid) -> str:
"""
takes an input id such as 'TULA.Flow.Inst.1Hour.0.Ccp-Rev'
and returns the DSS DataType 'INST-VAL' in this example
Expand All @@ -178,4 +178,4 @@ def dss_data_type_from_cwms_tsid(cwms_tsid):
dss_type = DssType.PER_MIN
else:
dss_type = ts_type # default: use cwms type
return dss_type
return str(dss_type)
2 changes: 2 additions & 0 deletions src/hecdss/dss_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ class DssType(Enum):
PER_MIN = "PER-MIN"
CONST = "CONST"

def __str__(self):
return self.value
18 changes: 18 additions & 0 deletions tests/test_dss_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import unittest
import os
import sys

sys.path.append(r'src')
sys.path.append(os.path.dirname(__file__))
from hecdss.dss_type import DssType


class TestBasics(unittest.TestCase):


def test_to_string(self):
""" This is testing the __str__ method in DssType """
t = DssType.PER_CUM
s = str(t)
assert s == "PER-CUM", f"actual:{s}, expected 'PER-CUM'"

2 changes: 1 addition & 1 deletion tests/test_dsspath.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_convert_cwms_tsid_to_dss_path(self):
for row in self.example_data:
tsid = row[0]
expected_pathname = row[1]
pathname = CwmsUtility.cwms_ts_id_to_pathname(tsid)
pathname = CwmsUtility.cwms_ts_id_to_dss_path(tsid)
expected_pathname_without_date = DssPath(str(expected_pathname)).path_without_date()
if expected_pathname_without_date != pathname:
print(f"error converting to path. expected '{expected_pathname_without_date}', actual: '{pathname}'")
Expand Down

0 comments on commit f8a5381

Please sign in to comment.