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

Commitb780a8c

Browse files
committed
Tweak@with_rw_directory and go back to using it
The situation with test_tree_modifier_ordering's helper, where itmakes sense to wrap the helper itself with `@with_rw_directory`while still deleting the temporary directory as soon as the helperitself finishes, in order to make clear that the test itself doesnot use the temporary directory that the helper used, only occursin one place in GitPython's tests as far as I know.In particular, all other places where `@with_rw_directory` wasactually in use are test methods, not helper methods, and the waythe decorator would have its wrapper log on failure documented thedecorated method as a test. Mainly for that reason, I had backedaway from using `@with_rw_directory` here.But the test code seems much easier to understand when it is usedcompared to other approaches. While it also has the disadvantage ofdoing a gc.collect that is unnecessary here, this is not the onlyplace what that is done.This commit brings back the test_tree_modifier_ordering helperimplementation that uses `@with_rw_directory`, while also modifyingthe logging logic in `@with_rw_directory` slightly, so that whenthe decorated method is not named as a test, it is referred to as a"Helper" rather than a "Test" in the failure log message.
1 parent0114a99 commitb780a8c

File tree

2 files changed

+32
-36
lines changed

2 files changed

+32
-36
lines changed

‎test/lib/helper.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ def wrapper(self, *args, **kwargs):
9797
returnfunc(self,path,*args,**kwargs)
9898
exceptException:
9999
_logger.info(
100-
"Test %s.%s failed, output is at %r\n",
100+
"%s %s.%s failed, output is at %r\n",
101+
"Test"iffunc.__name__.startswith("test_")else"Helper",
101102
type(self).__name__,
102103
func.__name__,
103104
path,

‎test/test_tree.py

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

1211
fromgit.objectsimportTree,Blob
13-
fromgit.utilimportcwd,rmtree
14-
fromtest.libimportTestBase
12+
fromgit.utilimportcwd
13+
fromtest.libimportTestBase,with_rw_directory
1514

1615

1716
classTestTree(TestBase):
@@ -43,39 +42,35 @@ def test_serializable(self):
4342
testtree._deserialize(stream)
4443
# END for each item in tree
4544

46-
@staticmethod
47-
def_get_git_ordered_files():
45+
@with_rw_directory
46+
def_get_git_ordered_files(self,rw_dir):
4847
"""Get files as git orders them, to compare in test_tree_modifier_ordering."""
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]
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]
7974

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp