Skip to content

Commit

Permalink
revert csv file type to be nested type, add file name to it
Browse files Browse the repository at this point in the history
  • Loading branch information
sanni-t committed Jul 18, 2024
1 parent da2132c commit cf5d62e
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 26 deletions.
5 changes: 3 additions & 2 deletions api/src/opentrons/protocol_api/_parameter_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
RunTimeParameter,
PrimitiveRunTimeParamValuesType,
CsvRunTimeParamFilesType,
FileInfo,
)

from ._parameters import Parameters
Expand Down Expand Up @@ -240,8 +241,8 @@ def initialize_csv_files(
f" but '{variable_name}' is not a CSV parameter."
)

parameter.id = file_id
# TODO (spp, 2024-07-16): assign the file as parameter.value
parameter.file_info = FileInfo(id=file_id, name="")
# TODO (spp, 2024-07-16): set the file name and assign the file as parameter.value.
# Most likely, we will be creating a temporary file copy of the original
# to pass onto the protocol context

Expand Down
12 changes: 11 additions & 1 deletion api/src/opentrons/protocol_engine/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1039,13 +1039,23 @@ class EnumParameter(RTPBase):
)


class FileInfo(BaseModel):
"""A file UUID descriptor."""

id: str = Field(
...,
description="The UUID identifier of the file stored on the robot.",
)
name: str = Field(..., description="Name of the file, including the extension.")


class CSVParameter(RTPBase):
"""A CSV file parameter defined in a protocol."""

type: Literal["csv_file"] = Field(
default="csv_file", description="String specifying the type of this parameter"
)
fileId: Optional[str] = Field(
file: Optional[FileInfo] = Field(
default=None,
description="ID of the CSV file stored on the robot; to be used for fetching the CSV file."
" For local analysis this will most likely be empty.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from opentrons.protocol_engine.types import (
RunTimeParameter,
CSVParameter as ProtocolEngineCSVParameter,
FileInfo,
)

from . import validation
Expand All @@ -28,7 +29,7 @@ def __init__(
self._variable_name = validation.ensure_variable_name(variable_name)
self._description = validation.ensure_description(description)
self._value: Optional[TextIO] = None
self._id: Optional[str] = None
self._file_info: Optional[FileInfo] = None

@property
def variable_name(self) -> str:
Expand All @@ -45,12 +46,12 @@ def value(self, new_file: TextIO) -> None:
self._value = new_file

@property
def id(self) -> Optional[str]:
return self._id
def file_info(self) -> Optional[FileInfo]:
return self._file_info

@id.setter
def id(self, uuid: str) -> None:
self._id = uuid
@file_info.setter
def file_info(self, file_info: FileInfo) -> None:
self._file_info = file_info

def as_csv_parameter_interface(self) -> CSVParameter:
return CSVParameter(csv_file=self._value)
Expand All @@ -61,7 +62,7 @@ def as_protocol_engine_type(self) -> RunTimeParameter:
displayName=self._display_name,
variableName=self._variable_name,
description=self._description,
fileId=self._id,
file=self._file_info,
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pytest
from decoy import Decoy

from opentrons.protocol_engine.types import CSVParameter
from opentrons.protocol_engine.types import CSVParameter, FileInfo
from opentrons.protocols.parameters import validation as mock_validation
from opentrons.protocols.parameters.csv_parameter_definition import (
create_csv_parameter,
Expand Down Expand Up @@ -49,7 +49,7 @@ def test_create_csv_parameter(decoy: Decoy) -> None:
assert result.variable_name == "my_cool_csv"
assert result._description == "Comma Separated Value"
assert result.value is None
assert result.id is None
assert result.file_info is None


def test_set_csv_value(
Expand All @@ -72,16 +72,16 @@ def test_csv_parameter_as_protocol_engine_type(
displayName="My cool CSV",
variableName="my_cool_csv",
description="Comma Separated Value",
fileId=None,
file=None,
)

csv_parameter_subject.id = "123abc"
csv_parameter_subject.file_info = FileInfo(id="123abc", name="")
result = csv_parameter_subject.as_protocol_engine_type()
assert result == CSVParameter(
displayName="My cool CSV",
variableName="my_cool_csv",
description="Comma Separated Value",
fileId="123abc",
file=FileInfo(id="123abc", name=""),
)


Expand Down
5 changes: 3 additions & 2 deletions robot-server/robot_server/protocols/analysis_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def _extract_csv_run_time_params(
CsvParameterResource(
analysis_id=completed_analysis.id,
parameter_variable_name=param.variableName,
file_id=param.fileId,
file_id=param.file.id if param.file else None,
)
for param in csv_rtp_list
if isinstance(param, CSVParameter)
Expand Down Expand Up @@ -402,7 +402,8 @@ async def matching_rtp_values_in_analysis(
), "Mismatch in parameters found in the current request vs. last saved parameters." # Indicates internal bug
for param in new_parameters:
if isinstance(param, CSVParameter):
if csv_rtps_in_last_analysis[param.variableName] != param.fileId:
new_file_id = param.file.id if param.file else None
if csv_rtps_in_last_analysis[param.variableName] != new_file_id:
return False
elif primitive_rtps_in_last_analysis[param.variableName] != param.value:
return False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,6 @@ stages:
- displayName: Liquid handling CSV file
variableName: liq_handling_csv_file
description: A CSV file that contains wells to use for pipetting
fileId: '{csv_file_id}'
file:
- id: '{csv_file_id}'
name: ''
21 changes: 15 additions & 6 deletions robot-server/tests/protocols/test_analysis_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
EnumChoice,
BooleanParameter,
CSVParameter,
FileInfo,
)

from sqlalchemy.engine import Engine as SQLEngine
Expand Down Expand Up @@ -112,12 +113,12 @@ def mock_number_param(name: str, value: float) -> NumberParameter:
)


def mock_csv_param(name: str, file_id: Optional[str]) -> CSVParameter:
def mock_csv_param(name: str, file: Optional[FileInfo]) -> CSVParameter:
"""Return a CSVParameter."""
return CSVParameter(
variableName=name,
displayName="csv param",
fileId=file_id,
file=file,
)


Expand Down Expand Up @@ -342,7 +343,9 @@ async def test_update_adds_rtp_values_to_completed_store(
default="blah",
)
csv_param = pe_types.CSVParameter(
displayName="A CSV param", variableName="coolest_param", fileId="file-id"
displayName="A CSV param",
variableName="coolest_param",
file=FileInfo(id="file-id", name="file-name"),
)
expected_completed_analysis_resource = CompletedAnalysisResource(
id="analysis-id",
Expand Down Expand Up @@ -545,7 +548,9 @@ async def test_save_initialization_failed_analysis(
mock_number_param("cool_param", 2.0),
mock_enum_param("cooler_param", "baz"),
mock_bool_param("uncool_param", True),
mock_csv_param("coolest_param", "file-id"),
mock_csv_param(
"coolest_param", FileInfo(id="file-id", name="file-name")
),
],
True,
),
Expand All @@ -554,7 +559,9 @@ async def test_save_initialization_failed_analysis(
mock_number_param("cool_param", 2),
mock_enum_param("cooler_param", "buzzzzz"),
mock_bool_param("uncool_param", False),
mock_csv_param("coolest_param", "file-id"),
mock_csv_param(
"coolest_param", FileInfo(id="file-id", name="file-name")
),
],
False,
),
Expand All @@ -563,7 +570,9 @@ async def test_save_initialization_failed_analysis(
# params in different order, cool param is '2' instead of '2.0'
mock_enum_param("cooler_param", "baz"),
mock_bool_param("uncool_param", True),
mock_csv_param("coolest_param", "file-id"),
mock_csv_param(
"coolest_param", FileInfo(id="file-id", name="file-name")
),
mock_number_param("cool_param", 2),
],
True,
Expand Down
5 changes: 4 additions & 1 deletion robot-server/tests/protocols/test_protocols_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
NumberParameter,
CSVParameter,
CsvRunTimeParamFilesType,
FileInfo,
)
from opentrons.protocols.api_support.types import APIVersion

Expand Down Expand Up @@ -1694,7 +1695,9 @@ async def test_update_protocol_analyses_with_new_rtp_values(
default=3.0,
)
csv_parameter = CSVParameter(
displayName="CSV parameter", variableName="csv_param", fileId="file-id"
displayName="CSV parameter",
variableName="csv_param",
file=FileInfo(id="file-id", name=""),
)
decoy.when(protocol_store.has(protocol_id="protocol-id")).then_return(True)
decoy.when(protocol_store.get(protocol_id="protocol-id")).then_return(
Expand Down
1 change: 0 additions & 1 deletion robot-server/tests/runs/test_run_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ def run_time_parameters() -> List[pe_types.RunTimeParameter]:
displayName="Display Name 4",
variableName="variable_name_4",
description="a csv parameter without file id",
fileId=None,
),
]

Expand Down

0 comments on commit cf5d62e

Please sign in to comment.