Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0114a99

Browse files
committed
Use more ligtweight approach to guarantee deletion
This changes from `@with_rw_directory` back to TemporaryDirectory,but calls git.util.rmtree on the repsitory's .git directory wheresome read-only files otherwise cause TemporaryDirectory's cleanupto raise PermissionError on Windows in Python 3.7.This avoids the gc.collect that is known not to be necessary inthis speciifc situation, as well as the problem that, if operatingin the temporary directory did fail, then name of the helper wouldbe logged as the name of the test where the failure occurred. Butthis has the disadvantage of making the helper more complex andharder to understand. So this may not be the best approach either.
1 parent90cf4d7 commit0114a99

File tree

1 file changed

+35
-30
lines changed

1 file changed

+35
-30
lines changed

‎test/test_tree.py

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
importos.pathasosp
88
frompathlibimportPath
99
importsubprocess
10+
importtempfile
1011

1112
fromgit.objectsimportTree,Blob
12-
fromgit.utilimportcwd
13-
fromtest.libimportTestBase,with_rw_directory
13+
fromgit.utilimportcwd,rmtree
14+
fromtest.libimportTestBase
1415

1516

1617
classTestTree(TestBase):
@@ -42,35 +43,39 @@ def test_serializable(self):
4243
testtree._deserialize(stream)
4344
# END for each item in tree
4445

45-
@with_rw_directory
46-
def_get_git_ordered_files(self,rw_dir):
46+
@staticmethod
47+
def_get_git_ordered_files():
4748
"""Get files as git orders them, to compare in test_tree_modifier_ordering."""
48-
# Create directory contents.
49-
Path(rw_dir,"file").mkdir()
50-
forfilenamein (
51-
"bin",
52-
"bin.d",
53-
"file.to",
54-
"file.toml",
55-
"file.toml.bin",
56-
"file0",
57-
):
58-
Path(rw_dir,filename).touch()
59-
Path(rw_dir,"file","a").touch()
60-
61-
withcwd(rw_dir):
62-
# Prepare the repository.
63-
subprocess.run(["git","init","-q"],check=True)
64-
subprocess.run(["git","add","."],check=True)
65-
subprocess.run(["git","commit","-m","c1"],check=True)
66-
67-
# Get git output from which an ordered file list can be parsed.
68-
rev_parse_command= ["git","rev-parse","HEAD^{tree}"]
69-
tree_hash=subprocess.check_output(rev_parse_command).decode().strip()
70-
cat_file_command= ["git","cat-file","-p",tree_hash]
71-
cat_file_output=subprocess.check_output(cat_file_command).decode()
72-
73-
return [line.split()[-1]forlineincat_file_output.split("\n")ifline]
49+
withtempfile.TemporaryDirectory()astdir:
50+
# Create directory contents.
51+
Path(tdir,"file").mkdir()
52+
forfilenamein (
53+
"bin",
54+
"bin.d",
55+
"file.to",
56+
"file.toml",
57+
"file.toml.bin",
58+
"file0",
59+
):
60+
Path(tdir,filename).touch()
61+
Path(tdir,"file","a").touch()
62+
63+
try:
64+
withcwd(tdir):
65+
# Prepare the repository.
66+
subprocess.run(["git","init","-q"],check=True)
67+
subprocess.run(["git","add","."],check=True)
68+
subprocess.run(["git","commit","-m","c1"],check=True)
69+
70+
# Get git output from which an ordered file list can be parsed.
71+
rev_parse_command= ["git","rev-parse","HEAD^{tree}"]
72+
tree_hash=subprocess.check_output(rev_parse_command).decode().strip()
73+
cat_file_command= ["git","cat-file","-p",tree_hash]
74+
cat_file_output=subprocess.check_output(cat_file_command).decode()
75+
finally:
76+
rmtree(Path(tdir,".git"))
77+
78+
return [line.split()[-1]forlineincat_file_output.split("\n")ifline]
7479

7580
deftest_tree_modifier_ordering(self):
7681
"""TreeModifier.set_done() sorts files in the same order git does."""

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp