Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
aisk wants to merge17 commits intopython:main
base:main
Choose a base branch
Loading
fromaisk:msvcrt-more-tests

Conversation

aisk
Copy link
Member

@aiskaisk commentedOct 27, 2024
edited by bedevere-appbot
Loading

aiskand others added2 commitsOctober 27, 2024 19:19
Co-authored-by: Tomas R. <tomas.roun8@gmail.com>
aiskand others added3 commitsOctober 28, 2024 14:47
Copy link
Member

@sobolevnsobolevn left a 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 :)

aisk reacted with heart emoji
@sobolevnsobolevn requested a review froma teamOctober 28, 2024 08:26
old = msvcrt.GetErrorMode()
self.addCleanup(msvcrt.SetErrorMode, old)

returned = msvcrt.SetErrorMode(0)

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).

Copy link
MemberAuthor

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!

Copy link
MemberAuthor

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.

@aisk
Copy link
MemberAuthor

aisk commentedJul 17, 2025
edited
Loading

Updated: I misunderstand theSetErrorMode API, it's mode can be restored after the test. Now this PR is ready for review.

cc@serhiy-storchaka

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:

python .\a.pyorigin mode: 32771  (0x1 + 0x2 + 0x8000)current default: 0set v: 1 (0x1)set v: 2 (0x2)set v: 32768 (0x8000)F======================================================================FAIL: test_SetErrorMode (__main__.TestOther)----------------------------------------------------------------------Traceback (most recent call last):  File "C:\Users\xxxxx\Source\cpython\a.py", line 18, in test_SetErrorMode    self.assertEqual(origin, msvcrt.GetErrorMode())AssertionError: 32771 != 32768----------------------------------------------------------------------Ran 1 test in 0.001sFAILED (failures=1)

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.
This leads to us not being able to restore the mode to the original value after we set it in the test case. I have no idea why this happens, maybe there are some limitations in the Windows OS. So should we keep this test?

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@serhiy-storchakaserhiy-storchakaserhiy-storchaka left review comments

@tomasr8tomasr8tomasr8 left review comments

@sobolevnsobolevnsobolevn approved these changes

Assignees
No one assigned
Labels
awaiting mergeskip newstestsTests in the Lib/test dir
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@aisk@serhiy-storchaka@sobolevn@tomasr8

[8]ページ先頭

©2009-2025 Movatter.jp