From c2561fd339b284c76ce99f0d41c45f18808a84d2 Mon Sep 17 00:00:00 2001 From: jbleon95 Date: Tue, 6 Aug 2024 15:06:16 -0400 Subject: [PATCH] test for parameter file reader --- .../parameters/test_parameter_file_reader.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 api/tests/opentrons/protocols/parameters/test_parameter_file_reader.py diff --git a/api/tests/opentrons/protocols/parameters/test_parameter_file_reader.py b/api/tests/opentrons/protocols/parameters/test_parameter_file_reader.py new file mode 100644 index 00000000000..b64734d93b5 --- /dev/null +++ b/api/tests/opentrons/protocols/parameters/test_parameter_file_reader.py @@ -0,0 +1,26 @@ +import pytest +from pathlib import Path +from tempfile import NamedTemporaryFile + +from opentrons.protocols.parameters.exceptions import RuntimeParameterRequired +from opentrons.protocols.parameters import parameter_file_reader as subject + + +def test_open_file_path() -> None: + """It should open a temporary file handler given a path.""" + with NamedTemporaryFile("r+") as file_to_open: + file_to_open.write("Hello World\n") + file_to_open.flush() + + result = subject.open_file_path(Path(file_to_open.name)) + + assert result.readable() + assert not result.writable() + assert result.read() == "Hello World\n" + result.close() + + +def test_open_file_path_raises() -> None: + """It should raise of no file path is provided.""" + with pytest.raises(RuntimeParameterRequired): + subject.open_file_path(None)