Skip to content

Commit 424a0b7

Browse files
authored
Merge pull request #1949 from atline/fix_who
client: fix header row placement in 'who' output
2 parents 029850b + e8618f5 commit 424a0b7

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

labgrid/remote/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ def print_who(self):
419419
if self.args.show_exporters:
420420
exporters = {resource_path[0] for resource_path in place.acquired_resources}
421421
result[-1].append(", ".join(sorted(exporters)))
422-
result.sort()
422+
result[1:] = sorted(result[1:])
423423

424424
widths = [max(map(len, c)) for c in zip(*result)]
425425
layout = []

tests/test_client.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,32 @@ def test_place_acquire(place):
162162
spawn.close()
163163
assert spawn.exitstatus == 0, spawn.before.strip()
164164

165+
def test_place_who_header_stays_first(monkeypatch, place):
166+
# A user name starting with an uppercase letter sorts before the "User"
167+
# header when comparing strings (uppercase letters have lower code points
168+
# than lowercase ones). Ensure the header still stays on the first line.
169+
user = "Alice"
170+
host = "test-host"
171+
monkeypatch.setenv("LG_USERNAME", user)
172+
monkeypatch.setenv("LG_HOSTNAME", host)
173+
174+
with pexpect.spawn('python -m labgrid.remote.client -p test acquire') as spawn:
175+
spawn.expect(pexpect.EOF)
176+
spawn.close()
177+
assert spawn.exitstatus == 0, spawn.before.strip()
178+
179+
with pexpect.spawn('python -m labgrid.remote.client who') as spawn:
180+
spawn.expect(pexpect.EOF)
181+
spawn.close()
182+
assert spawn.exitstatus == 0, spawn.before.strip()
183+
lines = spawn.before.decode("utf-8").strip().splitlines()
184+
assert lines[0].split()[:4] == ["User", "Host", "Place", "Changed"], lines
185+
186+
with pexpect.spawn('python -m labgrid.remote.client -p test release') as spawn:
187+
spawn.expect(pexpect.EOF)
188+
spawn.close()
189+
assert spawn.exitstatus == 0, spawn.before.strip()
190+
165191
def test_place_acquire_multiple(create_place, tmpdir):
166192
# create multiple places
167193
place_names = ['test1', 'test2']

0 commit comments

Comments
 (0)