Skip to content

Commit 161863e

Browse files
zygajrjohansen
authored andcommitted
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] python/cpython#103372 Signed-off-by: Zygmunt Krynicki <[email protected]> (cherry picked from commit 6336465) Signed-off-by: John Johansen <[email protected]>
1 parent b04faf1 commit 161863e

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

utils/test/test-aa-notify.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,13 @@ def test_help_contents(self):
209209
-p, --poll poll AppArmor logs and display notifications
210210
--display DISPLAY set the DISPLAY environment variable (might be needed if
211211
sudo resets $DISPLAY)
212-
-f FILE, --file FILE search FILE for AppArmor messages
212+
-f, --file FILE search FILE for AppArmor messages
213213
-l, --since-last display stats since last login
214-
-s NUM, --since-days NUM
215-
show stats for last NUM days (can be used alone or with
214+
-s, --since-days NUM show stats for last NUM days (can be used alone or with
216215
-p)
217216
-v, --verbose show messages with stats
218-
-u USER, --user USER user to drop privileges to when not using sudo
219-
-w NUM, --wait NUM wait NUM seconds before displaying notifications (with
217+
-u, --user USER user to drop privileges to when not using sudo
218+
-w, --wait NUM wait NUM seconds before displaying notifications (with
220219
-p)
221220
--prompt-filter PF kind of operations which display a popup prompt
222221
--debug debug mode
@@ -238,6 +237,28 @@ def test_help_contents(self):
238237
regular expression to match the network socket type
239238
''' # noqa: E128
240239

240+
if sys.version_info[:2] < (3, 13):
241+
# Python 3.13 tweaked argparse output [1]. When running on older
242+
# Python versions, we adapt the expected output to match.
243+
#
244+
# https://github.com/python/cpython/pull/103372
245+
patches = [(
246+
' -f, --file FILE search FILE for AppArmor messages',
247+
' -f FILE, --file FILE search FILE for AppArmor messages',
248+
), (
249+
' -s, --since-days NUM show stats for last NUM days (can be used alone or with',
250+
' -s NUM, --since-days NUM\n'
251+
+ ' show stats for last NUM days (can be used alone or with',
252+
), (
253+
' -u, --user USER user to drop privileges to when not using sudo',
254+
' -u USER, --user USER user to drop privileges to when not using sudo',
255+
), (
256+
' -w, --wait NUM wait NUM seconds before displaying notifications (with',
257+
' -w NUM, --wait NUM wait NUM seconds before displaying notifications (with',
258+
)]
259+
for patch in patches:
260+
expected_output_2 = expected_output_2.replace(patch[0], patch[1])
261+
241262
return_code, output = cmd(aanotify_bin + ['--help'])
242263
result = 'Got return code {}, expected {}\n'.format(return_code, expected_return_code)
243264
self.assertEqual(expected_return_code, return_code, result + output)

0 commit comments

Comments
 (0)