Skip to content

Commit fc53e20

Browse files
CarstenGrohmannphilpep
authored andcommitted
Fix KeyError in MountPoint.__repr__() if mount does not exist
1 parent 104629d commit fc53e20

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

test/test_modules.py

+2
Original file line numberDiff line numberDiff line change
@@ -482,12 +482,14 @@ def test_supervisor(host, supervisorctl_path, supervisorctl_conf):
482482
def test_mountpoint(host):
483483
root_mount = host.mount_point("/")
484484
assert root_mount.exists
485+
assert repr(root_mount)
485486
assert isinstance(root_mount.options, list)
486487
assert "rw" in root_mount.options
487488
assert root_mount.filesystem
488489

489490
fake_mount = host.mount_point("/fake/mount")
490491
assert not fake_mount.exists
492+
assert repr(fake_mount)
491493

492494
mountpoints = host.mount_point.get_mountpoints()
493495
assert mountpoints

testinfra/modules/mountpoint.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,17 @@ def get_module_class(cls, host):
101101
raise NotImplementedError
102102

103103
def __repr__(self):
104+
if self.exists:
105+
d = self.device
106+
f = self.filesystem
107+
o = ",".join(self.options)
108+
else:
109+
d = ""
110+
f = ""
111+
o = ""
104112
return (
105-
"<MountPoint(path={}, device={}, filesystem={}, " "options={})>"
106-
).format(
107-
self.path,
108-
self.device,
109-
self.filesystem,
110-
",".join(self.options),
113+
f'<MountPoint(path="{self.path}", exists={self.exists}, device="{d}", '
114+
f'filesystem="{f}", options="{o}") at 0x{id(self):08x}>'
111115
)
112116

113117

0 commit comments

Comments
 (0)