Skip to content

Commit

Permalink
Tentatively supported since nmcli.general parsing needed to take trai…
Browse files Browse the repository at this point in the history
…ling spaces.
  • Loading branch information
ushiboy committed Sep 15, 2024
1 parent 37ab3ad commit 01bdda8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
3 changes: 2 additions & 1 deletion nmcli/data/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def parse(cls, text: str) -> General:
+ r'$'
)

m = re.search(pattern, text)
# The execution result will have a trailing space, so trim it and then match it to the pattern.
m = re.search(pattern, text.rstrip())

if m:
state, connectivity, wifi_hw, wifi, wwan_hw, wwan, _metered = m.groups()
Expand Down
16 changes: 8 additions & 8 deletions tests/data/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,42 @@ def test_to_json():


def test_parse():
d1 = 'unknown none enabled enabled enabled disabled'
d1 = 'unknown none enabled enabled enabled disabled '
assert General.parse(d1) == General(NetworkManagerState.UNKNOWN,
NetworkConnectivity.NONE,
True, True, True, False)

d2 = 'asleep portal enabled enabled disabled enabled'
d2 = 'asleep portal enabled enabled disabled enabled '
assert General.parse(d2) == General(NetworkManagerState.ASLEEP,
NetworkConnectivity.PORTAL,
True, True, False, True)

d3 = 'connecting limited enabled disabled enabled enabled'
d3 = 'connecting limited enabled disabled enabled enabled '
assert General.parse(d3) == General(NetworkManagerState.CONNECTING,
NetworkConnectivity.LIMITED,
True, False, True, True)

d4 = 'connected (local only) full disabled enabled enabled enabled'
d4 = 'connected (local only) full disabled enabled enabled enabled '
assert General.parse(d4) == General(NetworkManagerState.CONNECTED_LOCAL,
NetworkConnectivity.FULL,
False, True, True, True)

d5 = 'connected (site only) full enabled enabled enabled enabled'
d5 = 'connected (site only) full enabled enabled enabled enabled '
assert General.parse(d5) == General(NetworkManagerState.CONNECTED_SITE,
NetworkConnectivity.FULL,
True, True, True, True)

d6 = 'disconnecting full enabled enabled enabled enabled'
d6 = 'disconnecting full enabled enabled enabled enabled '
assert General.parse(d6) == General(NetworkManagerState.DISCONNECTING,
NetworkConnectivity.FULL,
True, True, True, True)

d7 = 'disconnected full enabled enabled enabled enabled'
d7 = 'disconnected full enabled enabled enabled enabled '
assert General.parse(d7) == General(NetworkManagerState.DISCONNECTED,
NetworkConnectivity.FULL,
True, True, True, True)

d8 = 'connected full enabled enabled missing enabled no (guessed)'
d8 = 'connected full enabled enabled missing enabled no (guessed) '
assert General.parse(d8) == General(NetworkManagerState.CONNECTED_GLOBAL,
NetworkConnectivity.FULL,
True, True, False, True)
Expand Down

0 comments on commit 01bdda8

Please sign in to comment.