From 1b2f425a36b41039f074ad08a393c9bc20be8098 Mon Sep 17 00:00:00 2001 From: Robin Matz Date: Sat, 11 Nov 2023 21:48:27 +0100 Subject: [PATCH] Rename SearchResultMode to ResultMode --- Mainframe3270/keywords/commands.py | 4 ++-- Mainframe3270/keywords/read_write.py | 10 ++++------ Mainframe3270/utils.py | 12 ++++++------ utest/Mainframe3270/keywords/test_commands.py | 7 +++---- utest/Mainframe3270/keywords/test_read_write.py | 13 +++++-------- utest/Mainframe3270/test_utils.py | 13 ++++++------- 6 files changed, 26 insertions(+), 33 deletions(-) diff --git a/Mainframe3270/keywords/commands.py b/Mainframe3270/keywords/commands.py index eb88f94..f31c57e 100644 --- a/Mainframe3270/keywords/commands.py +++ b/Mainframe3270/keywords/commands.py @@ -4,7 +4,7 @@ from robot.api.deco import keyword from Mainframe3270.librarycomponent import LibraryComponent -from Mainframe3270.utils import SearchResultMode, prepare_position_as +from Mainframe3270.utils import ResultMode, prepare_position_as class CommandKeywords(LibraryComponent): @@ -85,7 +85,7 @@ def send_pf(self, pf: str) -> None: time.sleep(self.wait_time) @keyword("Get Current Position") - def get_current_position(self, mode: SearchResultMode = SearchResultMode.As_Tuple) -> Union[tuple, dict]: + def get_current_position(self, mode: ResultMode = ResultMode.As_Tuple) -> Union[tuple, dict]: """Returns the current cursor position. The coordinates are 1 based. By default, this keyword returns a tuple of integers. However, if you specify the `mode` with the value diff --git a/Mainframe3270/keywords/read_write.py b/Mainframe3270/keywords/read_write.py index f0112ec..0d73707 100644 --- a/Mainframe3270/keywords/read_write.py +++ b/Mainframe3270/keywords/read_write.py @@ -4,7 +4,7 @@ from robot.api.deco import keyword from Mainframe3270.librarycomponent import LibraryComponent -from Mainframe3270.utils import SearchResultMode, prepare_positions_as +from Mainframe3270.utils import ResultMode, prepare_positions_as class ReadWriteKeywords(LibraryComponent): @@ -44,9 +44,7 @@ def read_all_screen(self) -> str: return self.mf.read_all_screen() @keyword("Get String Positions") - def get_string_positions( - self, string: str, mode: SearchResultMode = SearchResultMode.As_Tuple, ignore_case: bool = False - ): + def get_string_positions(self, string: str, mode: ResultMode = ResultMode.As_Tuple, ignore_case: bool = False): """Returns a list of tuples of ypos and xpos for the position where the `string` was found, or an empty list if it was not found. @@ -68,7 +66,7 @@ def get_string_positions_only_after( ypos: int, xpos: int, string: str, - mode: SearchResultMode = SearchResultMode.As_Tuple, + mode: ResultMode = ResultMode.As_Tuple, ignore_case: bool = False, ): """Returns a list of tuples of ypos and xpos for the position where the `string` was found, @@ -94,7 +92,7 @@ def get_string_positions_only_before( ypos: int, xpos: int, string: str, - mode: SearchResultMode = SearchResultMode.As_Tuple, + mode: ResultMode = ResultMode.As_Tuple, ignore_case: bool = False, ): """Returns a list of tuples of ypos and xpos for the position where the `string` was found, diff --git a/Mainframe3270/utils.py b/Mainframe3270/utils.py index 80f222c..a4e7005 100644 --- a/Mainframe3270/utils.py +++ b/Mainframe3270/utils.py @@ -6,23 +6,23 @@ from robot.utils import timestr_to_secs -class SearchResultMode(Enum): +class ResultMode(Enum): As_Tuple = auto() As_Dict = auto() -def prepare_position_as(position: Tuple[int, int], mode: SearchResultMode): +def prepare_position_as(position: Tuple[int, int], mode: ResultMode): return prepare_positions_as([position], mode)[0] -def prepare_positions_as(positions: List[Tuple[int, int]], mode: SearchResultMode): - if mode == SearchResultMode.As_Dict: +def prepare_positions_as(positions: List[Tuple[int, int]], mode: ResultMode): + if mode == ResultMode.As_Dict: return [coordinates_to_dict(ypos, xpos) for ypos, xpos in positions] - elif mode == SearchResultMode.As_Tuple: + elif mode == ResultMode.As_Tuple: return positions else: logger.warn( - f'"mode" should be either "{SearchResultMode.As_Dict}" or "{SearchResultMode.As_Tuple}". ' + f'"mode" should be either "{ResultMode.As_Dict}" or "{ResultMode.As_Tuple}". ' "Returning the result as tuple" ) return positions diff --git a/utest/Mainframe3270/keywords/test_commands.py b/utest/Mainframe3270/keywords/test_commands.py index 9afb652..2d69a6f 100644 --- a/utest/Mainframe3270/keywords/test_commands.py +++ b/utest/Mainframe3270/keywords/test_commands.py @@ -6,7 +6,7 @@ from Mainframe3270.keywords import CommandKeywords from Mainframe3270.py3270 import Emulator -from Mainframe3270.utils import SearchResultMode +from Mainframe3270.utils import ResultMode from .utils import create_test_object_for @@ -108,7 +108,7 @@ def test_get_current_position(mocker: MockerFixture, under_test: CommandKeywords def test_get_current_position_as_dict(mocker: MockerFixture, under_test: CommandKeywords): mocker.patch("Mainframe3270.py3270.Emulator.get_current_position", return_value=(6, 6)) - assert under_test.get_current_position(SearchResultMode.As_Dict) == {"xpos": 6, "ypos": 6} + assert under_test.get_current_position(ResultMode.As_Dict) == {"xpos": 6, "ypos": 6} def test_get_current_position_invalid_mode(mocker: MockerFixture, under_test: CommandKeywords): @@ -118,8 +118,7 @@ def test_get_current_position_invalid_mode(mocker: MockerFixture, under_test: Co assert under_test.get_current_position("this is wrong") == (6, 6) logger.warn.assert_called_with( - '"mode" should be either "SearchResultMode.As_Dict" or "SearchResultMode.As_Tuple". ' - "Returning the result as tuple" + '"mode" should be either "ResultMode.As_Dict" or "ResultMode.As_Tuple". ' "Returning the result as tuple" ) diff --git a/utest/Mainframe3270/keywords/test_read_write.py b/utest/Mainframe3270/keywords/test_read_write.py index 5adda7a..7135aff 100644 --- a/utest/Mainframe3270/keywords/test_read_write.py +++ b/utest/Mainframe3270/keywords/test_read_write.py @@ -2,7 +2,7 @@ from pytest_mock import MockerFixture from robot.api import logger -from Mainframe3270.keywords.read_write import ReadWriteKeywords, SearchResultMode +from Mainframe3270.keywords.read_write import ReadWriteKeywords, ResultMode from Mainframe3270.py3270 import Emulator from .utils import create_test_object_for @@ -86,7 +86,7 @@ def test_get_string_positions(mocker: MockerFixture, under_test: ReadWriteKeywor def test_get_string_positions_as_dict(mocker: MockerFixture, under_test: ReadWriteKeywords): mocker.patch("Mainframe3270.py3270.Emulator.get_string_positions", return_value=[(5, 10), (6, 11)]) - assert under_test.get_string_positions("abc", SearchResultMode.As_Dict) == [ + assert under_test.get_string_positions("abc", ResultMode.As_Dict) == [ {"ypos": 5, "xpos": 10}, {"ypos": 6, "xpos": 11}, ] @@ -101,8 +101,7 @@ def test_get_string_positions_invalid_mode(mocker: MockerFixture, under_test: Re assert under_test.get_string_positions("abc", "this is wrong") == [(5, 10)] logger.warn.assert_called_with( - '"mode" should be either "SearchResultMode.As_Dict" or "SearchResultMode.As_Tuple". ' - "Returning the result as tuple" + '"mode" should be either "ResultMode.As_Dict" or "ResultMode.As_Tuple". ' "Returning the result as tuple" ) Emulator.get_string_positions.assert_called_once_with("abc", False) @@ -129,9 +128,7 @@ def test_get_string_positions_only_after_as_dict(mocker: MockerFixture, under_te mocker.patch("Mainframe3270.py3270.Emulator.check_limits") mocker.patch("Mainframe3270.py3270.Emulator.get_string_positions", return_value=[(1, 1), (5, 7)]) - assert under_test.get_string_positions_only_after(5, 6, "my string", SearchResultMode.As_Dict) == [ - {"xpos": 7, "ypos": 5} - ] + assert under_test.get_string_positions_only_after(5, 6, "my string", ResultMode.As_Dict) == [{"xpos": 7, "ypos": 5}] Emulator.check_limits.assert_called_with(5, 6) Emulator.get_string_positions.assert_called_with("my string", False) @@ -161,7 +158,7 @@ def test_get_string_positions_only_before_as_dict(mocker: MockerFixture, under_t mocker.patch("Mainframe3270.py3270.Emulator.check_limits") mocker.patch("Mainframe3270.py3270.Emulator.get_string_positions", return_value=[(1, 1), (5, 7)]) - assert under_test.get_string_positions_only_before(5, 7, "my string", SearchResultMode.As_Dict) == [ + assert under_test.get_string_positions_only_before(5, 7, "my string", ResultMode.As_Dict) == [ {"xpos": 1, "ypos": 1} ] diff --git a/utest/Mainframe3270/test_utils.py b/utest/Mainframe3270/test_utils.py index 0b6d96c..5fd7cb2 100644 --- a/utest/Mainframe3270/test_utils.py +++ b/utest/Mainframe3270/test_utils.py @@ -4,7 +4,7 @@ from robot.api import logger from Mainframe3270.utils import ( - SearchResultMode, + ResultMode, convert_timeout, coordinates_to_dict, prepare_position_as, @@ -24,19 +24,19 @@ def test_convert_timeout_with_timestring(): def test_prepare_position_as(): - assert prepare_position_as((5, 5), SearchResultMode.As_Tuple) == (5, 5) + assert prepare_position_as((5, 5), ResultMode.As_Tuple) == (5, 5) def test_prepare_position_as_dict(): - assert prepare_position_as((5, 6), SearchResultMode.As_Dict) == {"ypos": 5, "xpos": 6} + assert prepare_position_as((5, 6), ResultMode.As_Dict) == {"ypos": 5, "xpos": 6} def test_prepare_positions_as(): - assert prepare_positions_as([(5, 5)], SearchResultMode.As_Tuple) == [(5, 5)] + assert prepare_positions_as([(5, 5)], ResultMode.As_Tuple) == [(5, 5)] def test_prepare_positions_as_dict(): - assert prepare_positions_as([(5, 6)], SearchResultMode.As_Dict) == [{"ypos": 5, "xpos": 6}] + assert prepare_positions_as([(5, 6)], ResultMode.As_Dict) == [{"ypos": 5, "xpos": 6}] def test_prepare_positions_as_invalid_mode(mocker: MockerFixture): @@ -45,8 +45,7 @@ def test_prepare_positions_as_invalid_mode(mocker: MockerFixture): assert prepare_positions_as([(5, 10)], "abc") == [(5, 10)] logger.warn.assert_called_with( - '"mode" should be either "SearchResultMode.As_Dict" or "SearchResultMode.As_Tuple". ' - "Returning the result as tuple" + '"mode" should be either "ResultMode.As_Dict" or "ResultMode.As_Tuple". ' "Returning the result as tuple" )