Skip to content

Commit

Permalink
style: improve code formatting and test readability
Browse files Browse the repository at this point in the history
- Add consistent trailing commas in function parameters
- Fix string quote style in test files (single -> double quotes)
- Improve readability of long function calls by breaking into multiple lines
- Format CLI argument definitions consistently
- Clean up whitespace in docstrings and function signatures

The changes focus on code style consistency across the codebase,
particularly in sierra_status/src and tests directories.
  • Loading branch information
elkanamol committed Nov 7, 2024
1 parent e4d9c01 commit d2009ab
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 25 deletions.
5 changes: 3 additions & 2 deletions sierra_status/src/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ def main() -> None:
type=int,
)
optional.add_argument(
"-i", "--interactive",
"-i",
"--interactive",
help="Enter interactive mode to send custom AT commands",
action="store_true"
action="store_true",
)

args = parser.parse_args()
Expand Down
12 changes: 6 additions & 6 deletions sierra_status/src/usb_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,12 @@ def handle_interactive_session(port: str, baudrate: int, model: str) -> None:


def start_process(
port: str,
model: str,
log_level: int,
search: int,
port: str,
model: str,
log_level: int,
search: int,
baudrate: int = DEFAULT_BAUDRATE,
interactive: bool = False
interactive: bool = False,
) -> None:
"""
Main function to retrieve the status of an EM9xxx module using AT commands.
Expand All @@ -197,7 +197,7 @@ def start_process(
model (str): The model of the module.
log_level (int): The logging level to use.
search (int): The search parameter to use.
baudrate (int, optional): The baud rate to use for the serial connection.
baudrate (int, optional): The baud rate to use for the serial connection.
interactive (bool, optional): Run in interactive mode if True.
returns:
None
Expand Down
52 changes: 35 additions & 17 deletions tests/test_usb_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,28 +287,30 @@ def setUp(self) -> None:
self.mock_baudrate = 115200
self.mock_model = "TestModel"

@patch('builtins.input')
@patch("builtins.input")
def test_get_interactive_command_valid(self, mock_input) -> None:
mock_input.return_value = "AT+TEST"
result = get_interactive_command()
self.assertEqual(result, "AT+TEST")

@patch('builtins.input')
@patch("builtins.input")
def test_get_interactive_command_exit(self, mock_input) -> None:
mock_input.return_value = "exit"
result = get_interactive_command()
self.assertEqual(result, "")

@patch('builtins.input')
@patch("builtins.input")
def test_get_interactive_command_invalid(self, mock_input) -> None:
mock_input.side_effect = ["INVALID", "AT+TEST"]
result = get_interactive_command()
self.assertEqual(result, "AT+TEST")

@patch('sierra_status.src.usb_handle.get_interactive_command')
@patch('sierra_status.src.usb_handle.send_at_command')
@patch('sierra_status.src.usb_handle.creat_status_file')
def test_handle_interactive_session(self, mock_create_file, mock_send, mock_get_command) -> None:
@patch("sierra_status.src.usb_handle.get_interactive_command")
@patch("sierra_status.src.usb_handle.send_at_command")
@patch("sierra_status.src.usb_handle.creat_status_file")
def test_handle_interactive_session(
self, mock_create_file, mock_send, mock_get_command
) -> None:
mock_get_command.side_effect = ["AT+TEST1", "AT+TEST2", ""]
mock_send.return_value = "OK"

Expand All @@ -319,22 +321,38 @@ def test_handle_interactive_session(self, mock_create_file, mock_send, mock_get_
self.assertIn("AT+TEST1", mock_create_file.call_args[0][0])
self.assertIn("AT+TEST2", mock_create_file.call_args[0][0])

@patch('sierra_status.src.usb_handle.handle_interactive_session')
@patch('sierra_status.src.usb_handle.get_module_status')
def test_start_process_interactive_mode(self, mock_get_status, mock_interactive) -> None:
start_process(self.mock_port, "TestModel", logging.INFO, 0,
self.mock_baudrate, interactive=True)
@patch("sierra_status.src.usb_handle.handle_interactive_session")
@patch("sierra_status.src.usb_handle.get_module_status")
def test_start_process_interactive_mode(
self, mock_get_status, mock_interactive
) -> None:
start_process(
self.mock_port,
"TestModel",
logging.INFO,
0,
self.mock_baudrate,
interactive=True,
)

mock_interactive.assert_called_once_with(
self.mock_port, self.mock_baudrate, "TestModel"
)
mock_get_status.assert_not_called()

@patch('sierra_status.src.usb_handle.handle_interactive_session')
@patch('sierra_status.src.usb_handle.get_module_status')
def test_start_process_standard_mode(self, mock_get_status, mock_interactive) -> None:
start_process(self.mock_port, "TestModel", logging.INFO, 0,
self.mock_baudrate, interactive=False)
@patch("sierra_status.src.usb_handle.handle_interactive_session")
@patch("sierra_status.src.usb_handle.get_module_status")
def test_start_process_standard_mode(
self, mock_get_status, mock_interactive
) -> None:
start_process(
self.mock_port,
"TestModel",
logging.INFO,
0,
self.mock_baudrate,
interactive=False,
)

mock_interactive.assert_not_called()
mock_get_status.assert_called_once()
Expand Down

0 comments on commit d2009ab

Please sign in to comment.