Skip to content

Commit 474c448

Browse files
authored
fix(api): lowercase filename before checking extension in ProtocolReader (#9609)
1 parent d6a333e commit 474c448

File tree

6 files changed

+34
-5
lines changed

6 files changed

+34
-5
lines changed

api/src/opentrons/protocol_reader/config_analyzer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def analyze(main_file: RoleAnalysisFile) -> ConfigAnalysis:
4141

4242
# todo(mm, 2021-09-13): Deduplicate with opentrons.protocols.parse.
4343
def _analyze_python(main_file: RoleAnalysisFile) -> ConfigAnalysis: # noqa: C901
44-
assert main_file.name.endswith(".py"), "Expected main_file to be Python"
44+
assert main_file.name.lower().endswith(".py"), "Expected main_file to be Python"
4545

4646
try:
4747
# todo(mm, 2021-09-13): Investigate whether it's really appropriate to leave

api/src/opentrons/protocol_reader/file_reader_writer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ async def _read_file(input_file: AbstractInputFile, index: int) -> None:
4747
contents = await f.read()
4848
data: Optional[BufferedJsonFileData] = None
4949

50-
if input_file.filename.endswith(".json"):
50+
if input_file.filename.lower().endswith(".json"):
5151
try:
5252
data = parse_raw_as(BufferedJsonFileData, contents) # type: ignore[arg-type] # noqa: E501
5353

api/src/opentrons/protocol_reader/role_analyzer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def analyze(files: Sequence[BufferedFile]) -> RoleAnalysis:
5858
labware_files = []
5959

6060
for f in files:
61-
if f.name.endswith(".py") or isinstance(f.data, JsonProtocol):
61+
if f.name.lower().endswith(".py") or isinstance(f.data, JsonProtocol):
6262
data = f.data if isinstance(f.data, JsonProtocol) else None
6363
main_file_candidates.append(
6464
MainFile(name=f.name, contents=f.contents, data=data)

api/tests/opentrons/protocol_reader/test_config_analyzer.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,25 @@ class ConfigAnalyzerErrorSpec(NamedTuple):
117117
config=JsonProtocolConfig(schema_version=3),
118118
),
119119
),
120+
ConfigAnalyzerSpec(
121+
main_file=RoleAnalysisFile(
122+
name="protocol.PY",
123+
data=None,
124+
role=ProtocolFileRole.MAIN,
125+
contents=textwrap.dedent(
126+
"""
127+
metadata = {
128+
"author": "Dr. Sy. N. Tist",
129+
"apiLevel": "123.456",
130+
}
131+
"""
132+
).encode(),
133+
),
134+
expected=ConfigAnalysis(
135+
metadata={"author": "Dr. Sy. N. Tist", "apiLevel": "123.456"},
136+
config=PythonProtocolConfig(api_version=APIVersion(123, 456)),
137+
),
138+
),
120139
]
121140

122141

api/tests/opentrons/protocol_reader/test_file_reader_writer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ async def test_read() -> None:
3535
async def test_read_opentrons_json() -> None:
3636
"""It should read and parse Opentrons JSON protocol/labware file-likes."""
3737
file_1 = InputFile(filename="hello.json", file=io.BytesIO(SIMPLE_V5_JSON_PROTOCOL))
38-
file_2 = InputFile(filename="world.json", file=io.BytesIO(SIMPLE_LABWARE_DEF))
38+
file_2 = InputFile(filename="world.JSON", file=io.BytesIO(SIMPLE_LABWARE_DEF))
3939

4040
subject = FileReaderWriter()
4141
result = await subject.read([file_1, file_2])
@@ -47,7 +47,7 @@ async def test_read_opentrons_json() -> None:
4747
data=matchers.Anything(),
4848
),
4949
BufferedFile(
50-
name="world.json",
50+
name="world.JSON",
5151
contents=SIMPLE_LABWARE_DEF,
5252
data=matchers.Anything(),
5353
),

api/tests/opentrons/protocol_reader/test_role_analyzer.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,16 @@ class RoleAnalyzerErrorSpec(NamedTuple):
122122
],
123123
),
124124
),
125+
RoleAnalyzerSpec(
126+
files=[
127+
BufferedFile(name="PROTOCOL.PY", contents=b"", data=None),
128+
],
129+
expected=RoleAnalysis(
130+
main_file=MainFile(name="PROTOCOL.PY", contents=b""),
131+
labware_files=[],
132+
labware_definitions=[],
133+
),
134+
),
125135
]
126136

127137

0 commit comments

Comments
 (0)