Skip to content

Fix Python test suite failures on Windows. - #801

Open
MohammedAlkindi wants to merge 4 commits into
google:masterfrom
MohammedAlkindi:fix/windows-test-suite
Open

MohammedAlkindi wants to merge 4 commits into
google:masterfrom
MohammedAlkindi:fix/windows-test-suite

Conversation

@MohammedAlkindi

Copy link
Copy Markdown

The Python test suite does not pass on Windows. Six modules assert POSIX-only behaviour, and python_tests.yml runs ubuntu-latest only, so none of it is visible in CI. No product code is changed.

Four are separator assumptions the diff makes obvious. download_test is subtler: it hardcodes the SHA256 of LF text, but absltest.create_tempfile opens str content in text mode, so the file reaches disk as CRLF. Passing bytes skips the translation.

ntp_test is two problems. time.tzset() does not exist on Windows, so the module raised AttributeError before any assertion ran. It also asserted SYS_SYSTEM32 while ntp.py builds BINARY from WINPE_SYSTEM32. SyncClockToNtp runs only under autobuild.py's if winpe.check_winpe() guard, so WINPE_SYSTEM32 is correct and the assertion was wrong. The two constants collapse to one string under posixpath, which is why this never surfaced. Same root cause as #796.

Windows 11, Python 3.13.13: 56 passing / 3 failing before, 57 / 2 after. Counts come from testing/run_tests.py with sys.executable substituted for its PATH lookup of python, which is a separate issue and not part of this change. splice_test and drivers_test still fail; the first needs elevation to write C:\Program Files\Splice.

Six test modules make POSIX-only assumptions. python_tests.yml runs on
ubuntu-latest only, so none of them are observable in CI. No product code
is changed.

cache_test: ntpath.join('C:', name) is drive-relative and inserts no
separator. Mirror the cache_path + os.sep construction _DestinationPath
itself uses.

installer_test: two assertions built '{}/build_info.yaml' by hand where
the source calls os.path.join, and test_exit_win_pe expected a POSIX
literal rather than the WINPE_TASK_LIST and SYS_TASK_LIST constants
ExitWinPE actually passes to CopyFile.

logs_test: reproduce zipfile's own arcname rule (strip the drive, then
normalize to '/') instead of lstrip('/'), which is a no-op on 'C:\...'.

powershell_test: _GetResPath ends in os.path.normpath, so the expected
value needs normalizing too.

download_test: absltest's create_tempfile opens str content in text mode,
so the '\n' in _TEST_INI reached disk as '\r\n' and the hardcoded SHA256
no longer matched. Passing bytes routes through write_bytes, which does
no newline translation on any platform.

ntp_test: time.tzset() does not exist on Windows, so the module raised
AttributeError before any assertion ran. Mocking time.localtime pins the
same effective timezone portably. The binary assertion also named
SYS_SYSTEM32, while ntp.py builds BINARY from WINPE_SYSTEM32.
SyncClockToNtp is reached only under autobuild.py's
if winpe.check_winpe() guard, so WINPE_SYSTEM32 is the correct root and
the assertion was wrong. The two constants collapse to one string under
posixpath, which is why this never surfaced.

Measured on Windows 11, Python 3.13.13: 56 passing / 3 failing before,
57 passing / 2 failing after. splice_test needs elevation to write
C:\Program Files\Splice; drivers_test is unrelated to these changes.
@MohammedAlkindi

Copy link
Copy Markdown
Author

The measurement note above now has a PR behind it: #802 makes testing/run_tests.py launch each module with sys.executable instead of resolving python through PATH.

That is why the counts here were taken with the substitution applied by hand. Unpatched, the runner reports Success: 0 / Failure: 59 in a virtualenv, because every module is launched by the system interpreter.

The two touch disjoint files and can land in either order, though #802 first gives the cleaner story, since its own numbers are measured against unmodified tests.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant