test: search store/ in Python instead of shelling out to grep - #983
Open
ChrisDoufu wants to merge 1 commit into
Open
ChrisDoufu wants to merge 1 commit into
ChrisDoufu wants to merge 1 commit into
Conversation
test_store_no_forbidden_dict_keys and test_store_no_creator_orm_imports ran `grep -rnE` through subprocess. On Windows this fails: PowerShell has no grep (FileNotFoundError), and under Git Bash the output cannot be decoded with the default GBK console encoding (stdout comes back as None). A small helper now scans store/**/*.py with re and reports hits in the same path:line:text form. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Context
tests/test_no_user_info.pyhas two tests that search thestore/directory:test_store_no_forbidden_dict_keysandtest_store_no_creator_orm_imports. These tests rungrep -rnEthroughsubprocess.Problem
On Windows, these two tests fail. The failure does not come from the code under test.
grepcommand.subprocess.runraisesFileNotFoundError.grepis available. But Python decodes the output with the console encoding (GBK on Chinese Windows). The decode fails,out.stdoutisNone, and the test raisesAttributeError.Thus, on Windows, these tests cannot find forbidden keys in
store/.Change
Add a helper,
_grep_store(pattern). The helper reads eachstore/**/*.pyfile as UTF-8 and searches each line withre. It gives each hit aspath:line:text, asgrep -rndoes. The two tests use this helper. The patterns and the assertions do not change.store/contains only.pyfiles, so the helper searches the same files asgrep -r.Test
In PowerShell, on
main:FileNotFoundError.The helper also finds hits when they exist. In a branch that writes
"user_id":instore/, the test fails and shows each line.🤖 Generated with Claude Code