8000 utils: adjusts aa-notify tests to handle Python 3.13+ · DreamConnected/libapparmor-dev@6336465 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6336465

Browse files
committed
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 <zygmunt.krynicki@canonical.com>
1 parent 6405608 commit 6336465

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
-m, --merge-notifications
222221
Merge notification for improved readability (with -p)
@@ -240,6 +239,28 @@ def test_help_contents(self):
240239
regular expression to match the network socket type
241240
''' # noqa: E128
242241

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

0 commit comments

Comments
 (0)
0