-
-
Notifications
You must be signed in to change notification settings - Fork 32.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 our terms of service and privacy 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
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 :)
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
and 2**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 function SetErrorMode
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 of SetErrorMode
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.
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: import msvcrt
import unittest
class TestOther(unittest.TestCase):
def test_SetErrorMode(self):
origin = msvcrt.GetErrorMode()
print(f"origin mode: {origin}")
msvcrt.SetErrorMode(0)
current_default = msvcrt.GetErrorMode()
print(f"current default: {current_default}")
for v in (msvcrt.SEM_FAILCRITICALERRORS, msvcrt.SEM_NOGPFAULTERRORBOX,
msvcrt.SEM_NOALIGNMENTFAULTEXCEPT, msvcrt.SEM_NOOPENFILEERRORBOX):
if origin & 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. |
msvcrt
don't have tests #126028