Skip to content

Commit

Permalink
Fix KeyError in MountPoint.__repr__() if mount does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
CarstenGrohmann committed Nov 3, 2024
1 parent e1eb9c1 commit 0de8b72
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 2 additions & 0 deletions test/test_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,12 +482,14 @@ def test_supervisor(host, supervisorctl_path, supervisorctl_conf):
def test_mountpoint(host):
root_mount = host.mount_point("/")
assert root_mount.exists
assert repr(root_mount)
assert isinstance(root_mount.options, list)
assert "rw" in root_mount.options
assert root_mount.filesystem

fake_mount = host.mount_point("/fake/mount")
assert not fake_mount.exists
assert repr(fake_mount)

mountpoints = host.mount_point.get_mountpoints()
assert mountpoints
Expand Down
16 changes: 10 additions & 6 deletions testinfra/modules/mountpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,17 @@ def get_module_class(cls, host):
raise NotImplementedError

def __repr__(self):
if self.exists:
d = self.device
f = self.filesystem
o = ",".join(self.options)
else:
d = ""
f = ""
o = ""
return (
"<MountPoint(path={}, device={}, filesystem={}, " "options={})>"
).format(
self.path,
self.device,
self.filesystem,
",".join(self.options),
f'<MountPoint(path="{self.path}", exists={self.exists}, device="{d}", '
f'filesystem="{f}", options="{o}") at 0x{id(self):08x}>'
)


Expand Down

0 comments on commit 0de8b72

Please sign in to comment.