Skip to content

Commit

Permalink
gitdist: Move to Base Dir (#212)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jmgate committed Nov 2, 2017
1 parent 0250225 commit c7cee59
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions test/python_utils/gitdist_UnitTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit c7cee59

Please sign in to comment.