René's URL Explorer Experiment


Title: Keep temp files out of project dir and improve cleanup by EliahKagan · Pull Request #1825 · gitpython-developers/GitPython · GitHub

Open Graph Title: Keep temp files out of project dir and improve cleanup by EliahKagan · Pull Request #1825 · gitpython-developers/GitPython

X Title: Keep temp files out of project dir and improve cleanup by EliahKagan · Pull Request #1825 · gitpython-developers/GitPython

Description: Fixes #1824 This fixes temporary directory creation and cleanup in test_tree_modifier_ordering, extracts its helper to a separate method, slightly extends @with_rw_directory so it can be used directly on helper methods while still logging accurate descriptions, and uses it to ensure cleanup of the temporary directory that is used by the helper to generate the expected value that the test will compare its results to. Because that decorator was not previously used on any test helper methods, only on test methods, it is not obvious that my use of it on the helper, and my modification to it to properly support such use, is justified. The reason I think it is justified is that we really do want to complete cleanup, including deleting the temporary directory, before beginning to use the code under test, in order to make clear (when reading the code or when debugging tests or inspecting output) that the helper really is just arranging an expected value for the test. There's a little more information in the commit messages, but it's mostly covered by the details in #1824 and this PR description. One important question is whether the new test really still works as a regression test. The answer is yes, as shown by a temporary non-committed revert of 365d44f (the fix in #1799). This is from before the change in this PR: (.venv) ek@Glub:~/repos-wsl/GitPython (main $=)$ git log -1 365d44f50a3d72d7ebfa063b142d2abd4082cfaa commit 365d44f50a3d72d7ebfa063b142d2abd4082cfaa Author: Ethan Date: Mon Jan 15 14:50:43 2024 +0800 fix: treeNotSorted issue (.venv) ek@Glub:~/repos-wsl/GitPython (main $=)$ git revert --no-commit 365d44f50a3d72d7ebfa063b142d2abd4082cfaa (.venv) ek@Glub:~/repos-wsl/GitPython (main +$|REVERTING=)$ pytest --no-cov -vv test/test_tree.py Test session starts (platform: linux, Python 3.12.1, pytest 8.0.0, pytest-sugar 1.0.0) cachedir: .pytest_cache rootdir: /home/ek/repos-wsl/GitPython configfile: pyproject.toml plugins: mock-3.12.0, sugar-1.0.0, cov-4.1.0, instafail-0.5.0 collected 3 items test/test_tree.py::TestTree.test_serializable ✓ 33% ███▍ test/test_tree.py::TestTree.test_traverse ✓ 67% ██████▋ ――――――――――――――――――――――――――――――――――――――――― TestTree.test_tree_modifier_ordering ――――――――――――――――――――――――――――――――――――――――― self = def test_tree_modifier_ordering(self): def setup_git_repository_and_get_ordered_files(): os.mkdir("tmp") os.chdir("tmp") subprocess.run(["git", "init", "-q"], check=True) os.mkdir("file") for filename in [ "bin", "bin.d", "file.to", "file.toml", "file.toml.bin", "file0", "file/a", ]: open(filename, "a").close() subprocess.run(["git", "add", "."], check=True) subprocess.run(["git", "commit", "-m", "c1"], check=True) tree_hash = subprocess.check_output(["git", "rev-parse", "HEAD^{tree}"]).decode().strip() cat_file_output = subprocess.check_output(["git", "cat-file", "-p", tree_hash]).decode() return [line.split()[-1] for line in cat_file_output.split("\n") if line] hexsha = "6c1faef799095f3990e9970bc2cb10aa0221cf9c" roottree = self.rorepo.tree(hexsha) blob_mode = Tree.blob_id << 12 tree_mode = Tree.tree_id << 12 files_in_desired_order = [ (blob_mode, "bin"), (blob_mode, "bin.d"), (blob_mode, "file.to"), (blob_mode, "file.toml"), (blob_mode, "file.toml.bin"), (blob_mode, "file0"), (tree_mode, "file"), ] mod = roottree.cache for file_mode, file_name in files_in_desired_order: mod.add(hexsha, file_mode, file_name) # end for each file def file_names_in_order(): return [t[1] for t in files_in_desired_order] def names_in_mod_cache(): a = [t[2] for t in mod._cache] here = file_names_in_order() return [e for e in a if e in here] git_file_names_in_order = setup_git_repository_and_get_ordered_files() os.chdir("..") mod.set_done() > assert names_in_mod_cache() == git_file_names_in_order, "set_done() performs git-sorting" E AssertionError: set_done() performs git-sorting E assert ['bin', 'bin.d', 'file', 'file.to', 'file.toml', 'file.toml.bin', 'file0'] == ['bin', 'bin.d', 'file.to', 'file.toml', 'file.toml.bin', 'file', 'file0'] E E At index 2 diff: 'file' != 'file.to' E E Full diff: E [ E 'bin', E 'bin.d', E + 'file', E 'file.to', E 'file.toml', E 'file.toml.bin', E - 'file', E 'file0', E ] test/test_tree.py:99: AssertionError ------------------------------------------------- Captured stdout call ------------------------------------------------- [main (root-commit) ef03b86] c1 7 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 bin create mode 100644 bin.d create mode 100644 file.to create mode 100644 file.toml create mode 100644 file.toml.bin create mode 100644 file/a create mode 100644 file0 test/test_tree.py::TestTree.test_tree_modifier_ordering ⨯ 100% ██████████ =============================================== short test summary info ================================================ FAILED test/test_tree.py::TestTree::test_tree_modifier_ordering - AssertionError: set_done() performs git-sorting Results (0.24s): 2 passed 1 failed - test/test_tree.py:45 TestTree.test_tree_modifier_ordering (.venv) ek@Glub:~/repos-wsl/GitPython (main +$%|REVERTING=)$ rm -rf tmp (.venv) ek@Glub:~/repos-wsl/GitPython (main +$|REVERTING=)$ git revert --abort (.venv) ek@Glub:~/repos-wsl/GitPython (main $=)$ pytest --no-cov -vv test/test_tree.py Test session starts (platform: linux, Python 3.12.1, pytest 8.0.0, pytest-sugar 1.0.0) cachedir: .pytest_cache rootdir: /home/ek/repos-wsl/GitPython configfile: pyproject.toml plugins: mock-3.12.0, sugar-1.0.0, cov-4.1.0, instafail-0.5.0 collected 3 items test/test_tree.py::TestTree.test_serializable ✓ 33% ███▍ test/test_tree.py::TestTree.test_traverse ✓ 67% ██████▋ test/test_tree.py::TestTree.test_tree_modifier_ordering ✓ 100% ██████████ Results (0.29s): 3 passed (.venv) ek@Glub:~/repos-wsl/GitPython (main $%=)$ rm -rf tmp (.venv) ek@Glub:~/repos-wsl/GitPython (main $=)$ And this is from after the changes in this PR: (.venv) ek@Glub:~/repos-wsl/GitPython (tree-test $=)$ git status On branch tree-test Your branch is up to date with 'origin/tree-test'. nothing to commit, working tree clean (.venv) ek@Glub:~/repos-wsl/GitPython (tree-test $=)$ git revert --no-commit 365d44f50a3d72d7ebfa063b142d2abd4082cfaa (.venv) ek@Glub:~/repos-wsl/GitPython (tree-test +$|REVERTING=)$ pytest --no-cov -vv test/test_tree.py Test session starts (platform: linux, Python 3.12.1, pytest 8.0.0, pytest-sugar 1.0.0) cachedir: .pytest_cache rootdir: /home/ek/repos-wsl/GitPython configfile: pyproject.toml plugins: mock-3.12.0, sugar-1.0.0, cov-4.1.0, instafail-0.5.0 collected 3 items test/test_tree.py::TestTree.test_serializable ✓ 33% ███▍ test/test_tree.py::TestTree.test_traverse ✓ 67% ██████▋ ――――――――――――――――――――――――――――――――――――――――― TestTree.test_tree_modifier_ordering ――――――――――――――――――――――――――――――――――――――――― self = def test_tree_modifier_ordering(self): """TreeModifier.set_done() sorts files in the same order git does.""" git_file_names_in_order = self._get_git_ordered_files() hexsha = "6c1faef799095f3990e9970bc2cb10aa0221cf9c" roottree = self.rorepo.tree(hexsha) blob_mode = Tree.blob_id << 12 tree_mode = Tree.tree_id << 12 files_in_desired_order = [ (blob_mode, "bin"), (blob_mode, "bin.d"), (blob_mode, "file.to"), (blob_mode, "file.toml"), (blob_mode, "file.toml.bin"), (blob_mode, "file0"), (tree_mode, "file"), ] mod = roottree.cache for file_mode, file_name in files_in_desired_order: mod.add(hexsha, file_mode, file_name) # end for each file def file_names_in_order(): return [t[1] for t in files_in_desired_order] def names_in_mod_cache(): a = [t[2] for t in mod._cache] here = file_names_in_order() return [e for e in a if e in here] mod.set_done() > assert names_in_mod_cache() == git_file_names_in_order, "set_done() performs git-sorting" E AssertionError: set_done() performs git-sorting E assert ['bin', 'bin.d', 'file', 'file.to', 'file.toml', 'file.toml.bin', 'file0'] == ['bin', 'bin.d', 'file.to', 'file.toml', 'file.toml.bin', 'file', 'file0'] E E At index 2 diff: 'file' != 'file.to' E E Full diff: E [ E 'bin', E 'bin.d', E + 'file', E 'file.to', E 'file.toml', E 'file.toml.bin', E - 'file', E 'file0', E ] test/test_tree.py:107: AssertionError ------------------------------------------------- Captured stdout call ------------------------------------------------- [main (root-commit) 391489e] c1 7 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 bin create mode 100644 bin.d create mode 100644 file.to create mode 100644 file.toml create mode 100644 file.toml.bin create mode 100644 file/a create mode 100644 file0 test/test_tree.py::TestTree.test_tree_modifier_ordering ⨯ 100% ██████████ =============================================== short test summary info ================================================ FAILED test/test_tree.py::TestTree::test_tree_modifier_ordering - AssertionError: set_done() performs git-sorting Results (0.48s): 2 passed 1 failed - test/test_tree.py:75 TestTree.test_tree_modifier_ordering (.venv) ek@Glub:~/repos-wsl/GitPython (tree-test +$|REVERTING=)$ git revert --abort (.venv) ek@Glub:~/repos-wsl/GitPython (tree-test $=)$ pytest --no-cov -vv test/test_tree.py Test session starts (platform: linux, Python 3.12.1, pytest 8.0.0, pytest-sugar 1.0.0) cachedir: .pytest_cache rootdir: /home/ek/repos-wsl/GitPython configfile: pyproject.toml plugins: mock-3.12.0, sugar-1.0.0, cov-4.1.0, instafail-0.5.0 collected 3 items test/test_tree.py::TestTree.test_serializable ✓ 33% ███▍ test/test_tree.py::TestTree.test_traverse ✓ 67% ██████▋ test/test_tree.py::TestTree.test_tree_modifier_ordering ✓ 100% ██████████ Results (0.25s): 3 passed (.venv) ek@Glub:~/repos-wsl/GitPython (tree-test $=)$ Note that they fail the same way, as desired, when the original bug is temporarily brought back--in particular, see the file list order diff under "Full diff" in each run--and pass when the bugfix is applied.

Open Graph Description: Fixes #1824 This fixes temporary directory creation and cleanup in test_tree_modifier_ordering, extracts its helper to a separate method, slightly extends @with_rw_directory so it can be used direc...

X Description: Fixes #1824 This fixes temporary directory creation and cleanup in test_tree_modifier_ordering, extracts its helper to a separate method, slightly extends @with_rw_directory so it can be used direc...

Opengraph URL: https://github.com/gitpython-developers/GitPython/pull/1825

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/checks(.:format)
route-controllerpull_requests
route-actionchecks
fetch-noncev2:527c20d2-b7d4-798a-df5b-7c81cf4484a5
current-catalog-service-hash87dc3bc62d9b466312751bfd5f889726f4f1337bdff4e8be7da7c93d6c00a25a
request-id82EE:2CDBFE:1BC9C7:279BF6:6968AFD8
html-safe-nonce1a2270064a9955a8bec25ec54c1fb3cc86b68d01eda1cea43aee63eb9946de97
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MkVFOjJDREJGRToxQkM5Qzc6Mjc5QkY2OjY5NjhBRkQ4IiwidmlzaXRvcl9pZCI6IjM1MTY5NTU1MjQyNDM5NTk3NjgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacf5b7340b22c8c75940d8ab0b6daf512886b3e59ad6efd1d2ffeb2d7113f00b96
hovercard-subject-tagpull_request:1728173488
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,checks,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/checks
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/gitpython-developers/GitPython/pull/1825/checks
twitter:imagehttps://avatars.githubusercontent.com/u/1771172?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/1771172?s=400&v=4
og:image:altFixes #1824 This fixes temporary directory creation and cleanup in test_tree_modifier_ordering, extracts its helper to a separate method, slightly extends @with_rw_directory so it can be used direc...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Nonefdc7c66bd36a6c12eb8e771e806db863266e573fc299e77f27505a768d4f8a98
turbo-cache-controlno-preview
go-importgithub.com/gitpython-developers/GitPython git https://github.com/gitpython-developers/GitPython.git
octolytics-dimension-user_id503709
octolytics-dimension-user_logingitpython-developers
octolytics-dimension-repository_id1126087
octolytics-dimension-repository_nwogitpython-developers/GitPython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id1126087
octolytics-dimension-repository_network_root_nwogitpython-developers/GitPython
turbo-body-classeslogged-out env-production page-responsive full-width full-width-p-0
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release3223a6503d318917691422cdadfbe16cd8fb21e5
ui-targetcanary-1
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/gitpython-developers/GitPython/pull/1825/checks#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgitpython-developers%2FGitPython%2Fpull%2F1825%2Fchecks
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgitpython-developers%2FGitPython%2Fpull%2F1825%2Fchecks
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Fchecks&source=header-repo&source_repo=gitpython-developers%2FGitPython
Reloadhttps://github.com/gitpython-developers/GitPython/pull/1825/checks
Reloadhttps://github.com/gitpython-developers/GitPython/pull/1825/checks
Reloadhttps://github.com/gitpython-developers/GitPython/pull/1825/checks
gitpython-developers https://github.com/gitpython-developers
GitPythonhttps://github.com/gitpython-developers/GitPython
Please reload this pagehttps://github.com/gitpython-developers/GitPython/pull/1825/checks
Notifications https://github.com/login?return_to=%2Fgitpython-developers%2FGitPython
Fork 964 https://github.com/login?return_to=%2Fgitpython-developers%2FGitPython
Star 5k https://github.com/login?return_to=%2Fgitpython-developers%2FGitPython
Code https://github.com/gitpython-developers/GitPython
Issues 169 https://github.com/gitpython-developers/GitPython/issues
Pull requests 8 https://github.com/gitpython-developers/GitPython/pulls
Discussions https://github.com/gitpython-developers/GitPython/discussions
Actions https://github.com/gitpython-developers/GitPython/actions
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/gitpython-developers/GitPython/security
Please reload this pagehttps://github.com/gitpython-developers/GitPython/pull/1825/checks
Insights https://github.com/gitpython-developers/GitPython/pulse
Code https://github.com/gitpython-developers/GitPython
Issues https://github.com/gitpython-developers/GitPython/issues
Pull requests https://github.com/gitpython-developers/GitPython/pulls
Discussions https://github.com/gitpython-developers/GitPython/discussions
Actions https://github.com/gitpython-developers/GitPython/actions
Security https://github.com/gitpython-developers/GitPython/security
Insights https://github.com/gitpython-developers/GitPython/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fgitpython-developers%2FGitPython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fgitpython-developers%2FGitPython%2Fissues%2Fnew%2Fchoose
Byronhttps://github.com/Byron
gitpython-developers:mainhttps://github.com/gitpython-developers/GitPython/tree/main
EliahKagan:tree-testhttps://github.com/EliahKagan/GitPython/tree/tree-test
Conversation 1 https://github.com/gitpython-developers/GitPython/pull/1825
Commits 4 https://github.com/gitpython-developers/GitPython/pull/1825/commits
Checks 0 https://github.com/gitpython-developers/GitPython/pull/1825/checks
Files changed https://github.com/gitpython-developers/GitPython/pull/1825/files
Please reload this pagehttps://github.com/gitpython-developers/GitPython/pull/1825/checks
Please reload this pagehttps://github.com/gitpython-developers/GitPython/pull/1825/checks
Keep temp files out of project dir and improve cleanup https://github.com/gitpython-developers/GitPython/pull/1825/checks#top
Please reload this pagehttps://github.com/gitpython-developers/GitPython/pull/1825/checks
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.