Commit graph

15 commits

Author SHA1 Message Date
Thomas Haller
e35eceb9e3
clients/tests: add code comment and extend pattern in test_offline() 2022-04-20 15:47:01 +02:00
Thomas Haller
6aef83a556
clients/tests: workaround unexpected output for offline test
This test calls "nmcli g" with a bogus D-Bus bus address. We expect
a failure on stderr.

On alpine:latest, the error however looks slightly different:
  b'size: 258\nlocation: src/tests/client/test-client.py:test_offline()/1\ncmd: $NMCLI g\nlang: C\nreturncode: 1\nstderr: 136 bytes\n>>>\nError: Could not create NMClient object: Key/Value pair 0, *invalid*, in address element *very:invalid* does not contain an equal sign.\n\n<<<\n'
On ubuntu:16.04 and debian:9 we got:
  b"size: 258\nlocation: src/tests/client/test-client.py:test_offline()/1\ncmd: $NMCLI g\nlang: C\nreturncode: 1\nstderr: 136 bytes\n>>>\nError: Could not create NMClient object: Key/Value pair 0, 'invalid', in address element 'very:invalid' does not contain an equal sign.\n\n<<<\n"
On fedora and most recent systemd we got:
  b'size: 258\nlocation: src/tests/client/test-client.py:test_offline()/1\ncmd: $NMCLI g\nlang: C\nreturncode: 1\nstderr: 136 bytes\n>>>\nError: Could not create NMClient object: Key/Value pair 0, ?invalid?, in address element ?very:invalid? does not contain an equal sign.\n\n<<<\n'

This depends on the glib version (whether to print `%s', '%s', or “%s”).
Also, as we run the application with lang=C, so that libc (I think)
replaces Unicode with an ASCII character. Here musl and glibc behave
differently.

Workaround by replace the unexpected text.
2022-04-20 15:34:38 +02:00
Thomas Haller
2140da73a4
clients/tests: add code comment for how to get Polish translations on Fedora 2022-04-20 12:29:45 +02:00
Thomas Haller
7986ea8c1a
clients/tests: rework Util.replace_text() to uniformly accept a callable
Let the replace_arr parameter of Util.replace_text() only contain
callables, and don't special case the argument. Previously, we
either expected a regex or a 2-tuple, and the code would check
each explicitly.

Aside that the tuples are hard to follow, it also makes
Util.replace_text() strongly tied to those types. By instead accepting
and arbitrary function, each element can implement its own replacement.

Also, make text that was replaced by regex atomic. Meaning, if we
first match (and replace) a certain part of the text with the regex,
then the replacement cannot be split again. This is done by returning
a 1-tuple from the replace function.
2022-04-20 12:29:45 +02:00
Thomas Haller
a3038d4f5a
clients/tests: fix regular expression match in Util.replace_text()
Seems the previous code did not work properly:
With python36-3.6.8-38.module+el8.5.0+12207+5c5719bc.x86_6 on rhel-8.6:

  Traceback (most recent call last):
    File "/root/nm-build/NetworkManager/src/tests/client/test-client.py", line 1157, in f
      func(self)
    File "/root/nm-build/NetworkManager/src/tests/client/test-client.py", line 1724, in test_offline
      replace_stdout=replace_uuids,
    File "/root/nm-build/NetworkManager/src/tests/client/test-client.py", line 797, in call_nmcli
      frame,
    File "/root/nm-build/NetworkManager/src/tests/client/test-client.py", line 997, in _call_nmcli
      self.async_start(wait_all=sync_barrier)
    File "/root/nm-build/NetworkManager/src/tests/client/test-client.py", line 1032, in async_start
      async_job.wait_and_complete()
    File "/root/nm-build/NetworkManager/src/tests/client/test-client.py", line 670, in wait_and_complete
      self._complete_cb(self, return_code, stdout, stderr)
    File "/root/nm-build/NetworkManager/src/tests/client/test-client.py", line 919, in complete_cb
      stdout = Util.replace_text(stdout, replace_stdout)
    File "/root/nm-build/NetworkManager/src/tests/client/test-client.py", line 362, in replace_text
      if Util.is_regex_pattern(v_search):
    File "/root/nm-build/NetworkManager/src/tests/client/test-client.py", line 208, in is_regex_pattern
      t = re.Pattern
  AttributeError: module 're' has no attribute 'Pattern'

On this python version, re.compile() give an object of type
_sre.SRE_Pattern.

  # python -c 'import re; print(type(re.compile("a")))'
  <class '_sre.SRE_Pattern'>

Fixes: beebde9e56 ('client/test: allow matching and replacing regex-es in nmcli output')
2022-04-20 11:01:15 +02:00
Lubomir Rintel
97857dbacd client/test: add test for --offline behavior
Currently, only "add" and negative cases are tested. Testing "modify"
would require an ability to provide input. Perhaps at some later point.
2022-04-19 14:27:22 +02:00
Lubomir Rintel
e733357c91 client/test: add @nm_test_no_dbus decorator
Same as @nm_test, apart from that it doesn't spawn the mock D-Bus
service.
2022-04-19 14:12:43 +02:00
Lubomir Rintel
9108f8ecfc client/test: allow overriding all environment variables
Set extra variables after the pre-defined ones have been set. This
allows overriding then.

In particular, this allows overriding DBUS_SESSION_BUS_ADDRESS so that
the test can check the behavior of the client is correct when it's set
to some garbage.
2022-04-19 14:12:43 +02:00
Lubomir Rintel
beebde9e56 client/test: allow matching and replacing regex-es in nmcli output
This allows us to sanitize unpredictable UUIDs in client output in
--offline mode (where we can't just ask the mock service about the
actual UUID).
2022-04-19 14:12:43 +02:00
Thomas Haller
101a7cb56d
tests: improve documentation how to generate files for "/test-client.py" 2021-08-26 13:47:04 +02:00
Thomas Haller
56707a09ae
client/tests: check output of plain nmcli in "test-client.py" 2021-07-29 13:25:59 +02:00
Thomas Haller
10567386f0
cli/tests: add unit test for checking setting/getting of "gsm.apn"
"gsm.apn" is special, because it can both be %NULL and "".

Add a test for how we handle that.
2021-05-03 10:11:24 +02:00
Thomas Haller
c2265dd8a9
Revert "tests/client: increase timeout to wait for process"
This didn't help and was not necessary. Instead, there was an issue
that is fixed now.

This reverts commit b4c25f9131.
2021-03-19 11:35:18 +01:00
Thomas Haller
b4c25f9131
tests/client: increase timeout to wait for process
We now get unit test failures hitting this timeout. That is
likely a new bug introduced somewhere, but to rule out that
the timeout is simply too short, increase it.
2021-03-17 10:57:52 +01:00
Thomas Haller
019bc3233a
client/tests: move "clients/tests/test-client.py" to "src/tests/client/"
Note that "test-client.py" currently only tests nmcli. But what it does
is to spawn test-networkmanager-service.py and run nmcli against it.

As such, it could really be used to test any NetworkManager client
against the stub service. Hence this test is not under
"src/nmcli/tests", but under "src/tests/client/" where it is more
general.
2021-03-15 17:10:55 +01:00
Renamed from clients/tests/test-client.py (Browse further)