def create_worktree(tmpdir): """ Helper function: Create a nice worktree with several git projects """ worktree = qisrc.worktree.create(tmpdir.strpath) my_gui = tmpdir.mkdir("gui").mkdir("my_gui") worktree.add_project(my_gui.strpath) lib = tmpdir.mkdir("lib") lib_foo = lib.mkdir("libfoo") lib_foo.mkdir("src") worktree.add_project(lib_foo.strpath) lib_bar = lib.mkdir("libbar") lib_bar.mkdir("src") worktree.add_project(lib_bar.strpath) spam = tmpdir.mkdir("spam") worktree.add_project(spam.strpath) eggs = spam.mkdir("eggs") worktree.add_project(eggs.strpath) tmpdir.mkdir("other") return worktree
def test_add_project(self): xml = "<worktree />" worktree = self.create_worktee(xml) worktree.add_project("foo") self.assertEquals(len(worktree.projects), 1) foo = worktree.get_project("foo") self.assertEquals(foo.src, "foo")
def test_nested_worktrees(self): # Create a worktree in work, with a project named # foo work = os.path.join(self.tmp, "work") qibuild.sh.mkdir(work) worktree = qisrc.worktree.create(work) foo = os.path.join(work, "foo") qibuild.sh.mkdir(foo) worktree.add_project(foo) foo_test = os.path.join(foo, "test") qibuild.sh.mkdir(foo_test) # Try to create a worktree in foo/test: should # do nothing test_worktree = qisrc.worktree.create(foo_test) test_dot_qi = os.path.join(foo_test, ".qi") self.assertFalse(os.path.exists(test_dot_qi)) worktree2 = qisrc.worktree.open_worktree(work) worktree2.get_project("foo") # Use the force: worktree3 = qisrc.worktree.create(foo_test, force=True) self.assertEquals(worktree3.projects, list()) # Try to create a worktree in the same place should not raise worktree4 = qisrc.worktree.create(work)
def test_add_git_project(self): xml = "<worktree />" worktree = self.create_worktee(xml) worktree.add_project("foo") qibuild.sh.mkdir( os.path.join(self.tmp, "foo", ".git"), recursive=True) # Re-open worktre, check that foo is in git_projects worktree = qisrc.open_worktree(self.tmp) self.assertEquals(len(worktree.git_projects), 1) git_foo = worktree.get_project("foo") self.assertEquals(git_foo.src, "foo")
def test_remove_project(self): xml = "<worktree />" worktree = self.create_worktee(xml) foo_src = os.path.join(worktree.root, "foo") qibuild.sh.mkdir(foo_src) worktree.add_project("foo") self.assertEquals(len(worktree.projects), 1) foo = worktree.get_project("foo") self.assertEquals(foo.src, "foo") error = None try: worktree.remove_project("bar") except Exception, e: error = e
def test_guess_git_repo(tmpdir, args): worktree = qisys.worktree.WorkTree(tmpdir.strpath) foo = tmpdir.mkdir("foo") bar = foo.mkdir("bar") foo.join("qiproject.xml").write("""<project> <project src="bar" /> </project> """) worktree.add_project("foo") git = qisrc.git.Git(foo.strpath) git.init() git_worktree = qisrc.worktree.GitWorkTree(worktree) with qisys.sh.change_cwd(bar.strpath): assert qisys.parsers.get_projects(worktree, args)[0].src == "foo/bar" assert get_git_projects(git_worktree, args)[0].src == "foo"