You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add live tests for gaps in what CI checks on real Drive - #457
The first set of live tests for behaviour that CI never ran against real Drive. A review of the suite before 2.0 listed what users rely on but only mocks, or nothing at all, checked. These are the ones about data and paths.
Filesystem on a folder ID
A new module, test_fs_folder_id.py, mounts the filesystem on a folder ID, the form DVC remotes use (gdrive://FOLDER_ID/...). No live test wrote under a folder ID before. Each test makes its own folder and checks the result with a new filesystem instance, so the directory cache cannot hide a mistake.
Names Drive treats specially. Drive matches names without regard to case and has its own quoting. The tests cover:
Report.txt and report.txt side by side: each reads its own bytes, and removing one leaves the other;
names with a quote, a backslash, two spaces, an accent in the composed form and in the decomposed form that macOS hands to put(), and Japanese, all in one folder.
Checksums and sizes. The MD5 and size that info(), ls(detail=True) and find(detail=True) report equal those of the bytes written. DVC compares these.
What a folder-ID root changes: writes under the ID, fsspec.open(..., "rt").readline() on a gdrive:// URL with the ID, and info, ls and find of the root. The other operations have their own tests in test_fs.py.
rmdir with trash_only=False on a folder whose file is in the trash. It raises ENOTEMPTY, and the trashed file can still be restored. The guide promises this.
Uploads in several parts. Large files are uploaded in parts, which Drive acknowledges with 308 answers. PyDrive2 has no option for the part size (100 MiB), so the tests patch pydrive2.files.MediaIoBaseUpload to 256 KiB parts, and each test asserts that its uploads were built that way. A file of 1 MiB + 1 byte then needs five parts:
put_file with a progress callback;
an update of an existing file's content through GoogleDriveFile (in test_file.py).
Each is compared with the data byte for byte.
A write through open("wb") larger than the writer's 1 MiB memory buffer (fs.blocksize) arrives intact.
Moves:
a folder with contents, to another folder under a new name;
a file onto a folder path, which moves it into the folder;
a folder into its own subfolder, which raises and changes nothing.
Elsewhere
test_drive.py: a request after the service account token expired, and one after Drive rejected the token. Both succeed after a refresh, and the credentials are no longer expired. A long DVC job meets this after an hour; CI runs are shorter.
test_filelist.py: the paging test now selects only files(id,name) and still pages through all ten files, in more than one page. Drive returns the page token only when the field mask names it.
test_oauth.py: three service account tests only got a token and slept a second. One test now signs in with each key form and reads the account from Drive: a JSON file named in a settings file, a JSON string, a dict, and a PKCS12 file built from the CI key. PKCS12 had never been run against Google.
test_fs.py: the two filesystem sign-in tests now make a real Drive call through the new login: info("root"). They do not read the module's base folder, which may not exist yet when they run.
Validation
These tests describe what should already work, so they are expected to pass on main. Where one fails, it has found a bug, and the fix goes in its own PR.
The offline suite is unchanged (536 passed, also with google-auth 2.15.0). The new tests ran against the local fake Drive as a smoke check, apart from the multi-part uploads and the token tests, which the fake cannot do.
A filesystem mounted on a folder ID, as DVC uses it: names that differ
only in case, names with quotes, backslashes, spaces, accents (also in
the decomposed form macOS uses) and non-Latin scripts, checksums and
sizes against the bytes, files and folders under the folder ID, rmdir
for good with trashed files inside, uploads and updates in several
parts, a write that spills to a temporary file, and moves of folders,
onto folders and into themselves.
Also: a request after the service account token expired or was
rejected, and a listing with a field mask across pages.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Three live tests only got a token and slept a second. One test now
signs in with each key form, a JSON file named in a settings file, a
JSON string, a dict and a PKCS12 file made from the CI key, and reads
the account's name from Drive. The two filesystem sign-in tests check
that the base folder exists.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Drive lists a folder in its own order. The filesystem sign-in tests
read the root, since the module's base folder may not exist yet when
they run.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
[AI generated — Copilot]
5-pass review summary: valuable real-Drive coverage (PKCS12, Unicode/case sensitivity, multi-part uploads, folder moves, field-mask pagination). Main concerns: yet another standalone live test file duplicating fixtures across #457/#460/#462/#463, unverified multi-part monkeypatching, unnecessary monkeypatch on a local fs, and 6 separate Drive folders for NAMES.
All names go into one folder, the folder-ID test keeps what only a
folder-ID root shows, uploads assert their 256 KiB parts, and the
writer test sets the public blocksize. The core-API update moves to
test_file.py, the field-mask listing replaces the plain paging test,
and the token test checks the renewed expiry.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…util
Downloading by ID also works for a trashed file, so the test untrashes it
and checks its metadata.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The credential tests read the Drive root instead of the configured base folder, allowing them to pass even when that folder is missing.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Test the configured base folder instead of Drive root
pydrive2/test/test_fs.py:82
This reads the account's Drive root rather than base_remote_dir, so it passes even when the configured base folder is missing and does not exercise the base-folder read described in the PR. Call the existing fs_factory fixture to create the base folder, then assert fs.info(base_remote_dir). The inline-JSON test at line 92 needs the same change.
AI generated · Claude · On the review's note about test_fs.py:82: the sign-in tests read the Drive root on purpose. They check that a login from a service-account JSON works against Drive. The module's base folder is created by fs_factory and may not exist yet when they run. I corrected the PR description, which still said they read the base folder.
This branch has not been deployed
No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The first set of live tests for behaviour that CI never ran against real Drive. A review of the suite before 2.0 listed what users rely on but only mocks, or nothing at all, checked. These are the ones about data and paths.
Filesystem on a folder ID
A new module,
test_fs_folder_id.py, mounts the filesystem on a folder ID, the form DVC remotes use (gdrive://FOLDER_ID/...). No live test wrote under a folder ID before. Each test makes its own folder and checks the result with a new filesystem instance, so the directory cache cannot hide a mistake.Names Drive treats specially. Drive matches names without regard to case and has its own quoting. The tests cover:
Report.txtandreport.txtside by side: each reads its own bytes, and removing one leaves the other;put(), and Japanese, all in one folder.Checksums and sizes. The MD5 and size that
info(),ls(detail=True)andfind(detail=True)report equal those of the bytes written. DVC compares these.What a folder-ID root changes: writes under the ID,
fsspec.open(..., "rt").readline()on agdrive://URL with the ID, andinfo,lsandfindof the root. The other operations have their own tests intest_fs.py.rmdirwithtrash_only=Falseon a folder whose file is in the trash. It raisesENOTEMPTY, and the trashed file can still be restored. The guide promises this.Uploads in several parts. Large files are uploaded in parts, which Drive acknowledges with 308 answers. PyDrive2 has no option for the part size (100 MiB), so the tests patch
pydrive2.files.MediaIoBaseUploadto 256 KiB parts, and each test asserts that its uploads were built that way. A file of 1 MiB + 1 byte then needs five parts:put_filewith a progress callback;GoogleDriveFile(intest_file.py).Each is compared with the data byte for byte.
A write through
open("wb")larger than the writer's 1 MiB memory buffer (fs.blocksize) arrives intact.Moves:
Elsewhere
test_drive.py: a request after the service account token expired, and one after Drive rejected the token. Both succeed after a refresh, and the credentials are no longer expired. A long DVC job meets this after an hour; CI runs are shorter.test_filelist.py: the paging test now selects onlyfiles(id,name)and still pages through all ten files, in more than one page. Drive returns the page token only when the field mask names it.test_oauth.py: three service account tests only got a token and slept a second. One test now signs in with each key form and reads the account from Drive: a JSON file named in a settings file, a JSON string, a dict, and a PKCS12 file built from the CI key. PKCS12 had never been run against Google.test_fs.py: the two filesystem sign-in tests now make a real Drive call through the new login:info("root"). They do not read the module's base folder, which may not exist yet when they run.Validation
These tests describe what should already work, so they are expected to pass on main. Where one fails, it has found a bug, and the fix goes in its own PR.
The offline suite is unchanged (536 passed, also with google-auth 2.15.0). The new tests ran against the local fake Drive as a smoke check, apart from the multi-part uploads and the token tests, which the fake cannot do.
🤖 Generated with Claude Code