Example #1
0
def test_nested_qiprojects(tmpdir):
    a_project = tmpdir.mkdir("a")
    a_project.mkdir(".git")
    worktree_xml = tmpdir.mkdir(".qi").join("worktree.xml")
    worktree_xml.write("""
<worktree>
    <project src="a" />
</worktree>
""")

    a_xml = a_project.join("qiproject.xml")
    a_xml.write("""
<project name="a">
    <project src="b" />
</project>
""")

    b_project = a_project.mkdir("b")
    b_xml = b_project.join("qiproject.xml")
    b_xml.write("""
<project name="b">
    <project src="c" />
</project>
""")

    c_project = b_project.mkdir("c")
    c_xml = c_project.join("qiproject.xml")
    c_xml.write('<project name="c" />\n')

    worktree = qisys.worktree.open_worktree(tmpdir.strpath)
    assert len(worktree.projects) == 3
    a_proj = worktree.get_project("a")
    c_proj = worktree.get_project("a/b/c")
    assert c_proj.git_project.src == a_proj.src
Example #2
0
def test_guess_current_project(tmpdir):
    worktree = create_worktree(tmpdir)
    # Simple check
    bar_src = tmpdir.join("lib").join("libbar").join("src")
    cur_proj = qisrc.cmdparse.guess_current_project(worktree, bar_src.strpath)
    assert cur_proj.src == worktree.get_project("lib/libbar").src
    # Should return the most nested project
    eggs_src = tmpdir.join("spam").join("eggs").join("src")
    cur_proj = qisrc.cmdparse.guess_current_project(worktree, eggs_src.strpath)
    assert cur_proj.src == worktree.get_project("spam/eggs").src
    # Should return None
    other = tmpdir.join("other")
    assert qisrc.cmdparse.guess_current_project(worktree, other.strpath) is None
Example #3
0
 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")
Example #4
0
def test_add_project_simple(worktree):
    # pylint: disable-msg=E1101
    tmp = py.path.local(worktree.root)
    tmp.mkdir("foo")
    worktree.add_project("foo")
    assert len(worktree.projects) == 1
    foo = worktree.get_project("foo")
    assert foo.src == "foo"
Example #5
0
def test_add_project_simple(worktree):
    # pylint: disable-msg=E1101
    tmp = py.path.local(worktree.root)
    tmp.mkdir("foo")
    worktree.add_project("foo")
    assert len(worktree.projects) == 1
    foo = worktree.get_project("foo")
    assert foo.src == "foo"
Example #6
0
def test_add_project_simple(worktree):
    """ Test Add Project Simple """
    tmp = py.path.local(worktree.root)  # pylint:disable=no-member
    tmp.mkdir("foo")
    worktree.add_project("foo")
    assert len(worktree.projects) == 1
    foo1 = worktree.get_project("foo")
    assert foo1.src == "foo"
Example #7
0
def setup_tools():
    this_dir = os.path.basename(__file__)
    worktree_root = qisys.worktree.guess_worktree(raises=False)
    if not worktree_root:
        return
    worktree = qisys.worktree.WorkTree(worktree_root)
    tools_proj = worktree.get_project("doc/tools", raises=False)
    if not tools_proj:
        return
    if not tools_proj.path in sys.path:
        sys.path.insert(0, tools_proj.path)
Example #8
0
    def test_add_git_project(self):
        xml = "<worktree />"
        worktree = self.create_worktee(xml)
        worktree.add_project("foo")
        qisys.sh.mkdir(
            os.path.join(self.tmp, "foo", ".git"),
            recursive=True)

        # Re-open worktre, check that foo is in git_projects
        worktree = qisys.worktree.open_worktree(self.tmp)
        self.assertEquals(len(worktree.git_projects), 1)
        git_foo = worktree.get_project("foo")
        self.assertEquals(git_foo.src, "foo")
Example #9
0
 def test_remove_project(self):
     xml = "<worktree />"
     worktree = self.create_worktee(xml)
     foo_src = os.path.join(worktree.root, "foo")
     qisys.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
Example #10
0
def find_or_add(worktree, cwd=None):
    """
    If we find a qiproject.xml in a path not registered yet by looking
    in the parent directories, we just add it to the list.
    """
    if cwd is None:
        cwd = os.getcwd()
    head = cwd
    tail = None
    while True:
        candidate = os.path.join(head, "qiproject.xml")
        project = worktree.get_project(head)
        if project:
            return project
        if os.path.exists(candidate):
            return worktree.add_project(head)
        (head, tail) = os.path.split(head)
        if not tail:
            break
Example #11
0
def find_or_add(worktree, cwd=None):
    """
    If we find a qiproject.xml in a path not registered yet by looking
    in the parent directories, we just add it to the list.
    """
    if cwd is None:
        cwd = os.getcwd()
    head = cwd
    tail = None
    while True:
        candidate = os.path.join(head, "qiproject.xml")
        project = worktree.get_project(head)
        if project:
            return project
        if os.path.exists(candidate):
            return worktree.add_project(head)
        (head, tail) = os.path.split(head)
        if not tail:
            break
Example #12
0
def parse_project_arg(worktree, project_arg, single=False):
    """ Used to parse one 'project arg'
    Can be :
        * an absolute path
        * the path of the project relative to the worktree
    Result will be:
        * all the projects in the given subdir (unles single is True)
        * a project returned by worktree.get_project()

    """
    if not single:
        as_path = qisys.sh.to_native_path(project_arg)
        if os.path.exists(as_path):
            res = projects_in_subdir(worktree, as_path, raises=True)
            return res

    # Now assume it is a project src
    project = worktree.get_project(project_arg, raises=True)
    return [project]