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-controller | pull_requests |
| route-action | checks |
| fetch-nonce | v2:527c20d2-b7d4-798a-df5b-7c81cf4484a5 |
| current-catalog-service-hash | 87dc3bc62d9b466312751bfd5f889726f4f1337bdff4e8be7da7c93d6c00a25a |
| request-id | 82EE:2CDBFE:1BC9C7:279BF6:6968AFD8 |
| html-safe-nonce | 1a2270064a9955a8bec25ec54c1fb3cc86b68d01eda1cea43aee63eb9946de97 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MkVFOjJDREJGRToxQkM5Qzc6Mjc5QkY2OjY5NjhBRkQ4IiwidmlzaXRvcl9pZCI6IjM1MTY5NTU1MjQyNDM5NTk3NjgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | f5b7340b22c8c75940d8ab0b6daf512886b3e59ad6efd1d2ffeb2d7113f00b96 |
| hovercard-subject-tag | pull_request:1728173488 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,checks,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | ///pull_requests/show/checks |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/gitpython-developers/GitPython/pull/1825/checks |
| twitter:image | https://avatars.githubusercontent.com/u/1771172?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/1771172?s=400&v=4 |
| og:image:alt | 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... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | fdc7c66bd36a6c12eb8e771e806db863266e573fc299e77f27505a768d4f8a98 |
| turbo-cache-control | no-preview |
| go-import | github.com/gitpython-developers/GitPython git https://github.com/gitpython-developers/GitPython.git |
| octolytics-dimension-user_id | 503709 |
| octolytics-dimension-user_login | gitpython-developers |
| octolytics-dimension-repository_id | 1126087 |
| octolytics-dimension-repository_nwo | gitpython-developers/GitPython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1126087 |
| octolytics-dimension-repository_network_root_nwo | gitpython-developers/GitPython |
| turbo-body-classes | logged-out env-production page-responsive full-width full-width-p-0 |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 3223a6503d318917691422cdadfbe16cd8fb21e5 |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width
URLs of crawlers that visited me.