From c7cee59c0a5e34c51663b20f55cb3e485e809c31 Mon Sep 17 00:00:00 2001 From: "Jason M. Gates" Date: Thu, 2 Nov 2017 14:20:48 -0600 Subject: [PATCH] gitdist: Move to Base Dir (#212) The gitdist_move_to_base_dir unit test now covers the expected behavior when GITDIST_MOVE_TO_BASE_DIR is unset, or set to IMMEDIATE_BASE, or EXTREME_BASE. --- test/python_utils/gitdist_UnitTests.py | 78 ++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/test/python_utils/gitdist_UnitTests.py b/test/python_utils/gitdist_UnitTests.py index 13231f6b9..02300004b 100644 --- a/test/python_utils/gitdist_UnitTests.py +++ b/test/python_utils/gitdist_UnitTests.py @@ -1428,5 +1428,83 @@ def test_dist_repo_status_extra_args_fail(self): os.chdir(testBaseDir) + def test_gitdist_move_to_base_dir(self): + os.chdir(testBaseDir) + try: + + # Create a mock git meta-project. + testDir = createAndMoveIntoTestDir("gitdist_move_to_base_dir") + os.makedirs("ExtraRepo/path/to/somewhere") + open(".gitdist", "w").write( + ".\n" \ + "ExtraRepo\n" + ) + open("ExtraRepo/.gitdist", "w").write( + ".\n" + ) + os.chdir("ExtraRepo/path/to/somewhere") + + # Test with the default setting. + os.environ["GITDIST_MOVE_TO_BASE_DIR"] = "" + cmndOut = GeneralScriptSupport.getCmndOutput(gitdistPathMock+" status") + cmndOut_expected = \ + "\n*** Base Git Repo: somewhere\n" \ + "['mockgit', 'status']\n\n" + self.assertEqual(s(cmndOut), s(cmndOut_expected)) + + # Test moving up the directory tree until we find a .gitdist file. + os.environ["GITDIST_MOVE_TO_BASE_DIR"] = "IMMEDIATE_BASE" + cmndOut = GeneralScriptSupport.getCmndOutput(gitdistPathMock+" status") + cmndOut_expected = \ + "\n*** Base Git Repo: ExtraRepo\n" \ + "['mockgit', 'status']\n\n" + self.assertEqual(s(cmndOut), s(cmndOut_expected)) + + # Test moving up the directory tree until we find the outer-most .gitdist + # file. + os.environ["GITDIST_MOVE_TO_BASE_DIR"] = "EXTREME_BASE" + cmndOut = GeneralScriptSupport.getCmndOutput(gitdistPathMock+" status") + cmndOut_expected = \ + "\n*** Base Git Repo: MockProjectDir\n" \ + "['mockgit', 'status']\n\n" \ + "*** Git Repo: ExtraRepo\n" \ + "['mockgit', 'status']\n\n" + self.assertEqual(s(cmndOut), s(cmndOut_expected)) + + # Rename the .gitdist files .gitdist.default, and try the tests again. + os.rename("../../../.gitdist", "../../../.gitdist.default") + os.rename("../../../../.gitdist", "../../../../.gitdist.default") + + # Test with the default setting. + os.environ["GITDIST_MOVE_TO_BASE_DIR"] = "" + cmndOut = GeneralScriptSupport.getCmndOutput(gitdistPathMock+" status") + cmndOut_expected = \ + "\n*** Base Git Repo: somewhere\n" \ + "['mockgit', 'status']\n\n" + self.assertEqual(s(cmndOut), s(cmndOut_expected)) + + # Test moving up the directory tree until we find a .gitdist file. + os.environ["GITDIST_MOVE_TO_BASE_DIR"] = "IMMEDIATE_BASE" + cmndOut = GeneralScriptSupport.getCmndOutput(gitdistPathMock+" status") + cmndOut_expected = \ + "\n*** Base Git Repo: ExtraRepo\n" \ + "['mockgit', 'status']\n\n" + self.assertEqual(s(cmndOut), s(cmndOut_expected)) + + # Test moving up the directory tree until we find the outer-most .gitdist + # file. + os.environ["GITDIST_MOVE_TO_BASE_DIR"] = "EXTREME_BASE" + cmndOut = GeneralScriptSupport.getCmndOutput(gitdistPathMock+" status") + cmndOut_expected = \ + "\n*** Base Git Repo: MockProjectDir\n" \ + "['mockgit', 'status']\n\n" \ + "*** Git Repo: ExtraRepo\n" \ + "['mockgit', 'status']\n\n" + self.assertEqual(s(cmndOut), s(cmndOut_expected)) + + finally: + os.chdir(testBaseDir) + + if __name__ == '__main__': unittest.main()