Refactoring: Use fake cwd in release script tests.
authormachenbach@chromium.org <machenbach@chromium.org>
Fri, 19 Sep 2014 13:37:34 +0000 (13:37 +0000)
committermachenbach@chromium.org <machenbach@chromium.org>
Fri, 19 Sep 2014 13:37:34 +0000 (13:37 +0000)
TEST=script_test.py
R=tandrii@chromium.org
TBR=jarin@chromium.org

Review URL: https://codereview.chromium.org/585893002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24086 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

tools/push-to-trunk/auto_push.py
tools/push-to-trunk/auto_tag.py
tools/push-to-trunk/chromium_roll.py
tools/push-to-trunk/common_includes.py
tools/push-to-trunk/merge_to_branch.py
tools/push-to-trunk/push_to_trunk.py
tools/push-to-trunk/releases.py
tools/push-to-trunk/test_scripts.py

index aeaea80..5a061f6 100755 (executable)
@@ -40,7 +40,6 @@ SETTINGS_LOCATION = "SETTINGS_LOCATION"
 
 CONFIG = {
   PERSISTFILE_BASENAME: "/tmp/v8-auto-push-tempfile",
-  DOT_GIT_LOCATION: ".git",
   SETTINGS_LOCATION: "~/.auto-roll",
 }
 
@@ -51,7 +50,7 @@ class Preparation(Step):
   MESSAGE = "Preparation."
 
   def RunStep(self):
-    self.InitialEnvironmentChecks()
+    self.InitialEnvironmentChecks(self.default_cwd)
     self.CommonPrepare()
 
 
index 6beaaff..007a50d 100755 (executable)
@@ -11,7 +11,6 @@ from common_includes import *
 CONFIG = {
   BRANCHNAME: "auto-tag-v8",
   PERSISTFILE_BASENAME: "/tmp/v8-auto-tag-tempfile",
-  DOT_GIT_LOCATION: ".git",
   VERSION_FILE: "src/version.cc",
 }
 
index c09d939..35603a2 100755 (executable)
@@ -13,7 +13,6 @@ CHROMIUM = "CHROMIUM"
 
 CONFIG = {
   PERSISTFILE_BASENAME: "/tmp/v8-chromium-roll-tempfile",
-  DOT_GIT_LOCATION: ".git",
 }
 
 
@@ -43,7 +42,7 @@ class SwitchChromium(Step):
     self["v8_path"] = os.getcwd()
     cwd = self._options.chromium
     os.chdir(cwd)
-    self.InitialEnvironmentChecks()
+    self.InitialEnvironmentChecks(cwd)
     # Check for a clean workdir.
     if not self.GitIsWorkdirClean(cwd=cwd):  # pragma: no cover
       self.Die("Workspace is not clean. Please commit or undo your changes.")
index 5f2eff4..d33c539 100644 (file)
@@ -47,7 +47,6 @@ from git_recipes import GitFailedException
 
 PERSISTFILE_BASENAME = "PERSISTFILE_BASENAME"
 BRANCHNAME = "BRANCHNAME"
-DOT_GIT_LOCATION = "DOT_GIT_LOCATION"
 VERSION_FILE = "VERSION_FILE"
 CHANGELOG_FILE = "CHANGELOG_FILE"
 CHANGELOG_ENTRY_FILE = "CHANGELOG_ENTRY_FILE"
@@ -414,9 +413,9 @@ class Step(GitRecipesMixin):
           msg = "Can't continue. Please delete branch %s and try again." % name
           self.Die(msg)
 
-  def InitialEnvironmentChecks(self):
+  def InitialEnvironmentChecks(self, cwd):
     # Cancel if this is not a git checkout.
-    if not os.path.exists(self._config[DOT_GIT_LOCATION]):  # pragma: no cover
+    if not os.path.exists(os.path.join(cwd, ".git")):  # pragma: no cover
       self.Die("This is not a git checkout, this script won't work for you.")
 
     # Cancel if EDITOR is unset or not executable.
index f6e0bb0..ec06f9c 100755 (executable)
@@ -41,7 +41,6 @@ CONFIG = {
   PERSISTFILE_BASENAME: "/tmp/v8-merge-to-branch-tempfile",
   ALREADY_MERGING_SENTINEL_FILE:
       "/tmp/v8-merge-to-branch-tempfile-already-merging",
-  DOT_GIT_LOCATION: ".git",
   VERSION_FILE: "src/version.cc",
   TEMPORARY_PATCH_FILE: "/tmp/v8-prepare-merge-tempfile-temporary-patch",
   COMMITMSG_FILE: "/tmp/v8-prepare-merge-tempfile-commitmsg",
@@ -60,7 +59,7 @@ class Preparation(Step):
         self.Die("A merge is already in progress")
     open(self.Config(ALREADY_MERGING_SENTINEL_FILE), "a").close()
 
-    self.InitialEnvironmentChecks()
+    self.InitialEnvironmentChecks(self.default_cwd)
     if self._options.revert_bleeding_edge:
       self["merge_to_branch"] = "bleeding_edge"
     elif self._options.branch:
index 5902f04..70aa801 100755 (executable)
@@ -40,7 +40,6 @@ CONFIG = {
   BRANCHNAME: "prepare-push",
   TRUNKBRANCH: "trunk-push",
   PERSISTFILE_BASENAME: "/tmp/v8-push-to-trunk-tempfile",
-  DOT_GIT_LOCATION: ".git",
   VERSION_FILE: "src/version.cc",
   CHANGELOG_FILE: "ChangeLog",
   CHANGELOG_ENTRY_FILE: "/tmp/v8-push-to-trunk-tempfile-changelog-entry",
@@ -56,7 +55,7 @@ class Preparation(Step):
   MESSAGE = "Preparation."
 
   def RunStep(self):
-    self.InitialEnvironmentChecks()
+    self.InitialEnvironmentChecks(self.default_cwd)
     self.CommonPrepare()
 
     if(self["current_branch"] == self.Config(TRUNKBRANCH)
index 21eb462..f2d9856 100755 (executable)
@@ -25,7 +25,6 @@ CHROMIUM = "CHROMIUM"
 CONFIG = {
   BRANCHNAME: "retrieve-v8-releases",
   PERSISTFILE_BASENAME: "/tmp/v8-releases-tempfile",
-  DOT_GIT_LOCATION: ".git",
   VERSION_FILE: "src/version.cc",
 }
 
index e1f483b..61d98a8 100644 (file)
@@ -56,11 +56,10 @@ from auto_tag import AutoTag
 
 
 TEST_CONFIG = {
-  "DEFAULT_CWD": "[DEFAULT_CWD]",
+  "DEFAULT_CWD": None,
   BRANCHNAME: "test-prepare-push",
   TRUNKBRANCH: "test-trunk-push",
   PERSISTFILE_BASENAME: "/tmp/test-v8-push-to-trunk-tempfile",
-  DOT_GIT_LOCATION: None,
   VERSION_FILE: None,
   CHANGELOG_FILE: None,
   CHANGELOG_ENTRY_FILE: "/tmp/test-v8-push-to-trunk-tempfile-changelog-entry",
@@ -259,7 +258,7 @@ def Cmd(*args, **kwargs):
     "args": args,
     "ret": args[-1],
     "cb": kwargs.get("cb"),
-    "cwd": kwargs.get("cwd", "[DEFAULT_CWD]"),
+    "cwd": kwargs.get("cwd", TEST_CONFIG["DEFAULT_CWD"]),
   }
 
 
@@ -424,6 +423,7 @@ class ScriptTest(unittest.TestCase):
     self._mock = SimpleMock()
     self._tmp_files = []
     self._state = {}
+    TEST_CONFIG["DEFAULT_CWD"] = self.MakeEmptyTempDirectory()
 
   def tearDown(self):
     if os.path.exists(TEST_CONFIG[PERSISTFILE_BASENAME]):
@@ -483,12 +483,12 @@ class ScriptTest(unittest.TestCase):
     self.assertEquals("some_branch", self._state["current_branch"])
 
   def testInitialEnvironmentChecks(self):
-    TEST_CONFIG[DOT_GIT_LOCATION] = self.MakeEmptyTempFile()
+    TextToFile("", os.path.join(TEST_CONFIG["DEFAULT_CWD"], ".git"))
     os.environ["EDITOR"] = "vi"
     self.Expect([
       Cmd("which vi", "/usr/bin/vi"),
     ])
-    self.MakeStep().InitialEnvironmentChecks()
+    self.MakeStep().InitialEnvironmentChecks(TEST_CONFIG["DEFAULT_CWD"])
 
   def testReadAndPersistVersion(self):
     TEST_CONFIG[VERSION_FILE] = self.MakeEmptyTempFile()
@@ -681,7 +681,7 @@ Performance and stability improvements on all platforms."""
     self._TestSquashCommits(change_log, commit_msg)
 
   def _PushToTrunk(self, force=False, manual=False):
-    TEST_CONFIG[DOT_GIT_LOCATION] = self.MakeEmptyTempFile()
+    TextToFile("", os.path.join(TEST_CONFIG["DEFAULT_CWD"], ".git"))
 
     # The version file on bleeding edge has build level 5, while the version
     # file from trunk has build level 4.
@@ -857,8 +857,8 @@ def get_list():
   pass""")
 
     # Setup fake directory structures.
-    TEST_CONFIG[DOT_GIT_LOCATION] = self.MakeEmptyTempFile()
     TEST_CONFIG[CHROMIUM] = self.MakeEmptyTempDirectory()
+    TextToFile("", os.path.join(TEST_CONFIG[CHROMIUM], ".git"))
     chrome_dir = TEST_CONFIG[CHROMIUM]
     os.makedirs(os.path.join(chrome_dir, "v8"))
 
@@ -921,7 +921,7 @@ def get_list():
                                                       AUTO_PUSH_ARGS))
 
   def testAutoPush(self):
-    TEST_CONFIG[DOT_GIT_LOCATION] = self.MakeEmptyTempFile()
+    TextToFile("", os.path.join(TEST_CONFIG["DEFAULT_CWD"], ".git"))
     TEST_CONFIG[SETTINGS_LOCATION] = "~/.doesnotexist"
 
     self.Expect([
@@ -947,7 +947,7 @@ def get_list():
     self.assertEquals("100", state["lkgr"])
 
   def testAutoPushStoppedBySettings(self):
-    TEST_CONFIG[DOT_GIT_LOCATION] = self.MakeEmptyTempFile()
+    TextToFile("", os.path.join(TEST_CONFIG["DEFAULT_CWD"], ".git"))
     TEST_CONFIG[SETTINGS_LOCATION] = self.MakeEmptyTempFile()
     TextToFile("{\"enable_auto_push\": false}", TEST_CONFIG[SETTINGS_LOCATION])
 
@@ -962,7 +962,7 @@ def get_list():
     self.assertRaises(Exception, RunAutoPush)
 
   def testAutoPushStoppedByTreeStatus(self):
-    TEST_CONFIG[DOT_GIT_LOCATION] = self.MakeEmptyTempFile()
+    TextToFile("", os.path.join(TEST_CONFIG["DEFAULT_CWD"], ".git"))
     TEST_CONFIG[SETTINGS_LOCATION] = "~/.doesnotexist"
 
     self.Expect([
@@ -1042,7 +1042,7 @@ deps = {
 
   def testMergeToBranch(self):
     TEST_CONFIG[ALREADY_MERGING_SENTINEL_FILE] = self.MakeEmptyTempFile()
-    TEST_CONFIG[DOT_GIT_LOCATION] = self.MakeEmptyTempFile()
+    TextToFile("", os.path.join(TEST_CONFIG["DEFAULT_CWD"], ".git"))
     TEST_CONFIG[VERSION_FILE] = self.MakeEmptyTempFile()
     self.WriteFakeVersionFile(build=5)
     os.environ["EDITOR"] = "vi"
@@ -1226,7 +1226,6 @@ git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3456 0039-1c4b
     TEST_CONFIG[VERSION_FILE] = self.MakeEmptyTempFile()
     self.WriteFakeVersionFile()
 
-    TEST_CONFIG[DOT_GIT_LOCATION] = self.MakeEmptyTempFile()
     TEST_CONFIG[CHROMIUM] = self.MakeEmptyTempDirectory()
     chrome_dir = TEST_CONFIG[CHROMIUM]
     chrome_v8_dir = os.path.join(chrome_dir, "v8")