Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.4k
gh-126028: Add more tests for msvcrt module#126029
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Conversation
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: sobolevn <mail@sobolevn.me>
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.
LGTM now, I will wait for MS expert to also approve :)
Uh oh!
There was an error while loading.Please reload this page.
Lib/test/test_msvcrt.py Outdated
old = msvcrt.GetErrorMode() | ||
self.addCleanup(msvcrt.SetErrorMode, old) | ||
returned = msvcrt.SetErrorMode(0) |
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.
Maybe test it also with non-zero value, and also with out-of-range values-1
and2**32
? If this is possible (if the test does not crash or hangs).
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 functionSetErrorMode
have weird behaviors and it behaves different in the test case or in a standalone test script, it sometimes returns different mode compare to the one set. I'm still try to figure it out and will update it tomorrow, thank you for the review!
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.
Figured out the case ofSetErrorMode
and found that it's actually not set the value to current, but set the bit flags on it. Currently made the test workable, but still have some concerns about it.
Added some details as a separate comment blow.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
aisk commentedJul 17, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Updated: I misunderstand the Bellow comment is wrong:Hi, I found that the [`SetErrorMode`](https://learn.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-seterrormode) actually sets the value as a bit flag to the current state, and `SetErrorMode(0)` sets it to 0.I have some code like this: importmsvcrtimportunittestclassTestOther(unittest.TestCase):deftest_SetErrorMode(self):origin=msvcrt.GetErrorMode()print(f"origin mode:{origin}")msvcrt.SetErrorMode(0)current_default=msvcrt.GetErrorMode()print(f"current default:{current_default}")forvin (msvcrt.SEM_FAILCRITICALERRORS,msvcrt.SEM_NOGPFAULTERRORBOX,msvcrt.SEM_NOALIGNMENTFAULTEXCEPT,msvcrt.SEM_NOOPENFILEERRORBOX):iforigin&v:print("set v:",v)msvcrt.SetErrorMode(v)self.assertEqual(origin,msvcrt.GetErrorMode())if__name__=="__main__":unittest.main() It reads the original mode, and sets the current mode to 0, and compares the 4 available bit flags to the original mode, and if it's true, then sets it. There is the running result:
But the final result is not the same as the original mode. There is a difference of "3", so I guess the bit flags "0x1" and "0x2" don't have any effect. |
Uh oh!
There was an error while loading.Please reload this page.
msvcrt
don't have tests #126028