Issue 7843 - SyntaxWarning in the test suite - #7856
Conversation
Bug description: 389ds#7843 reports a SyntaxWarning from lib389/lint.py showing up in test output. Compiling every .py in the tree finds 21 more, all in dirsrvtests, so pytest output stays noisy once that one is fixed: '\ ' globalgroup_part2_test.py, globalgroup_test.py '\(' '\{' syntax_test.py '\(' '\_' ds_logs_test.py '\=' fourwaymmr_test.py '\|' monitor_test.py '\(' acceptance_test.py '\(' virtual_attribute_replication_test.py '\(' basic_test.py '\(' ticket48973_test.py '\*' ticket49471_test.py These evaluate to a backslash followed by the character, so the values are correct today, but Python 3.12 warns on each and the sequences are slated to become errors in a later release. Fix description: Mark the literals raw, which is what regular expressions, LDAP filters and DN escapes want anyway. Three of them could not simply be marked raw, because they mix an invalid escape with a real one that raw would turn into two characters: - the roles and virtual attribute assertions also contain \', so the quotes are unescaped by hand; inside a double quoted string they need no escape - ticket48973_test.py also contains \", so the outer quotes are swapped to single - syntax_test.py:118 is an f-string where \\\{ is a real \\ followed by an invalid \{, and the brace still interpolates; it becomes \\\\ with a plain {DEFAULT_SUFFIX} No test string changes. Each file was compiled before and after and its string constants compared recursively: 1505 constants across the 11 files, all byte identical, with the warning count going from 21 to 0. lib389/lint.py is left alone here, it is fixed in 389ds#7844. Relates: 389ds#7843
3eb1735 to
393c432
Compare
|
Congratulations! One of the builds has completed. 🍾 You can install the built RPMs by following these steps:
Please note that the RPMs should be used only in a testing environment. |
|
Changes looks good. Waiting for the test result before approving and merging this PR |
|
Thanks @progier389. On waiting for the test result — the current run is 242 green and 4 red, and What this PR touches. Only test files, in these suites: What is failing. And the same jobs are red on everyone's PRs right now:
I am not asking you to merge over a red tick — if you would rather wait for a clean baseline that Happy to rebase onto current |
Relates to #7843. This is the follow-up I offered in #7844.
#7843 is about one
SyntaxWarningfromlib389/lint.py. Compiling every.pyin the tree finds 21 more, all indirsrvtests, so pytest output stays noisy once that one is fixed:'\ 'acl/globalgroup_part2_test.py,acl/globalgroup_test.py'\(''\{'acl/syntax_test.py'\(''\_'ds_logs/ds_logs_test.py'\='fourwaymmr/fourwaymmr_test.py'|'monitor/monitor_test.py'\('replication/acceptance_test.py,replication/virtual_attribute_replication_test.py,roles/basic_test.py,tickets/ticket48973_test.py'\*'tickets/ticket49471_test.pyThey evaluate to a backslash followed by the character, so the values are right today, but 3.12 warns on each and the sequences are slated to become errors later.
Not a blanket raw-string sweep
Most become raw strings, which is what the regular expressions, LDAP filters and DN escapes wanted anyway. Three could not, because they mix an invalid escape with a real one that raw would turn into two characters:
\'. Marking them raw would leave a literal backslash before each quote and the assertion would stop matching, so the quotes are unescaped by hand — inside a double-quoted string they need no escape.ticket48973_test.pyalso contains\", so the outer quotes are swapped to single ones.syntax_test.py:118is an f-string,f'(target = ldap:\\\{DEFAULT_SUFFIX})...'. That is a real\\followed by an invalid\{, and the brace still interpolates, so the value has two backslashes and the suffix substituted. It becomes\\\\with a plain{DEFAULT_SUFFIX}.Verification
No test string changes value. Each file was compiled before and after and its string constants compared recursively:
That check is the reason I am comfortable sending this without a server: it does not matter whether I judged each literal correctly by eye, because any literal whose value moved would have shown up as a differing constant. After this,
src/lib389/lib389/lint.pyis the only invalid escape left in the tree, and #7844 covers it.I have not run the suite — these need a live instance — so please shout if any of the rewritten assertions look wrong to you in context.
Summary by Sourcery
Remove invalid escape sequences from directory server tests to keep the test suite warning-free on newer Python versions.
Enhancements:
Tests: