Skip to content

Commit

Permalink
_common.py: Accept unknown curve types (#520)
Browse files Browse the repository at this point in the history
  • Loading branch information
martingalvan-volue authored Oct 24, 2024
1 parent 6664b1e commit 4978a51
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/source/versions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ New features
Changes
~~~~~~~~~~~~~~~~~~

- TBA
- **Fixed:** Processing time series objects with unknown curve types. :issue:`519`

Install instructions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
3 changes: 1 addition & 2 deletions src/volue/mesh/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,9 @@ def _from_proto_guid(guid: Optional[type.resources_pb2.Guid]) -> Optional[uuid.U
return uuid.UUID(bytes_le=guid.bytes_le)


# We intentionally leave out Curve.UNKNOWN so that a KeyError will be raised if we receive such
# values.
CURVE_TYPES = bidict(
{
Timeseries.Curve.UNKNOWN: type.resources_pb2.Curve.UNKNOWN,
Timeseries.Curve.PIECEWISELINEAR: type.resources_pb2.Curve.PIECEWISELINEAR,
Timeseries.Curve.STAIRCASE: type.resources_pb2.Curve.STAIRCASE,
Timeseries.Curve.STAIRCASESTARTOFSTEP: type.resources_pb2.Curve.STAIRCASESTARTOFSTEP,
Expand Down
21 changes: 20 additions & 1 deletion src/volue/mesh/tests/test_timeseries_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ def ts_init_data(self):
return TestCreatePhysicalTimeseries.TSInitData()

@staticmethod
def _verify_timeseries(timeseries: TimeseriesResource, expected_ts_data):
def _verify_timeseries(
timeseries: TimeseriesResource, expected_ts_data: TimeseriesResource
):
# Newly created time series have "Resource" prepended to their paths, and the time series
# name appended to it.
expected_path = "Resource" + expected_ts_data.path + expected_ts_data.name
Expand Down Expand Up @@ -183,6 +185,23 @@ def test_create_physical_timeseries(self, session, ts_init_data):
# requires us to know the time series' key, which CreatePhysicalTimeseries cannot return
# since it's generated at the commit stage.

def test_create_timeseries_with_unknown_curve_type(self, session, ts_init_data):
"""Check that an unknown curve type still works."""
ts_data = ts_init_data
ts_data.curve_type = Timeseries.Curve.UNKNOWN

timeseries = session.create_physical_timeseries(
path=ts_data.path,
name=ts_data.name,
curve_type=ts_data.curve_type,
resolution=ts_data.resolution,
unit_of_measurement=ts_data.unit_of_measurement,
)

session.commit()

self._verify_timeseries(timeseries, ts_data)

@pytest.mark.asyncio
async def test_create_physical_timeseries_async(self, async_session, ts_init_data):
"""Check that we can create a new physical time series."""
Expand Down

0 comments on commit 4978a51

Please sign in to comment.