def assert_roundtrip_golden(self, env, make_view_from_repo_path, golden_file_name=None, extra_invariant_funcs=()): # .write() / .apply() cycle leaves repository (and index in particular) # unchanged def invariant(): diff = env.cmd(["git", "diff"]).stdout_output cached = env.cmd(["git", "diff", "--cached"]).stdout_output diffs = """\ git diff {0} git diff --cached {1} """.format( diff, cached ) if extra_invariant_funcs: extra = "\n".join(str(func()) for func in extra_invariant_funcs) return "\n".join([diffs, extra, ""]) else: return diffs before = invariant() path = trim(env.cmd(["readlink", "-e", "."]).stdout_output, suffix="\n") view = make_view_from_repo_path(path) out = self.make_temp_dir() view.write(env, out) listing = list_tree.ls_tree(out) listing = listing.replace(path, "<repo>") if golden_file_name is not None: self.assert_golden_file(listing, golden_file_name) view.apply(env, out) after = invariant() self.assert_equal_golden(before, after)
def assert_write_golden(self, env, make_view_from_repo_path, golden_file_name): path = trim(env.cmd(["readlink", "-e", "."]).stdout_output, suffix="\n") view = make_view_from_repo_path(path) out = self.make_temp_dir() view.write(env, out) listing = list_tree.ls_tree(out) listing = listing.replace(path, "<repo>") self.assert_golden_file(listing, golden_file_name)
def assert_write_golden(self, env, make_view_from_repo_path, golden_file_name): path = trim(env.cmd(["readlink", "-e", "."]).stdout_output, suffix="\n") view = make_view_from_repo_path(path) out = self.make_temp_dir() view.write(env, out) listing = list_tree.ls_tree(out) listing = listing.replace(path, '<repo>') self.assert_golden_file(listing, golden_file_name)
def assert_roundtrip_golden(self, env, make_view_from_repo_path, golden_file_name=None, extra_invariant_funcs=()): # .write() / .apply() cycle leaves repository (and index in particular) # unchanged def invariant(): diff = env.cmd(["git", "diff"]).stdout_output cached = env.cmd(["git", "diff", "--cached"]).stdout_output diffs = """\ git diff {0} git diff --cached {1} """.format(diff, cached) if extra_invariant_funcs: extra = "\n".join( str(func()) for func in extra_invariant_funcs) return "\n".join([diffs, extra, ""]) else: return diffs before = invariant() path = trim(env.cmd(["readlink", "-e", "."]).stdout_output, suffix="\n") view = make_view_from_repo_path(path) out = self.make_temp_dir() view.write(env, out) listing = list_tree.ls_tree(out) listing = listing.replace(path, '<repo>') if golden_file_name is not None: self.assert_golden_file(listing, golden_file_name) view.apply(env, out) after = invariant() self.assert_equal_golden(before, after)