From e38699bd9583c2ee9eb1436f3fc640cf97462722 Mon Sep 17 00:00:00 2001 From: iannucci Date: Mon, 15 Aug 2016 17:32:31 -0700 Subject: [PATCH] Fix broken git tests on mac. Unfortunately there's a bunch of other broken stuff, but it's something :/ R=agable@chromium.org, thakis@chromium.org BUG=607344 Review-Url: https://codereview.chromium.org/2244023003 --- git_common.py | 12 +++++++----- testing_support/git_test_utils.py | 2 +- tests/git_common_test.py | 17 +++++++++++------ 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/git_common.py b/git_common.py index 720840cc5..0fd1e7f6c 100644 --- a/git_common.py +++ b/git_common.py @@ -756,14 +756,16 @@ def get_dirty_files(): def is_dirty_git_tree(cmd): + w = lambda s: sys.stderr.write(s+"\n") + dirty = get_dirty_files() if dirty: - print 'Cannot %s with a dirty tree. '\ - 'Commit, freeze or stash your changes first.' % cmd - print 'Uncommitted files: (git diff-index --name-status HEAD)' - print dirty[:4096] + w('Cannot %s with a dirty tree. Commit, freeze or stash your changes first.' + % cmd) + w('Uncommitted files: (git diff-index --name-status HEAD)') + w(dirty[:4096]) if len(dirty) > 4096: # pragma: no cover - print '... (run "git diff-index --name-status HEAD" to see full output).' + w('... (run "git diff-index --name-status HEAD" to see full output).') return True return False diff --git a/testing_support/git_test_utils.py b/testing_support/git_test_utils.py index 1e7065a22..3fe2b1e2c 100644 --- a/testing_support/git_test_utils.py +++ b/testing_support/git_test_utils.py @@ -283,7 +283,7 @@ class GitRepo(object): Args: schema - An instance of GitRepoSchema """ - self.repo_path = tempfile.mkdtemp(dir=self.BASE_TEMP_DIR) + self.repo_path = os.path.realpath(tempfile.mkdtemp(dir=self.BASE_TEMP_DIR)) self.commit_map = {} self._date = datetime.datetime(1970, 1, 1, tzinfo=UTC) diff --git a/tests/git_common_test.py b/tests/git_common_test.py index 4b6a1d269..c33e9bed8 100755 --- a/tests/git_common_test.py +++ b/tests/git_common_test.py @@ -333,7 +333,6 @@ class GitReadOnlyFunctionsTest(git_test_utils.GitRepoReadOnlyTestBase, def testRepoRoot(self): def cd_and_repo_root(path): - print(os.getcwd()) os.chdir(path) return self.gc.repo_root() @@ -649,10 +648,18 @@ class GitMutableStructuredTest(git_test_utils.GitRepoReadWriteTestBase, ]) def testIsGitTreeDirty(self): - self.assertEquals(False, self.repo.run(self.gc.is_dirty_git_tree, 'foo')) + retval = [] + self.repo.capture_stdio( + lambda: retval.append(self.repo.run(self.gc.is_dirty_git_tree, 'foo'))) + + self.assertEquals(False, retval[0]) self.repo.open('test.file', 'w').write('test data') self.repo.git('add', 'test.file') - self.assertEquals(True, self.repo.run(self.gc.is_dirty_git_tree, 'foo')) + + retval = [] + self.repo.capture_stdio( + lambda: retval.append(self.repo.run(self.gc.is_dirty_git_tree, 'foo'))) + self.assertEquals(True, retval[0]) def testSquashBranch(self): self.repo.git('checkout', 'branch_K') @@ -895,10 +902,8 @@ class GitMakeWorkdir(git_test_utils.GitRepoReadOnlyTestBase, GitCommonTestBase): A """ + @unittest.skipIf(not hasattr(os, 'symlink'), "OS doesn't support symlink") def testMakeWorkdir(self): - if not hasattr(os, 'symlink'): - return - workdir = os.path.join(self._tempdir, 'workdir') self.gc.make_workdir(os.path.join(self.repo.repo_path, '.git'), os.path.join(workdir, '.git'))