2 files changed
@@ -97,7 +97,8 @@ def wrapper(self, *args, **kwargs): | |||
| 97 | 97 | return func(self, path, *args, **kwargs) | |
| 98 | 98 | except Exception: | |
| 99 | 99 | _logger.info( | |
| 100 | - "Test %s.%s failed, output is at %r\n", | ||
| 100 | + "%s %s.%s failed, output is at %r\n", | ||
| 101 | + "Test" if func.__name__.startswith("test_") else "Helper", | ||
| 101 | 102 | type(self).__name__, | |
| 102 | 103 | func.__name__, | |
| 103 | 104 | path, | |
@@ -7,11 +7,10 @@ | |||
| 7 | 7 | import os.path as osp | |
| 8 | 8 | from pathlib import Path | |
| 9 | 9 | import subprocess | |
| 10 | - import tempfile | ||
| 11 | 10 | ||
| 12 | 11 | from git.objects import Tree, Blob | |
| 13 | - from git.util import cwd, rmtree | ||
| 14 | - from test.lib import TestBase | ||
| 12 | + from git.util import cwd | ||
| 13 | + from test.lib import TestBase, with_rw_directory | ||
| 15 | 14 | ||
| 16 | 15 | ||
| 17 | 16 | class TestTree(TestBase): | |
@@ -43,39 +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 | - with tempfile.TemporaryDirectory() as tdir: | ||
| 50 | - # Create directory contents. | ||
| 51 | - Path(tdir, "file").mkdir() | ||
| 52 | - for filename in ( | ||
| 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 | - with cwd(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] for line in cat_file_output.split("\n") if line] | ||
| 48 | + # Create directory contents. | ||
| 49 | + Path(rw_dir, "file").mkdir() | ||
| 50 | + for filename in ( | ||
| 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 | + with cwd(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] for line in cat_file_output.split("\n") if line] | ||
| 79 | 74 | ||
| 80 | 75 | def test_tree_modifier_ordering(self): | |
| 81 | 76 | """TreeModifier.set_done() sorts files in the same order git does.""" | |
0 commit comments