def test_rosinstall_detailed_locapath_info(self):
        cmd = ["rosws", "info", "-t", "ws"]
        os.chdir(self.test_root_path)
        sys.stdout = output = StringIO()
        rosws_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual(['clone', 'hg', self.version_end, os.path.join(self.test_root_path, 'remote')], tokens, output)

        clone_path = os.path.join(self.local_path, "clone")
        # make local modifications check
        subprocess.check_call(["hg", "rm", "test2.txt"], cwd=clone_path)
        os.chdir(self.test_root_path)
        sys.stdout = output = StringIO()
        rosws_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual(['clone', 'M', 'hg', self.version_end, os.path.join(self.test_root_path, 'remote')], tokens)

        subprocess.check_call(["rm", ".rosinstall"], cwd=self.local_path)
        _add_to_file(os.path.join(self.local_path, ".rosinstall"), "- other: {local-name: ../ros}\n- hg: {local-name: clone, uri: ../remote, version: \"footag\"}")
        os.chdir(self.test_root_path)
        sys.stdout = output = StringIO()
        rosws_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual(['clone', 'MV', 'hg', 'footag', self.version_end, "(%s)" % self.version_init, os.path.join(self.test_root_path, 'remote')], tokens)

        subprocess.check_call(["rm", "-rf", "clone"], cwd=self.local_path)
        os.chdir(self.test_root_path)
        sys.stdout = output = StringIO()
        rosws_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual(['clone', 'x', 'hg', 'footag', os.path.join(self.test_root_path, 'remote')], tokens)
Beispiel #2
0
    def test_rosinstall_detailed_locapath_info(self):
        cmd = ["wstool", "info", "-t", "ws"]
        os.chdir(self.test_root_path)
        sys.stdout = output = StringIO()
        wstool_main(cmd)
        output = output.getvalue()

        tokens = _nth_line_split(-2, output)
        self.assertEqual(['clone', 'bzr', self.version_end, os.path.join(self.test_root_path, 'remote')], tokens)

        clone_path = os.path.join(self.local_path, "clone")
        # make local modifications check
        subprocess.check_call(["rm", "test2.txt"], cwd=clone_path)
        sys.stdout = output = StringIO()
        wstool_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual(['clone', 'M', 'bzr', self.version_end, os.path.join(self.test_root_path, 'remote')], tokens)

        subprocess.check_call(["rm", ".rosinstall"], cwd=self.local_path)
        _add_to_file(os.path.join(self.local_path, ".rosinstall"), "- other: {local-name: ../ros}\n- bzr: {local-name: clone, uri: ../remote, version: \"footag\"}")
        os.chdir(self.test_root_path)
        sys.stdout = output = StringIO()
        wstool_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual(['clone', 'MV', 'bzr', 'footag', self.version_end, "(%s)" % self.version_init, os.path.join(self.test_root_path, 'remote')], tokens)

        subprocess.check_call(["rm", "-rf", "clone"], cwd=self.local_path)
        os.chdir(self.test_root_path)
        sys.stdout = output = StringIO()
        wstool_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual(['clone', 'x', 'bzr', 'footag', os.path.join(self.test_root_path, 'remote')], tokens)
    def test_rosws_info_git(self):
        cmd = ["rosws", "info", "-t", "ws"]
        os.chdir(self.test_root_path)
        sys.stdout = output = StringIO();
        rosws_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual(['clone', 'M', 'git'], tokens[0:3])
        tokens2 = _nth_line_split(-1, output)
        self.assertEqual(1, len(tokens2))
        self.assertEqual('../ros', tokens2[0])

        cli = RoswsCLI()
        self.assertEqual(0, cli.cmd_info(os.path.join(self.test_root_path, 'ws'), []))
    def test_rosws_info_git(self):
        cmd = ["rosws", "info", "-t", "ws"]
        os.chdir(self.test_root_path)
        sys.stdout = output = StringIO()
        rosws_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual(['clone', 'M', 'git'], tokens[0:3])
        tokens2 = _nth_line_split(-1, output)
        self.assertEqual(1, len(tokens2))
        self.assertEqual('../ros', tokens2[0])

        cli = RoswsCLI()
        self.assertEqual(
            0, cli.cmd_info(os.path.join(self.test_root_path, 'ws'), []))
    def test_rosinstall_detailed_locapath_info(self):
        cmd = ["rosws", "info", "-t", "ws"]
        os.chdir(self.test_root_path)
        sys.stdout = output = StringIO()
        rosws_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual(['clone', 'svn', self.version_end, self.svn_uri],
                         tokens)

        clone_path = os.path.join(self.local_path, "clone")
        # make local modifications check
        subprocess.check_call(["touch", "test3.txt"], cwd=clone_path)
        subprocess.check_call(["svn", "add", "test3.txt"], cwd=clone_path)
        os.chdir(self.test_root_path)
        sys.stdout = output = StringIO()
        rosws_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual(['clone', 'M', 'svn', self.version_end, self.svn_uri],
                         tokens)

        subprocess.check_call(["rm", ".rosinstall"], cwd=self.local_path)
        _add_to_file(
            os.path.join(self.local_path, ".rosinstall"),
            "- other: {local-name: ../ros}\n- svn: {local-name: clone, uri: '"
            + self.svn_uri + "', version: \"1\"}")
        os.chdir(self.test_root_path)
        sys.stdout = output = StringIO()
        rosws_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual([
            'clone', 'MV', 'svn', '1', self.version_end,
            "(%s)" % self.version_init, self.svn_uri
        ], tokens)

        subprocess.check_call(["rm", "-rf", "clone"], cwd=self.local_path)
        os.chdir(self.test_root_path)
        sys.stdout = output = StringIO()
        rosws_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual(['clone', 'x', 'svn', '1', self.svn_uri], tokens)
    def test_rosws_info_hg(self):
        cmd = ["rosws", "info", "-t", "ws"]
        os.chdir(self.test_root_path)
        sys.stdout = output = StringIO()
        rosws_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual(['clone', 'M', 'hg'], tokens[0:3], output)

        cli = RoswsCLI()
        self.assertEqual(0, cli.cmd_info(os.path.join(self.test_root_path, 'ws'), []))
    def test_wstool_info_svn(self):
        cmd = ["wstool", "info", "-t", "ws"]
        os.chdir(self.test_root_path)
        sys.stdout = output = StringIO()
        wstool_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual(['clone', 'M', 'svn'], tokens[0:3])

        cli = WstoolCLI()
        self.assertEqual(0, cli.cmd_info(os.path.join(self.test_root_path, 'ws'), []))
    def test_rosinstall_detailed_locapath_info(self):
        cmd = ["wstool", "info", "-t", "ws"]
        os.chdir(self.test_root_path)
        sys.stdout = output = StringIO()
        wstool_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual(['clone', 'svn', self.version_end, self.svn_uri], tokens)

        clone_path = os.path.join(self.local_path, "clone")
        # make local modifications check
        subprocess.check_call(["touch", "test3.txt"], cwd=clone_path)
        subprocess.check_call(["svn", "add", "test3.txt"], cwd=clone_path)
        os.chdir(self.test_root_path)
        sys.stdout = output = StringIO()
        wstool_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual(['clone', 'M', 'svn', self.version_end, self.svn_uri], tokens)

        subprocess.check_call(["rm", ".rosinstall"], cwd=self.local_path)
        _add_to_file(os.path.join(self.local_path, ".rosinstall"), "- other: {local-name: ../ros}\n- svn: {local-name: clone, uri: '" + self.svn_uri + "', version: \"1\"}")
        os.chdir(self.test_root_path)
        sys.stdout = output = StringIO()
        wstool_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual(['clone', 'MV', 'svn', '1', '(-)', self.version_end, "(%s)" % self.version_init, self.svn_uri], tokens)

        subprocess.check_call(["rm", "-rf", "clone"], cwd=self.local_path)
        os.chdir(self.test_root_path)
        sys.stdout = output = StringIO()
        wstool_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual(['clone', 'x', 'svn', '(-)', self.svn_uri], tokens)
    def test_rosinstall_detailed_localpath_info(self):
        cmd = ["rosws", "info", "-t", "ws"]
        os.chdir(self.test_root_path)
        sys.stdout = output = StringIO()
        rosws_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual(['clone', 'git', self.version_end, os.path.join(self.test_root_path, 'remote')], tokens, output)

        clone_path = os.path.join(self.local_path, "clone")
        # make local modifications check
        subprocess.check_call(["rm", "test2.txt"], cwd=clone_path)
        sys.stdout = output = StringIO()
        rosws_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual(['clone', 'M', 'git', self.version_end, os.path.join(self.test_root_path, 'remote')], tokens)

        subprocess.check_call(["rm", ".rosinstall"], cwd=self.local_path)
        _add_to_file(os.path.join(self.local_path, ".rosinstall"), "- other: {local-name: ../ros}\n- git: {local-name: clone, uri: ../remote, version: \"footag\"}")
        sys.stdout = output = StringIO()
        rosws_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual(['clone', 'MV', 'git', 'footag', self.version_end, "(%s)" % self.version_init, os.path.join(self.test_root_path, 'remote')], tokens)

        # using a denormalized local-name here
        subprocess.check_call(["rm", ".rosinstall"], cwd=self.local_path)
        _add_to_file(os.path.join(self.local_path, ".rosinstall"), "- other: {local-name: ../ros}\n- git: {local-name: clone/../clone, uri: ../remote, version: \"footag\"}")
        sys.stdout = output = StringIO()
        rosws_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual(['clone', 'MV', 'git', 'footag', self.version_end, "(%s)" %
                         self.version_init, os.path.join(self.test_root_path, 'remote')], tokens)

        # using an absolute path to clone dir here
        subprocess.check_call(["rm", ".rosinstall"], cwd=self.local_path)
        _add_to_file(os.path.join(self.local_path, ".rosinstall"), "- other: {local-name: ../ros}\n- git: {local-name: '"+clone_path+"', uri: ../remote, version: \"footag\"}")
        sys.stdout = output = StringIO()
        rosws_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual([clone_path, 'MV', 'git', 'footag', self.version_end, "(%s)" % self.version_init, os.path.join(self.test_root_path, 'remote')], tokens)

        # using an absolute path here where relative path is shorter to display (also checks x for missing)
        subprocess.check_call(["rm", ".rosinstall"], cwd=self.local_path)
        _add_to_file(os.path.join(self.local_path, ".rosinstall"), "- other: {local-name: ../ros}\n- git: {local-name: '"+os.path.join(self.local_path, "../foo")+"', uri: ../remote, version: \"footag\"}")
        sys.stdout = output = StringIO()
        rosws_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
Beispiel #10
0
 def test_info_table(self):
     basepath = '/foo/path'
     entries = []
     self.assertEqual('', rosinstall.cli_common.get_info_table(basepath, entries))
     entries = [{'scm': 'scm',
                 'uri': 'uri',
                 'curr_uri': 'uri',
                 'version': 'version',
                 'localname': 'localname',
                 'specversion': None,
                 'actualversion': None}]
     self.assertEqual(["localname", "scm", "version", "uri"], _nth_line_split(-1, rosinstall.cli_common.get_info_table(basepath, entries)))
     entries = [{'scm': 'scm',
                 'uri': 'uri',
                 'curr_uri': 'uri',
                 'version': 'version',
                 'localname': 'localname',
                 'specversion': 'specversion',
                 'actualversion': 'actualversion'}]
     self.assertEqual(["localname", 'V', "scm", "version", "actualversion", "(specversion)", "uri"], _nth_line_split(-1, rosinstall.cli_common.get_info_table(basepath, entries)))
     entries = [{'scm': 'scm',
                 'uri': 'uri',
                 'curr_uri': 'curr_uri',
                 'version': 'version',
                 'localname': 'localname'}]
     self.assertEqual(["localname", 'V', "scm", "version", "curr_uri", "(uri)"], _nth_line_split(-1, rosinstall.cli_common.get_info_table(basepath, entries)))
     entries = [{'scm': 'scm',
                 'uri': 'uri',
                 'version': 'version',
                 'localname': 'localname',
                 'exists': False}]
     self.assertEqual(["localname", 'x', "scm", "version", "uri"], _nth_line_split(-1, rosinstall.cli_common.get_info_table(basepath, entries)))
     # shorten SHAIDs for git
     entries = [{'scm': 'git',
                 'uri': 'uri',
                 'actualversion': '01234567890123456789012345678',
                 'localname': 'localname',
                 'exists': False}]
     self.assertEqual(["localname", 'x', "git", "012345678901", "uri"], _nth_line_split(-1, rosinstall.cli_common.get_info_table(basepath, entries)))
     entries = [{'scm': 'git',
                 'uri': 'uri',
                 'actualversion': '01234567890123456789012345678',
                 'specversion': '1234567890123456789012345678',
                 'localname': 'localname'}]
     self.assertEqual(["localname", 'V', "git", "012345678901", "(123456789012)", "uri"], _nth_line_split(-1, rosinstall.cli_common.get_info_table(basepath, entries)))
     # recompute svn startdard layout
     entries = [{'scm': 'svn',
                 'uri': 'https://some.svn.tags.server/some/tags/tagname',
                 'curr_uri': None,
                 'version': 'version',
                 'localname': 'localname',
                 'specversion': None,
                 'actualversion': None}]
     self.assertEqual(["localname", "svn", "tags/tagname", "some.svn.tags.server/some/"], _nth_line_split(-1, rosinstall.cli_common.get_info_table(basepath, entries)))
     entries = [{'scm': 'svn',
                 'uri': 'https://some.svn.tags.server/some/branches/branchname',
                 'curr_uri': None,
                 'version': 'version',
                 'localname': 'localname',
                 'specversion': None,
                 'actualversion': None}]
     self.assertEqual(["localname", "svn", "branches/branchname", "some.svn.tags.server/some/"], _nth_line_split(-1, rosinstall.cli_common.get_info_table(basepath, entries)))
     entries = [{'scm': 'svn',
                 'uri': 'https://some.svn.tags.server/some/trunk',
                 'curr_uri': None,
                 'version': 'version',
                 'localname': 'localname',
                 'specversion': None,
                 'actualversion': None}]
     self.assertEqual(["localname", "svn", "trunk", "some.svn.tags.server/some/"], _nth_line_split(-1, rosinstall.cli_common.get_info_table(basepath, entries)))
     entries = [{'scm': 'svn',
                 'uri': 'https://some.svn.tags.server/some/branches/branchname',
                 'curr_uri': 'https://some.svn.tags.server/some/tags/tagname',
                 'version': 'version',
                 'localname': 'localname',
                 'specversion': None,
                 'actualversion': None}]
     self.assertEqual(["localname", "svn", "tags/tagname", "(branches/branchname)", "some.svn.tags.server/some/"], _nth_line_split(-1, rosinstall.cli_common.get_info_table(basepath, entries)))
     entries = [{'scm': 'svn',
                 'uri': 'https://some.svn.tags.server/some/branches/branchname',
                 'curr_uri': 'https://some.svn.tags.server/some/tags/tagname',
                 'version': None,
                 'localname': 'localname',
                 'specversion': 'broken',
                 'actualversion': 'version'}]
     self.assertEqual(["localname", "V", "svn", "tags/tagname", "(branches/branchname)", "version", "(broken)", "some.svn.tags.server/some/"], _nth_line_split(-1, rosinstall.cli_common.get_info_table(basepath, entries)))
Beispiel #11
0
 def test_info_table(self):
     basepath = '/foo/path'
     entries = []
     self.assertEqual(
         '', rosinstall.cli_common.get_info_table(basepath, entries))
     entries = [{
         'scm': 'scm',
         'uri': 'uri',
         'curr_uri': 'uri',
         'version': 'version',
         'localname': 'localname',
         'specversion': None,
         'actualversion': None
     }]
     self.assertEqual(["localname", "scm", "version", "uri"],
                      _nth_line_split(
                          -1,
                          rosinstall.cli_common.get_info_table(
                              basepath, entries)))
     entries = [{
         'scm': 'scm',
         'uri': 'uri',
         'curr_uri': 'uri',
         'version': 'version',
         'localname': 'localname',
         'specversion': 'specversion',
         'actualversion': 'actualversion'
     }]
     self.assertEqual([
         "localname", 'V', "scm", "version", "actualversion",
         "(specversion)", "uri"
     ],
                      _nth_line_split(
                          -1,
                          rosinstall.cli_common.get_info_table(
                              basepath, entries)))
     entries = [{
         'scm': 'scm',
         'uri': 'uri',
         'curr_uri': 'curr_uri',
         'version': 'version',
         'localname': 'localname'
     }]
     self.assertEqual(
         ["localname", 'V', "scm", "version", "curr_uri", "(uri)"],
         _nth_line_split(
             -1, rosinstall.cli_common.get_info_table(basepath, entries)))
     entries = [{
         'scm': 'scm',
         'uri': 'uri',
         'version': 'version',
         'localname': 'localname',
         'exists': False
     }]
     self.assertEqual(["localname", 'x', "scm", "version", "uri"],
                      _nth_line_split(
                          -1,
                          rosinstall.cli_common.get_info_table(
                              basepath, entries)))
     # shorten SHAIDs for git
     entries = [{
         'scm': 'git',
         'uri': 'uri',
         'actualversion': '01234567890123456789012345678',
         'localname': 'localname',
         'exists': False
     }]
     self.assertEqual(["localname", 'x', "git", "012345678901", "uri"],
                      _nth_line_split(
                          -1,
                          rosinstall.cli_common.get_info_table(
                              basepath, entries)))
     entries = [{
         'scm': 'git',
         'uri': 'uri',
         'actualversion': '01234567890123456789012345678',
         'specversion': '1234567890123456789012345678',
         'localname': 'localname'
     }]
     self.assertEqual(
         ["localname", 'V', "git", "012345678901", "(123456789012)", "uri"],
         _nth_line_split(
             -1, rosinstall.cli_common.get_info_table(basepath, entries)))
     # recompute svn startdard layout
     entries = [{
         'scm': 'svn',
         'uri': 'https://some.svn.tags.server/some/tags/tagname',
         'curr_uri': None,
         'version': 'version',
         'localname': 'localname',
         'specversion': None,
         'actualversion': None
     }]
     self.assertEqual(
         ["localname", "svn", "tags/tagname", "some.svn.tags.server/some/"],
         _nth_line_split(
             -1, rosinstall.cli_common.get_info_table(basepath, entries)))
     entries = [{
         'scm': 'svn',
         'uri': 'https://some.svn.tags.server/some/branches/branchname',
         'curr_uri': None,
         'version': 'version',
         'localname': 'localname',
         'specversion': None,
         'actualversion': None
     }]
     self.assertEqual([
         "localname", "svn", "branches/branchname",
         "some.svn.tags.server/some/"
     ],
                      _nth_line_split(
                          -1,
                          rosinstall.cli_common.get_info_table(
                              basepath, entries)))
     entries = [{
         'scm': 'svn',
         'uri': 'https://some.svn.tags.server/some/trunk',
         'curr_uri': None,
         'version': 'version',
         'localname': 'localname',
         'specversion': None,
         'actualversion': None
     }]
     self.assertEqual(
         ["localname", "svn", "trunk", "some.svn.tags.server/some/"],
         _nth_line_split(
             -1, rosinstall.cli_common.get_info_table(basepath, entries)))
     entries = [{
         'scm': 'svn',
         'uri': 'https://some.svn.tags.server/some/branches/branchname',
         'curr_uri': 'https://some.svn.tags.server/some/tags/tagname',
         'version': 'version',
         'localname': 'localname',
         'specversion': None,
         'actualversion': None
     }]
     self.assertEqual([
         "localname", "svn", "tags/tagname", "(branches/branchname)",
         "some.svn.tags.server/some/"
     ],
                      _nth_line_split(
                          -1,
                          rosinstall.cli_common.get_info_table(
                              basepath, entries)))
     entries = [{
         'scm': 'svn',
         'uri': 'https://some.svn.tags.server/some/branches/branchname',
         'curr_uri': 'https://some.svn.tags.server/some/tags/tagname',
         'version': None,
         'localname': 'localname',
         'specversion': 'broken',
         'actualversion': 'version'
     }]
     self.assertEqual([
         "localname", "V", "svn", "tags/tagname", "(branches/branchname)",
         "version", "(broken)", "some.svn.tags.server/some/"
     ],
                      _nth_line_split(
                          -1,
                          rosinstall.cli_common.get_info_table(
                              basepath, entries)))
    def test_rosinstall_detailed_locapath_info(self):
        cmd = ["rosws", "info", "-t", "ws"]
        os.chdir(self.test_root_path)
        sys.stdout = output = StringIO()
        rosws_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual([
            'clone', 'git', self.version_end,
            os.path.join(self.test_root_path, 'remote')
        ], tokens, output)

        clone_path = os.path.join(self.local_path, "clone")
        # make local modifications check
        subprocess.check_call(["rm", "test2.txt"], cwd=clone_path)
        sys.stdout = output = StringIO()
        rosws_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual([
            'clone', 'M', 'git', self.version_end,
            os.path.join(self.test_root_path, 'remote')
        ], tokens)

        subprocess.check_call(["rm", ".rosinstall"], cwd=self.local_path)
        _add_to_file(
            os.path.join(self.local_path, ".rosinstall"),
            "- other: {local-name: ../ros}\n- git: {local-name: clone, uri: ../remote, version: \"footag\"}"
        )
        sys.stdout = output = StringIO()
        rosws_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual([
            'clone', 'MV', 'git', 'footag', self.version_end,
            "(%s)" % self.version_init,
            os.path.join(self.test_root_path, 'remote')
        ], tokens)

        # using a denormalized local-name here
        subprocess.check_call(["rm", ".rosinstall"], cwd=self.local_path)
        _add_to_file(
            os.path.join(self.local_path, ".rosinstall"),
            "- other: {local-name: ../ros}\n- git: {local-name: clone/../clone, uri: ../remote, version: \"footag\"}"
        )
        sys.stdout = output = StringIO()
        rosws_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual([
            'clone', 'MV', 'git', 'footag', self.version_end,
            "(%s)" % self.version_init,
            os.path.join(self.test_root_path, 'remote')
        ], tokens)

        # using an absolute path to clone dir here
        subprocess.check_call(["rm", ".rosinstall"], cwd=self.local_path)
        _add_to_file(
            os.path.join(self.local_path, ".rosinstall"),
            "- other: {local-name: ../ros}\n- git: {local-name: '" +
            clone_path + "', uri: ../remote, version: \"footag\"}")
        sys.stdout = output = StringIO()
        rosws_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual([
            clone_path, 'MV', 'git', 'footag', self.version_end,
            "(%s)" % self.version_init,
            os.path.join(self.test_root_path, 'remote')
        ], tokens)

        # using an absolute path here where relative path is shorter to display (also checks x for missing)
        subprocess.check_call(["rm", ".rosinstall"], cwd=self.local_path)
        _add_to_file(
            os.path.join(self.local_path, ".rosinstall"),
            "- other: {local-name: ../ros}\n- git: {local-name: '" +
            os.path.join(self.local_path, "../foo") +
            "', uri: ../remote, version: \"footag\"}")
        sys.stdout = output = StringIO()
        rosws_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
    def test_wstool_detailed_localpath_info(self):
        cmd = ["wstool", "info", "-t", "ws", "--managed-only"]
        os.chdir(self.test_root_path)
        sys.stdout = output = StringIO()
        wstool_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual([
            'clone', 'git', 'master', '(-)', self.version_end, self.remote_path
        ], tokens)

        # test when remote version is different
        subprocess.check_call(["git", "reset", "--hard", "HEAD~1"],
                              cwd=self.clone_path)
        sys.stdout = output = StringIO()
        wstool_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual([
            'clone', 'C', 'git', 'master', '(-)', self.version_init,
            self.remote_path
        ], tokens)
        # return branch back to original revision
        subprocess.check_call(["git", "reset", "--hard", self.version_end],
                              cwd=self.clone_path)

        # make local modifications check
        subprocess.check_call(["rm", "test2.txt"], cwd=self.clone_path)
        sys.stdout = output = StringIO()
        wstool_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual([
            'clone', 'M', 'git', 'master', '(-)', self.version_end,
            self.remote_path
        ], tokens)

        subprocess.check_call(["rm", ".rosinstall"], cwd=self.local_path)
        _add_to_file(
            os.path.join(self.local_path, ".rosinstall"),
            "- other: {local-name: ../ros}\n- git: {local-name: clone, uri: ../remote, version: \"footag\"}"
        )
        # test when version is different
        sys.stdout = output = StringIO()
        wstool_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual([
            'clone', 'MV', 'git', 'master', '(footag)', self.version_end,
            "(%s)" % self.version_init, self.remote_path
        ], tokens)
        # test when tracking branch is different from current branch
        subprocess.check_call(["git", "checkout", "-b", "test_branch"],
                              cwd=self.clone_path)
        subprocess.check_call([
            "git", "config", "--replace-all", "branch.test_branch.remote",
            "origin"
        ],
                              cwd=self.clone_path)
        subprocess.check_call([
            "git", "config", "--replace-all", "branch.test_branch.merge",
            "master"
        ],
                              cwd=self.clone_path)
        sys.stdout = output = StringIO()
        wstool_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual([
            'clone', 'MV', 'git', 'test_branch', '<', 'master', '(footag)',
            self.version_end,
            "(%s)" % self.version_init, self.remote_path
        ], tokens)

        # test when remote is different from origin by rename
        subprocess.check_call(["git", "remote", "rename", "origin", "remote2"],
                              cwd=self.clone_path)
        subprocess.check_call([
            "git", "config", "--replace-all", "branch.test_branch.remote",
            "remote2"
        ],
                              cwd=self.clone_path)
        sys.stdout = output = StringIO()
        wstool_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual([
            'clone', 'MV', 'git', 'test_branch', '<', 'remote2/master',
            '(footag)', self.version_end,
            "(%s)" % self.version_init,
            "(%s)" % self.remote_path
        ], tokens)
        # return remote name to origin
        subprocess.check_call(["git", "remote", "rename", "remote2", "origin"],
                              cwd=self.clone_path)

        # test when remote is different from origin, no fetch
        subprocess.check_call(
            ["git", "remote", "add", "remote2", "../../remote"],
            cwd=self.clone_path)
        subprocess.check_call([
            "git", "config", "--replace-all", "branch.test_branch.remote",
            "remote2"
        ],
                              cwd=self.clone_path)
        sys.stdout = output = StringIO()
        wstool_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual([
            'clone', 'MV', 'git', 'test_branch', '(footag)', self.version_end,
            "(%s)" % self.version_init, self.remote_path
        ], tokens)

        # test when remote is different from origin, with fetch
        sys.stdout = output = StringIO()
        wstool_main(cmd + ['--fetch'])
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual([
            'clone', 'MV', 'git', 'test_branch', '<', 'remote2/master',
            '(footag)', self.version_end,
            "(%s)" % self.version_init, self.remote_path
        ], tokens)

        # return branch back to master
        subprocess.check_call(["git", "checkout", "master"],
                              cwd=self.clone_path)

        # using a denormalized local-name here
        subprocess.check_call(["rm", ".rosinstall"], cwd=self.local_path)
        _add_to_file(
            os.path.join(self.local_path, ".rosinstall"),
            "- other: {local-name: ../ros}\n- git: {local-name: clone/../clone, uri: ../remote, version: \"footag\"}"
        )
        sys.stdout = output = StringIO()
        wstool_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual([
            'clone', 'MV', 'git', 'master', '(footag)', self.version_end,
            "(%s)" % self.version_init, self.remote_path
        ], tokens)

        # using an absolute path to clone dir here
        subprocess.check_call(["rm", ".rosinstall"], cwd=self.local_path)
        _add_to_file(
            os.path.join(self.local_path, ".rosinstall"),
            "- other: {local-name: ../ros}\n- git: {local-name: '" +
            self.clone_path + "', uri: ../remote, version: \"footag\"}")
        sys.stdout = output = StringIO()
        wstool_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual([
            self.clone_path, 'MV', 'git', 'master', '(footag)',
            self.version_end,
            "(%s)" % self.version_init, self.remote_path
        ], tokens)

        # using an absolute path here where relative path is shorter to display (also checks x for missing)
        subprocess.check_call(["rm", ".rosinstall"], cwd=self.local_path)
        _add_to_file(
            os.path.join(self.local_path, ".rosinstall"),
            "- other: {local-name: ../ros}\n- git: {local-name: '" +
            os.path.join(self.local_path, "../foo") +
            "', uri: ../remote, version: \"footag\"}")
        sys.stdout = output = StringIO()
        wstool_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        localname = os.path.join(os.path.dirname(self.local_path), 'foo')
        self.assertEqual([localname, 'x', 'git', '(footag)', self.remote_path],
                         tokens)
    def test_wstool_detailed_localpath_info(self):
        cmd = ["wstool", "info", "-t", "ws", "--managed-only"]
        os.chdir(self.test_root_path)
        sys.stdout = output = StringIO()
        wstool_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual(['clone', 'git', 'master', '(-)', self.version_end, self.remote_path], tokens)

        # test when remote version is different
        subprocess.check_call(["git", "reset", "--hard", "HEAD~1"], cwd=self.clone_path)
        sys.stdout = output = StringIO()
        wstool_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual(['clone', 'C', 'git', 'master', '(-)', self.version_init, self.remote_path], tokens)
        # return branch back to original revision
        subprocess.check_call(["git", "reset", "--hard", self.version_end], cwd=self.clone_path)

        # make local modifications check
        subprocess.check_call(["rm", "test2.txt"], cwd=self.clone_path)
        sys.stdout = output = StringIO()
        wstool_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual(['clone', 'M', 'git', 'master', '(-)', self.version_end, self.remote_path], tokens)

        subprocess.check_call(["rm", ".rosinstall"], cwd=self.local_path)
        _add_to_file(os.path.join(self.local_path, ".rosinstall"), "- other: {local-name: ../ros}\n- git: {local-name: clone, uri: ../remote, version: \"footag\"}")
        # test when version is different
        sys.stdout = output = StringIO()
        wstool_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual(['clone', 'MV', 'git', 'master', '(footag)', self.version_end, "(%s)" % self.version_init, self.remote_path], tokens)
        # test when tracking branch is different from current branch
        subprocess.check_call(["git", "checkout", "-b", "test_branch"], cwd=self.clone_path)
        subprocess.check_call(["git", "config", "--replace-all", "branch.test_branch.remote", "origin"], cwd=self.clone_path)
        subprocess.check_call(["git", "config", "--replace-all", "branch.test_branch.merge", "master"], cwd=self.clone_path)
        sys.stdout = output = StringIO()
        wstool_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual(['clone', 'MV', 'git', 'test_branch', '<', 'master', '(footag)', self.version_end, "(%s)" % self.version_init, self.remote_path], tokens)

        # test when remote is different from origin by rename
        subprocess.check_call(["git", "remote", "rename", "origin", "remote2"], cwd=self.clone_path)
        subprocess.check_call(["git", "config", "--replace-all", "branch.test_branch.remote", "remote2"], cwd=self.clone_path)
        sys.stdout = output = StringIO()
        wstool_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual(['clone', 'MV', 'git', 'test_branch', '<', 'remote2/master', '(footag)', self.version_end, "(%s)" % self.version_init, "(%s)" % self.remote_path], tokens)
        # return remote name to origin
        subprocess.check_call(["git", "remote", "rename", "remote2", "origin"], cwd=self.clone_path)

        # test when remote is different from origin, no fetch
        subprocess.check_call(["git", "remote", "add", "remote2", "../../remote"], cwd=self.clone_path)
        subprocess.check_call(["git", "config", "--replace-all", "branch.test_branch.remote", "remote2"], cwd=self.clone_path)
        sys.stdout = output = StringIO()
        wstool_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual(['clone', 'MV', 'git', 'test_branch', '(footag)', self.version_end, "(%s)" % self.version_init, self.remote_path], tokens)


        # test when remote is different from origin, with fetch
        sys.stdout = output = StringIO()
        wstool_main(cmd + ['--fetch'])
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual(['clone', 'MV', 'git', 'test_branch', '<', 'remote2/master', '(footag)', self.version_end, "(%s)" % self.version_init, self.remote_path], tokens)


        # return branch back to master
        subprocess.check_call(["git", "checkout", "master"], cwd=self.clone_path)

        # using a denormalized local-name here
        subprocess.check_call(["rm", ".rosinstall"], cwd=self.local_path)
        _add_to_file(os.path.join(self.local_path, ".rosinstall"), "- other: {local-name: ../ros}\n- git: {local-name: clone/../clone, uri: ../remote, version: \"footag\"}")
        sys.stdout = output = StringIO()
        wstool_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual(['clone', 'MV', 'git', 'master', '(footag)', self.version_end, "(%s)" %
                         self.version_init, self.remote_path], tokens)

        # using an absolute path to clone dir here
        subprocess.check_call(["rm", ".rosinstall"], cwd=self.local_path)
        _add_to_file(os.path.join(self.local_path, ".rosinstall"), "- other: {local-name: ../ros}\n- git: {local-name: '"+self.clone_path+"', uri: ../remote, version: \"footag\"}")
        sys.stdout = output = StringIO()
        wstool_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        self.assertEqual([self.clone_path, 'MV', 'git', 'master', '(footag)', self.version_end, "(%s)" % self.version_init, self.remote_path], tokens)

        # using an absolute path here where relative path is shorter to display (also checks x for missing)
        subprocess.check_call(["rm", ".rosinstall"], cwd=self.local_path)
        _add_to_file(os.path.join(self.local_path, ".rosinstall"), "- other: {local-name: ../ros}\n- git: {local-name: '"+os.path.join(self.local_path, "../foo")+"', uri: ../remote, version: \"footag\"}")
        sys.stdout = output = StringIO()
        wstool_main(cmd)
        output = output.getvalue()
        tokens = _nth_line_split(-2, output)
        localname = os.path.join(os.path.dirname(self.local_path), 'foo')
        self.assertEqual([localname, 'x', 'git', '(footag)', self.remote_path], tokens)