|
7 | 7 | importos.pathasosp
|
8 | 8 | frompathlibimportPath
|
9 | 9 | importsubprocess
|
10 |
| -importtempfile |
11 | 10 |
|
12 | 11 | fromgit.objectsimportTree,Blob
|
13 | 12 | fromgit.utilimportcwd
|
14 |
| -fromtest.libimportTestBase |
| 13 | +fromtest.libimportTestBase,with_rw_directory |
15 | 14 |
|
16 | 15 |
|
17 | 16 | classTestTree(TestBase):
|
@@ -43,36 +42,35 @@ def test_serializable(self):
|
43 | 42 | testtree._deserialize(stream)
|
44 | 43 | # END for each item in tree
|
45 | 44 |
|
46 |
| -@staticmethod |
47 |
| -def_get_git_ordered_files(): |
| 45 | +@with_rw_directory |
| 46 | +def_get_git_ordered_files(self,rw_dir): |
48 | 47 | """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 |
| -withcwd(tdir): |
64 |
| -# Prepare the repository. |
65 |
| -subprocess.run(["git","init","-q"],check=True) |
66 |
| -subprocess.run(["git","add","."],check=True) |
67 |
| -subprocess.run(["git","commit","-m","c1"],check=True) |
68 |
| - |
69 |
| -# Get git output from which an ordered file list can be parsed. |
70 |
| -rev_parse_command= ["git","rev-parse","HEAD^{tree}"] |
71 |
| -tree_hash=subprocess.check_output(rev_parse_command).decode().strip() |
72 |
| -cat_file_command= ["git","cat-file","-p",tree_hash] |
73 |
| -cat_file_output=subprocess.check_output(cat_file_command).decode() |
74 |
| - |
75 |
| -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] |
76 | 74 |
|
77 | 75 | deftest_tree_modifier_ordering(self):
|
78 | 76 | """TreeModifier.set_done() sorts files in the same order git does."""
|
|