Merge utils: adjusts aa-notify tests to handle Python 3.13+

Python 3.13 changes the formatting of long-short option pairs that use a
meta-variable. Up until 3.13 the meta-variable was repeated. Since
Python change [1] the meta-var is only printed once.

[1] https://github.com/python/cpython/pull/103372

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1495
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Zygmunt Krynicki <me@zygoon.pl>
This commit is contained in:
Zygmunt Krynicki 2025-01-28 22:24:25 +00:00
commit 219626c503

View file

@ -209,14 +209,13 @@ Display AppArmor notifications or messages for DENIED entries.
-p, --poll poll AppArmor logs and display notifications -p, --poll poll AppArmor logs and display notifications
--display DISPLAY set the DISPLAY environment variable (might be needed if --display DISPLAY set the DISPLAY environment variable (might be needed if
sudo resets $DISPLAY) sudo resets $DISPLAY)
-f FILE, --file FILE search FILE for AppArmor messages -f, --file FILE search FILE for AppArmor messages
-l, --since-last display stats since last login -l, --since-last display stats since last login
-s NUM, --since-days NUM -s, --since-days NUM show stats for last NUM days (can be used alone or with
show stats for last NUM days (can be used alone or with
-p) -p)
-v, --verbose show messages with stats -v, --verbose show messages with stats
-u USER, --user USER user to drop privileges to when not using sudo -u, --user USER user to drop privileges to when not using sudo
-w NUM, --wait NUM wait NUM seconds before displaying notifications (with -w, --wait NUM wait NUM seconds before displaying notifications (with
-p) -p)
-m, --merge-notifications -m, --merge-notifications
Merge notification for improved readability (with -p) Merge notification for improved readability (with -p)
@ -240,6 +239,28 @@ Filtering options:
regular expression to match the network socket type regular expression to match the network socket type
''' # noqa: E128 ''' # noqa: E128
if sys.version_info[:2] < (3, 13):
# Python 3.13 tweaked argparse output [1]. When running on older
# Python versions, we adapt the expected output to match.
#
# https://github.com/python/cpython/pull/103372
patches = [(
', --file FILE ',
' FILE, --file FILE',
), (
', --since-days NUM show stats for last NUM days (can be used alone or with',
' NUM, --since-days NUM\n'
+ ' show stats for last NUM days (can be used alone or with',
), (
', --user USER ',
' USER, --user USER',
), (
', --wait NUM ',
' NUM, --wait NUM',
)]
for patch in patches:
expected_output_2 = expected_output_2.replace(patch[0], patch[1])
return_code, output = cmd(aanotify_bin + ['--help']) return_code, output = cmd(aanotify_bin + ['--help'])
result = 'Got return code {}, expected {}\n'.format(return_code, expected_return_code) result = 'Got return code {}, expected {}\n'.format(return_code, expected_return_code)
self.assertEqual(expected_return_code, return_code, result + output) self.assertEqual(expected_return_code, return_code, result + output)