|
4 | 4 | # 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/
|
5 | 5 |
|
6 | 6 | fromioimportBytesIO
|
7 |
| - |
8 |
| -fromgit.objectsimportTree,Blob |
9 |
| -fromtest.libimportTestBase |
10 |
| - |
11 |
| -importos |
12 | 7 | importos.pathasosp
|
| 8 | +frompathlibimportPath |
13 | 9 | importsubprocess
|
14 | 10 |
|
| 11 | +fromgit.objectsimportTree,Blob |
| 12 | +fromgit.utilimportcwd |
| 13 | +fromtest.libimportTestBase,with_rw_directory |
| 14 | + |
15 | 15 |
|
16 | 16 | classTestTree(TestBase):
|
17 | 17 | deftest_serializable(self):
|
@@ -42,28 +42,39 @@ def test_serializable(self):
|
42 | 42 | testtree._deserialize(stream)
|
43 | 43 | # END for each item in tree
|
44 | 44 |
|
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. |
49 | 63 | 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 |
| - |
62 | 64 | subprocess.run(["git","add","."],check=True)
|
63 | 65 | 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() |
67 | 78 |
|
68 | 79 | hexsha="6c1faef799095f3990e9970bc2cb10aa0221cf9c"
|
69 | 80 | roottree=self.rorepo.tree(hexsha)
|
@@ -92,9 +103,6 @@ def names_in_mod_cache():
|
92 | 103 | here=file_names_in_order()
|
93 | 104 | return [eforeinaifeinhere]
|
94 | 105 |
|
95 |
| -git_file_names_in_order=setup_git_repository_and_get_ordered_files() |
96 |
| -os.chdir("..") |
97 |
| - |
98 | 106 | mod.set_done()
|
99 | 107 | assertnames_in_mod_cache()==git_file_names_in_order,"set_done() performs git-sorting"
|
100 | 108 |
|
|