Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix KeyError in MountPoint.__repr__() #781

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading