Skip to content

Commit 3861820

Browse files
committed
wip
1 parent 8a6e7bd commit 3861820

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

src/nrfcredstore/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ def main(args, credstore):
131131
credstore.command_interface.enable_error_codes()
132132
exec_cmd(args, credstore)
133133

134-
def run():
134+
def run(argv=sys.argv):
135135
logging.basicConfig(level='DEBUG')
136-
args = parse_args(sys.argv[1:])
136+
args = parse_args(argv[1:])
137137
comms = None
138138

139139
# use inquirer to find the device

src/nrfcredstore/command_interface.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ def detect_shell_mode(self):
109109

110110
def enable_error_codes(self):
111111
"""Enable error codes in the AT client"""
112-
self.at_command('AT+CMEE=1', wait_for_result=True)
112+
if not self.at_command('AT+CMEE=1', wait_for_result=True):
113+
logger.error("Failed to enable error codes.")
113114

114115
def at_command(self, at_command, wait_for_result=False, suppress_errors=False):
115116
"""Write an AT command to the command interface. Optionally wait for OK"""

tests/test_cli.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from unittest.mock import Mock, ANY, patch
44
from serial import SerialException
5-
from nrfcredstore.cli import main, parse_args, FUN_MODE_OFFLINE
5+
from nrfcredstore.cli import main, parse_args, run, FUN_MODE_OFFLINE
66

77
from nrfcredstore.credstore import CredType
88
from nrfcredstore.exceptions import NoATClientException, ATCommandError
@@ -32,6 +32,9 @@ def test_non_responsive_device(self, credstore, command_interface):
3232
main(parse_args(['fakedev', 'list']), credstore)
3333
assert e.type == TimeoutError
3434

35+
def test_non_responsive_device(self, credstore, command_interface, empty_cred_list):
36+
command_interface.detect_shell_mode.enable_error_codes.return_value = False
37+
main(parse_args(['fakedev', 'list']), credstore)
3538

3639
def test_list_default(self, credstore, empty_cred_list):
3740
main(parse_args(['fakedev', 'list']), credstore)
@@ -117,6 +120,9 @@ def test_at_command_error_exit_code(self, credstore):
117120
main(parse_args(['fakedev', 'list']), credstore)
118121
assert e.type == RuntimeError
119122

120-
# plan for new tests:
121-
# Comms cannot find device
122-
# Comms cannot enable error codes
123+
def test_cannot_find_device(self):
124+
with patch("nrfcredstore.comms.__init__", return_value=Mock()) as mock_comms:
125+
mock_comms.side_effect = Exception("No device found")
126+
with pytest.raises(Exception) as e:
127+
run(['nrfcredstore', 'fakedev', 'list'])
128+
assert e.type == Exception

0 commit comments

Comments
 (0)