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

Commit9caf3ae

Browse files
authored
Merge pull request#1825 from EliahKagan/tree-test
Keep temp files out of project dir and improve cleanup
2 parents2613421 +b780a8c commit9caf3ae

File tree

2 files changed

+37
-28
lines changed

2 files changed

+37
-28
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: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/
55

66
fromioimportBytesIO
7-
8-
fromgit.objectsimportTree,Blob
9-
fromtest.libimportTestBase
10-
11-
importos
127
importos.pathasosp
8+
frompathlibimportPath
139
importsubprocess
1410

11+
fromgit.objectsimportTree,Blob
12+
fromgit.utilimportcwd
13+
fromtest.libimportTestBase,with_rw_directory
14+
1515

1616
classTestTree(TestBase):
1717
deftest_serializable(self):
@@ -42,28 +42,39 @@ def test_serializable(self):
4242
testtree._deserialize(stream)
4343
# END for each item in tree
4444

45-
deftest_tree_modifier_ordering(self):
46-
defsetup_git_repository_and_get_ordered_files():
47-
os.mkdir("tmp")
48-
os.chdir("tmp")
45+
@with_rw_directory
46+
def_get_git_ordered_files(self,rw_dir):
47+
"""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.
4963
subprocess.run(["git","init","-q"],check=True)
50-
os.mkdir("file")
51-
forfilenamein [
52-
"bin",
53-
"bin.d",
54-
"file.to",
55-
"file.toml",
56-
"file.toml.bin",
57-
"file0",
58-
"file/a",
59-
]:
60-
open(filename,"a").close()
61-
6264
subprocess.run(["git","add","."],check=True)
6365
subprocess.run(["git","commit","-m","c1"],check=True)
64-
tree_hash=subprocess.check_output(["git","rev-parse","HEAD^{tree}"]).decode().strip()
65-
cat_file_output=subprocess.check_output(["git","cat-file","-p",tree_hash]).decode()
66-
return [line.split()[-1]forlineincat_file_output.split("\n")ifline]
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]
74+
75+
deftest_tree_modifier_ordering(self):
76+
"""TreeModifier.set_done() sorts files in the same order git does."""
77+
git_file_names_in_order=self._get_git_ordered_files()
6778

6879
hexsha="6c1faef799095f3990e9970bc2cb10aa0221cf9c"
6980
roottree=self.rorepo.tree(hexsha)
@@ -92,9 +103,6 @@ def names_in_mod_cache():
92103
here=file_names_in_order()
93104
return [eforeinaifeinhere]
94105

95-
git_file_names_in_order=setup_git_repository_and_get_ordered_files()
96-
os.chdir("..")
97-
98106
mod.set_done()
99107
assertnames_in_mod_cache()==git_file_names_in_order,"set_done() performs git-sorting"
100108

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp