-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PR: Fix some tests failing on Python 3.12 #21692
Conversation
Hello @juliangilbey! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
Comment last updated at 2024-01-12 06:38:56 UTC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @juliangilbey for your help with this! I left a small comment for you. The rest looks good to me.
editor.renamed.assert_called_with(source='/test/directory/file4.rst', | ||
dest='/test/dir/file4.rst') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is clearly not a fix for this test because we need to check that all files have been renamed. And that's detected by our Windows tests.
So, I recommend instead to revert these changes and simply skip it in your test env.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, this test didn't do anything (even on Windows), because called_once
always silently returned a true value without testing anything. I've just pushed a new version of the patch, replacing the assert_called_with()
call, which only tests the most recent call, with assert_any_call()
, which checks whether the method has ever been called with the specified arguments. So this new version of the patch now correctly checks for all three calls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small clarification to that comment: called_once()
always silently returned a true value on Python <= 3.11. But on Python 3.12, it throws an error, which is how I discovered this bug.
2b737f5
to
e20df10
Compare
It turns out that fixing this test shows that
Note the key information here: the Let's run the steps of >>> import os
>>> import os.path as osp
>>> os.getcwd()
'C:\\Program Files\\Python39'
>>> source = "/test/directory"
>>> dest = "/test/dir"
>>> fname = "/test/directory/file1.py"
>>> dirname = osp.abspath(source)
>>> dirname
'C:\\test\\directory'
>>> osp.abspath(fname)
'C:\\test\\directory\\file1.py'
>>> osp.abspath(fname).startswith(dirname)
True
>>> fname.replace(dirname, dest)
'/test/directory/file1.py' Oops! The next question, then, is how to fix source_re = "^" + re.escape(source)
dest_quoted = dest.replace("\\", r"\\")
new_filename = re.sub(source_re, dest_quoted, fname, count=1) This works on both Windows and Linux (so presumably on macOS as well). I'll submit a separate PR with this fix. |
Well, I found a separate issue in the file as I was editing it, so I've just submitted two separate PRs: #21695 and #21696. The tests for this PR should work once those two PRs are accepted and this PR is rebased against it. (The tests for #21696 will work because |
OK, I've now fixed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me now, thanks @juliangilbey for your help with this!
Description of Changes
These fix all of the issues identified in #21688 except for
test_move_to_first_breakpoint[False]
. The tests usingcalled_with
were both broken, and this patch also fixes this.Issue(s) Resolved
Almost resolves (fixes) #21688, but not quite
Affirmation
By submitting this Pull Request or typing my (user)name below,
I affirm the Developer Certificate of Origin
with respect to all commits and content included in this PR,
and understand I am releasing the same under Spyder's MIT (Expat) license.
I certify the above statement is true and correct: @juliangilbey