Skip to content

Commit

Permalink
test_hostkeys: test SubDict.__delitem__()
Browse files Browse the repository at this point in the history
SubDict.__delitem__() would trigger the KeyError exception if a key type to
be deleted is not present.

Signed-off-by: Lans Zhang <[email protected]>
  • Loading branch information
Lans Zhang authored and bitprophet committed Nov 29, 2021
1 parent b79892d commit 15fa5b8
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/test_hostkeys.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,20 @@ def test_delitem(self):
pass # Good
else:
assert False, "Entry was not deleted from HostKeys on delitem!"

def test_entry_delitem(self):
hostdict = paramiko.HostKeys('hostfile.temp')
target = 'happy.example.com'
entry = hostdict[target]
key_type_list = [ key_type for key_type in entry ]
for key_type in key_type_list:
del entry[key_type]

# will KeyError if not present
for key_type in key_type_list:
try:
del entry[key_type]
except KeyError:
pass # Good
else:
assert False, "Key was not deleted from Entry on delitem!"

0 comments on commit 15fa5b8

Please sign in to comment.