Skip to content

Commit

Permalink
Make usage of coordinates_to_dict more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
robinmatz committed Nov 5, 2023
1 parent 0f25bbc commit e20ba7c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
10 changes: 5 additions & 5 deletions Mainframe3270/keywords/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,19 @@ def get_current_position(self, mode: str = "As Tuple") -> Union[tuple, dict]:
| Get Cursor Position | As Dict | # Returns a position like {"xpos": 1, "ypos": 1} |
"""
result = self.mf.get_current_position()
ypos, xpos = self.mf.get_current_position()
if mode.lower() == "as dict":
return coordinates_to_dict(*result)
return coordinates_to_dict(ypos, xpos)
elif mode.lower() == "as tuple":
return result
return ypos, xpos
else:
logger.warn('"mode" should be either "as dict" or "as tuple". Returning the result as tuple')
return result
return ypos, xpos

@keyword("Move Cursor To")
def move_cursor_to(self, ypos: int, xpos: int):
"""Moves the cursor to the specified ypos/xpos position. The coordinates are 1 based.
This keyword raises an error if the specified values exceed the Mainframe screen dimension.
This keyword raises an error if the specified values exceed the Mainframe screen dimensions.
Example:
| Move Cursor To | 1 | 5 |
Expand Down
6 changes: 3 additions & 3 deletions Mainframe3270/keywords/read_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def read(self, ypos: int, xpos: int, length: int) -> str:
def read_from_current_position(self, length: int):
"""Similar to `Read`, however this keyword only takes `length` as an argument
to get a string of length from the current cursor position."""
position = self.library.get_current_position()
return self.mf.string_get(position[0], position[1], length)
ypos, xpos = self.library.get_current_position()
return self.mf.string_get(ypos, xpos, length)

@keyword("Read All Screen")
def read_all_screen(self) -> str:
Expand Down Expand Up @@ -60,7 +60,7 @@ def get_string_positions(self, string: str, mode: str = "As Tuple", ignore_case:
"""
results = self.mf.get_string_positions(string, ignore_case)
if mode.lower() == "as dict":
return [coordinates_to_dict(*result) for result in results]
return [coordinates_to_dict(ypos, xpos) for ypos, xpos in results]
elif mode.lower() == "as tuple":
return results
else:
Expand Down
3 changes: 0 additions & 3 deletions atest/HelperLibrary.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ def emulator_model_should_be(self, model):
error_message = f'Emulator model should have been "{model}", but was "{self.library.mf.model}"'
self.built_in.should_be_equal_as_strings(model, self.library.mf.model, error_message, False)

def move_cursor_to(self, ypos, xpos):
self.library.mf.move_to(int(ypos), int(xpos))

def _end_keyword(self, name, attributes):
if attributes["kwname"] in [
"Open Connection",
Expand Down
10 changes: 5 additions & 5 deletions atest/mainframe.robot
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ Test Page Should Not Contain String
Page Should Not Contain String ${WELCOME_WRONG_CASE}
Page Should Not Contain String ${STRING_NON_EXISTENT} ignore_case=${True}

Test Move Cursor To
Move Cursor To 5 5
${position} Get Current Position
Should Be Equal ${{ (5, 5) }} ${position}

Test Read
${read_text} Read 1 10 48
Should Be Equal As Strings ${WELCOME_TITLE} ${read_text}
Expand Down Expand Up @@ -272,11 +277,6 @@ Test Get String Positions Without Result
${position} Get String Positions ${STRING_NON_EXISTENT} As Dict
Should Be Equal ${{ [] }} ${position}

Test Move Cursor To
Move Cursor To 5 5
${position} Get Cursor Position
Should Be Equal ${{ (5, 5) }} ${position}


*** Keywords ***
Suite Setup
Expand Down

0 comments on commit e20ba7c

Please sign in to comment.