def test_set_add_plain(self): workspace = os.path.join(self.test_root_path, 'ws5') cli = RoswsCLI() self.assertEqual(0, cli.cmd_init([workspace, self.simple_rosinstall])) config = rosinstall.multiproject_cmd.get_config(workspace, config_filename='.rosinstall') self.assertEqual(2, len(config.get_config_elements())) self.assertEqual('ros', config.get_config_elements()[0].get_local_name()) self.assertEqual('gitrepo', config.get_config_elements()[1].get_local_name()) # detached self.assertEqual(0, cli.cmd_set(workspace, [os.path.join(workspace, 'foo'), '-y'])) config = rosinstall.multiproject_cmd.get_config(workspace, config_filename='.rosinstall') self.assertEqual(3, len(config.get_config_elements())) self.assertEqual('ros', config.get_config_elements()[0].get_local_name()) self.assertEqual('gitrepo', config.get_config_elements()[1].get_local_name()) self.assertEqual(False, config.get_config_elements()[2].is_vcs_element()) self.assertEqual('foo', config.get_config_elements()[2].get_local_name()) self.assertEqual(0, cli.cmd_set(workspace, [os.path.join(workspace, 'hgrepo'), '-y', '--detached'])) config = rosinstall.multiproject_cmd.get_config(workspace, config_filename='.rosinstall') self.assertEqual(4, len(config.get_config_elements())) self.assertEqual('ros', config.get_config_elements()[0].get_local_name()) self.assertEqual('gitrepo', config.get_config_elements()[1].get_local_name()) self.assertEqual(False, config.get_config_elements()[2].is_vcs_element()) self.assertEqual('foo', config.get_config_elements()[2].get_local_name()) self.assertEqual(False, config.get_config_elements()[3].is_vcs_element()) self.assertEqual('hgrepo', config.get_config_elements()[3].get_local_name()) # turn into scm repo self.assertEqual(0, cli.cmd_set(workspace, [os.path.join(workspace, 'hgrepo'), '../hgrepo', '-y', '--hg'])) config = rosinstall.multiproject_cmd.get_config(workspace, config_filename='.rosinstall') self.assertEqual(4, len(config.get_config_elements())) self.assertEqual('ros', config.get_config_elements()[0].get_local_name()) self.assertEqual('gitrepo', config.get_config_elements()[1].get_local_name()) self.assertTrue(config.get_config_elements()[3].is_vcs_element()) self.assertEqual('hgrepo', config.get_config_elements()[3].get_local_name())
def test_setup_sh(self): self.local_path = os.path.join(self.test_root_path, "ws13") cli = RoswsCLI() self.assertEqual( 0, cli.cmd_init([self.local_path, self.simple_rosinstall])) command = "echo $ROS_WORKSPACE" self.execute_check_result_allshells(command, self.local_path, expect=self.local_path) self.execute_check_result_allshells(command, '.', cwd=self.local_path, expect=self.local_path) self.execute_check_result_allshells(command, 'ws13', cwd=self.test_root_path, expect=self.local_path) local_ros_path = os.path.join(self.local_path, "ros") local_git_path = os.path.join(self.local_path, "gitrepo") package_path = "%s:%s" % (local_git_path, local_ros_path) command = "echo $ROS_PACKAGE_PATH" self.execute_check_result_allshells(command, self.local_path, expect=package_path) self.execute_check_result_allshells(command, '.', cwd=self.local_path, expect=package_path) self.execute_check_result_allshells(command, 'ws13', cwd=self.test_root_path, expect=package_path)
def test_set_add_scm_change_localname(self): workspace = os.path.join(self.test_root_path, 'ws8') cli = RoswsCLI() self.assertEqual(0, cli.cmd_init([workspace, self.ros_path])) config = rosinstall.multiproject_cmd.get_config(workspace, config_filename='.rosinstall') self.assertEqual(1, len(config.get_config_elements())) self.assertEqual(os.path.join(self.test_root_path, 'ros'), config.get_config_elements()[0].get_local_name()) # use a weird absolute localname self.assertEqual(0, cli.cmd_set(workspace, [os.path.join(workspace, '..', 'ws8', 'hgrepo'), '../hgrepo', '-y', '--hg'])) config = rosinstall.multiproject_cmd.get_config(workspace, config_filename='.rosinstall') self.assertEqual(2, len(config.get_config_elements())) self.assertEqual('hgrepo', config.get_config_elements()[1].get_local_name()) oldcwd = os.getcwd() try: os.chdir(self.test_root_path) # try pointing to a relative dir that also exists elsewhere try: cli.cmd_set(workspace, ['gitrepo', '../gitrepo', '-y', '--hg']) self.fail("Expected SystemExit") except SystemExit: pass # use a weird relative localname self.assertEqual(0, cli.cmd_set(workspace, [os.path.join('ws8', 'gitrepo'), '../gitrepo', '-y', '--hg'])) config = rosinstall.multiproject_cmd.get_config(workspace, config_filename='.rosinstall') self.assertEqual(3, len(config.get_config_elements())) self.assertEqual('hgrepo', config.get_config_elements()[1].get_local_name()) self.assertEqual('gitrepo', config.get_config_elements()[2].get_local_name()) finally: os.chdir(oldcwd)
def test_init(self): workspace = os.path.join(self.test_root_path, 'ws1') cli = RoswsCLI() try: cli.cmd_init([workspace, 'foo', 'bar']) fail("expected exit") except SystemExit: pass self.assertEqual(0, cli.cmd_init([workspace, self.simple_rosinstall])) self.assertTrue(os.path.exists(workspace)) self.assertTrue(os.path.exists(os.path.join(workspace, '.rosinstall'))) self.assertTrue(os.path.exists(os.path.join(workspace, 'setup.sh'))) self.assertTrue(os.path.isdir(os.path.join(workspace, 'ros'))) self.assertTrue(os.path.isdir(os.path.join(workspace, 'gitrepo'))) self.assertTrue(os.path.isdir(os.path.join(workspace, 'gitrepo', '.git'))) config = rosinstall.multiproject_cmd.get_config(workspace, config_filename='.rosinstall') self.assertEqual(2, len(config.get_config_elements()))
def test_cmd_init_makedir(self): # rosinstall to create dir self.local_path = os.path.join(self.test_root_path, "ws9") cli = RoswsCLI() self.assertEqual(0, cli.cmd_init([self.local_path, self.ros_path])) self.assertTrue(os.path.exists(os.path.join(self.local_path, 'setup.sh'))) self.assertTrue(os.path.exists(os.path.join(self.local_path, 'setup.bash'))) self.assertTrue(os.path.exists(os.path.join(self.local_path, 'setup.zsh')))
def test_init_pwd(self): workspace = os.path.join(self.test_root_path, 'ws1b') cli = RoswsCLI() self.assertEqual(0, cli.cmd_init([workspace])) self.assertTrue(os.path.exists(workspace)) self.assertTrue(os.path.exists(os.path.join(workspace, '.rosinstall'))) self.assertTrue(os.path.exists(os.path.join(workspace, 'setup.sh'))) config = rosinstall.multiproject_cmd.get_config(workspace, config_filename='.rosinstall') self.assertEqual(0, len(config.get_config_elements()))
def test_cmd_init_catkin2(self): self.local_path = os.path.join(self.test_root_path, "ws7") os.makedirs(self.local_path) cli = RoswsCLI() self.assertEqual(0, cli.cmd_init([self.local_path, self.ros_path, "--catkin"])) self.assertFalse(os.path.exists(os.path.join(self.local_path, 'setup.sh'))) self.assertFalse(os.path.exists(os.path.join(self.local_path, 'setup.bash'))) self.assertFalse(os.path.exists(os.path.join(self.local_path, 'setup.zsh'))) self.assertTrue(os.path.exists(os.path.join(self.local_path, '.rosinstall'))) self.assertTrue(os.path.exists(os.path.join(self.local_path, 'CMakeLists.txt')))
def test_cmd_init_makedir(self): # rosinstall to create dir self.local_path = os.path.join(self.test_root_path, "ws9") cli = RoswsCLI() self.assertEqual(0, cli.cmd_init([self.local_path, self.ros_path])) self.assertTrue( os.path.exists(os.path.join(self.local_path, 'setup.sh'))) self.assertTrue( os.path.exists(os.path.join(self.local_path, 'setup.bash'))) self.assertTrue( os.path.exists(os.path.join(self.local_path, 'setup.zsh')))
def test_remove(self): workspace = os.path.join(self.test_root_path, 'ws3') cli = RoswsCLI() self.assertEqual(0, cli.cmd_init([workspace, self.simple_rosinstall])) self.assertEqual(0, cli.cmd_merge(workspace, [self.simple_changed_vcs_rosinstall, '-y'])) self.assertEqual(0, cli.cmd_update(workspace, [])) config = rosinstall.multiproject_cmd.get_config(workspace, config_filename='.rosinstall') self.assertEqual(3, len(config.get_config_elements())) self.assertEqual(0, cli.cmd_remove(workspace, ['hgrepo'])) config = rosinstall.multiproject_cmd.get_config(workspace, config_filename='.rosinstall') self.assertEqual(2, len(config.get_config_elements()))
def test_cmd_generate_ros_files_build(self): self.local_path = os.path.join(self.test_root_path, "ws2b") os.makedirs(self.local_path) local_rosinstall = os.path.join(self.test_root_path, "local.rosinstall") _create_yaml_file([_create_config_elt_dict("git", 'ros_comm', self.git_path), _create_config_elt_dict("git", 'ros', self.ros_path), _create_config_elt_dict("hg", 'hgrepo', self.hg_path)], local_rosinstall) cli = RoswsCLI() self.assertEqual(0, cli.cmd_init([self.local_path, local_rosinstall])) self.assertTrue(os.path.exists(os.path.join(self.local_path, 'setup.sh'))) self.assertTrue(os.path.exists(os.path.join(self.local_path, 'setup.bash'))) self.assertTrue(os.path.exists(os.path.join(self.local_path, 'setup.zsh')))
def test_cmd_init_no_ros(self): self.local_path = os.path.join(self.test_root_path, "ws10") ros_root_existed = False if 'ROS_ROOT' in os.environ: ros_root_existed = True oldros = os.environ.pop('ROS_ROOT') cli = RoswsCLI() self.assertEqual(0, cli.cmd_init([self.local_path])) shutil.rmtree(self.local_path) os.environ['ROS_ROOT'] = self.ros_path self.assertEqual(0, cli.cmd_init([self.local_path])) self.assertTrue(os.path.exists(os.path.join(self.local_path, 'setup.sh'))) self.assertTrue(os.path.exists(os.path.join(self.local_path, 'setup.bash'))) self.assertTrue(os.path.exists(os.path.join(self.local_path, 'setup.zsh'))) if ros_root_existed: os.environ['ROS_ROOT'] = oldros else: os.environ.pop('ROS_ROOT')
def test_cmd_init_catkinpp(self): self.local_path = os.path.join(self.test_root_path, "ws8") os.makedirs(self.local_path) cli = RoswsCLI() self.assertEqual(0, cli.cmd_init([self.local_path, self.ros_path, "--catkin", "--cmake-prefix-path=foo"])) self.assertFalse(os.path.exists(os.path.join(self.local_path, 'setup.sh'))) self.assertFalse(os.path.exists(os.path.join(self.local_path, 'setup.bash'))) self.assertFalse(os.path.exists(os.path.join(self.local_path, 'setup.zsh'))) self.assertTrue(os.path.exists(os.path.join(self.local_path, '.rosinstall'))) self.assertTrue(os.path.exists(os.path.join(self.local_path, 'CMakeLists.txt'))) self.assertTrue(os.path.exists(os.path.join(self.local_path, 'workspace-config.cmake')))
def test_merge(self): workspace = os.path.join(self.test_root_path, 'ws2') cli = RoswsCLI() self.assertEqual(0, cli.cmd_init([workspace, self.simple_rosinstall])) self.assertEqual(0, cli.cmd_merge(workspace, [self.simple_changed_vcs_rosinstall, '-y'])) self.assertFalse(os.path.isdir(os.path.join(workspace, 'hgrepo'))) self.assertFalse(os.path.isdir(os.path.join(workspace, 'hgrepo', '.hg'))) self.assertEqual(0, cli.cmd_update(workspace, [])) self.assertTrue(os.path.isdir(os.path.join(workspace, 'hgrepo'))) self.assertTrue(os.path.isdir(os.path.join(workspace, 'hgrepo', '.hg'))) config = wstool.multiproject_cmd.get_config(workspace, config_filename='.rosinstall') self.assertEqual(3, len(config.get_config_elements()))
def test_cmd_remove(self): # rosinstall to create dir self.local_path = os.path.join(self.test_root_path, "ws12") cli = RoswsCLI() self.assertEqual(0, cli.cmd_init([self.local_path, self.ros_path])) self.assertEqual(0, cli.cmd_merge(self.local_path, [self.git_path, "-y"])) self.assertEqual(0, cli.cmd_merge(self.local_path, [self.hg_path, "-y"])) config = rosinstall.multiproject_cmd.get_config(basepath=self.local_path, config_filename='.rosinstall') self.assertEqual(len(config.get_config_elements()), 3) self.assertEqual(0, cli.cmd_remove(self.local_path, [self.git_path])) config = rosinstall.multiproject_cmd.get_config(basepath=self.local_path, config_filename='.rosinstall') self.assertEqual(len(config.get_config_elements()), 2)
def prepare_workspace(path: str) -> None: """Prepare workspace at the given path. This is equivalent to calling `rosws init` on the given path. Internal use only. Args: path (str): Local workspace path. """ cli = RoswsCLI() cli.cmd_init([path]) # Fix setup.sh path with open(os.path.join(path, "setup.sh"), "r") as f: script = f.read() newpath = "export ROS_WORKSPACE=/workspace/fido_ws\n" script = re.sub(r"(export ROS_WORKSPACE=).*(\n)", newpath, script) with open(os.path.join(path, "setup.sh"), "w") as f: f.write(script)
def test_cmd_init(self): self.local_path = os.path.join(self.test_root_path, "ws5") os.makedirs(self.local_path) cli = RoswsCLI() self.assertEqual(0, cli.cmd_init([self.local_path, self.ros_path])) self.assertTrue( os.path.exists(os.path.join(self.local_path, 'setup.sh'))) self.assertTrue( os.path.exists(os.path.join(self.local_path, 'setup.bash'))) self.assertTrue( os.path.exists(os.path.join(self.local_path, 'setup.zsh'))) self.assertTrue( os.path.exists(os.path.join(self.local_path, '.rosinstall'))) self.assertEqual( 0, subprocess.call(". %s" % os.path.join(self.local_path, 'setup.sh'), shell=True, env=self.new_environ)) self.assertEqual( 0, subprocess.call(". %s" % os.path.join(self.local_path, 'setup.bash'), shell=True, env=self.new_environ, executable='/bin/bash')) self.assertEqual(0, cli.cmd_merge(self.local_path, [self.ros_path, "-y"])) self.assertTrue( os.path.exists(os.path.join(self.local_path, 'setup.sh'))) self.assertTrue( os.path.exists(os.path.join(self.local_path, 'setup.bash'))) self.assertTrue( os.path.exists(os.path.join(self.local_path, 'setup.zsh'))) self.assertTrue( os.path.exists(os.path.join(self.local_path, '.rosinstall'))) self.assertEqual( 0, subprocess.call(". %s" % os.path.join(self.local_path, 'setup.sh'), shell=True, env=self.new_environ)) self.assertEqual( 0, subprocess.call(". %s" % os.path.join(self.local_path, 'setup.bash'), shell=True, env=self.new_environ, executable='/bin/bash'))
def test_cmd_init_no_ros(self): self.local_path = os.path.join(self.test_root_path, "ws10") ros_root_existed = False if 'ROS_ROOT' in os.environ: ros_root_existed = True oldros = os.environ.pop('ROS_ROOT') cli = RoswsCLI() self.assertEqual(0, cli.cmd_init([self.local_path])) shutil.rmtree(self.local_path) os.environ['ROS_ROOT'] = self.ros_path self.assertEqual(0, cli.cmd_init([self.local_path])) self.assertTrue( os.path.exists(os.path.join(self.local_path, 'setup.sh'))) self.assertTrue( os.path.exists(os.path.join(self.local_path, 'setup.bash'))) self.assertTrue( os.path.exists(os.path.join(self.local_path, 'setup.zsh'))) if ros_root_existed: os.environ['ROS_ROOT'] = oldros else: os.environ.pop('ROS_ROOT')
def test_cmd_remove(self): # rosinstall to create dir self.local_path = os.path.join(self.test_root_path, "ws12") cli = RoswsCLI() self.assertEqual(0, cli.cmd_init([self.local_path, self.ros_path])) self.assertEqual(0, cli.cmd_merge(self.local_path, [self.git_path, "-y"])) self.assertEqual(0, cli.cmd_merge(self.local_path, [self.hg_path, "-y"])) config = rosinstall.multiproject_cmd.get_config( basepath=self.local_path, config_filename='.rosinstall') self.assertEqual(len(config.get_config_elements()), 3) self.assertEqual(0, cli.cmd_remove(self.local_path, [self.git_path])) config = rosinstall.multiproject_cmd.get_config( basepath=self.local_path, config_filename='.rosinstall') self.assertEqual(len(config.get_config_elements()), 2)
def test_cmd_init_catkin2(self): self.local_path = os.path.join(self.test_root_path, "ws7") os.makedirs(self.local_path) cli = RoswsCLI() self.assertEqual( 0, cli.cmd_init([self.local_path, self.ros_path, "--catkin"])) self.assertFalse( os.path.exists(os.path.join(self.local_path, 'setup.sh'))) self.assertFalse( os.path.exists(os.path.join(self.local_path, 'setup.bash'))) self.assertFalse( os.path.exists(os.path.join(self.local_path, 'setup.zsh'))) self.assertTrue( os.path.exists(os.path.join(self.local_path, '.rosinstall'))) self.assertTrue( os.path.exists(os.path.join(self.local_path, 'CMakeLists.txt')))
def test_setup_sh(self): self.local_path = os.path.join(self.test_root_path, "ws13") cli = RoswsCLI() self.assertEqual(0, cli.cmd_init([self.local_path, self.simple_rosinstall])) command = "echo $ROS_WORKSPACE" self.execute_check_result_allshells(command, self.local_path, expect=self.local_path) self.execute_check_result_allshells(command, '.', cwd=self.local_path, expect=self.local_path) self.execute_check_result_allshells(command, 'ws13', cwd=self.test_root_path, expect=self.local_path) local_ros_path = os.path.join(self.local_path, "ros") local_git_path = os.path.join(self.local_path, "gitrepo") package_path = "%s:%s" % (local_git_path, local_ros_path) command = "echo $ROS_PACKAGE_PATH" self.execute_check_result_allshells(command, self.local_path, expect=package_path) self.execute_check_result_allshells(command, '.', cwd=self.local_path, expect=package_path) self.execute_check_result_allshells(command, 'ws13', cwd=self.test_root_path, expect=package_path)
def test_cmd_generate_ros_files_build(self): self.local_path = os.path.join(self.test_root_path, "ws2b") os.makedirs(self.local_path) local_rosinstall = os.path.join(self.test_root_path, "local.rosinstall") _create_yaml_file([ _create_config_elt_dict("git", 'ros_comm', self.git_path), _create_config_elt_dict("git", 'ros', self.ros_path), _create_config_elt_dict("hg", 'hgrepo', self.hg_path) ], local_rosinstall) cli = RoswsCLI() self.assertEqual(0, cli.cmd_init([self.local_path, local_rosinstall])) self.assertTrue( os.path.exists(os.path.join(self.local_path, 'setup.sh'))) self.assertTrue( os.path.exists(os.path.join(self.local_path, 'setup.bash'))) self.assertTrue( os.path.exists(os.path.join(self.local_path, 'setup.zsh')))
def test_setup_sh_relros(self): self.local_path = os.path.join(self.test_root_path, "ws14") cli = RoswsCLI() simple_rel_rosinstall = os.path.join(self.test_root_path, "simple_rel.rosinstall") _create_yaml_file([_create_config_elt_dict("git", "ros", "../ros")], simple_rel_rosinstall) self.assertEqual(0, cli.cmd_init([self.local_path, simple_rel_rosinstall])) command = "echo $ROS_WORKSPACE" self.execute_check_result_allshells(command, self.local_path, expect=self.local_path) self.execute_check_result_allshells(command, '.', cwd=self.local_path, expect=self.local_path) self.execute_check_result_allshells(command, 'ws14', cwd=self.test_root_path, expect=self.local_path) package_path = os.path.join(self.local_path, "ros") command = "echo $ROS_PACKAGE_PATH" self.execute_check_result_allshells(command, self.local_path, expect=package_path) self.execute_check_result_allshells(command, '.', cwd=self.local_path, expect=package_path) self.execute_check_result_allshells(command, 'ws14', cwd=self.test_root_path, expect=package_path)
def test_set_detached(self): workspace = os.path.join(self.test_root_path, 'ws4') cli = RoswsCLI() self.assertEqual(0, cli.cmd_init([workspace, self.simple_rosinstall])) self.assertEqual(0, cli.cmd_merge(workspace, [self.simple_changed_vcs_rosinstall, '-y'])) self.assertEqual(0, cli.cmd_update(workspace, [])) config = rosinstall.multiproject_cmd.get_config(workspace, config_filename='.rosinstall') self.assertEqual(3, len(config.get_config_elements())) self.assertEqual('ros', config.get_config_elements()[0].get_local_name()) self.assertEqual('gitrepo', config.get_config_elements()[1].get_local_name()) self.assertEqual(True, config.get_config_elements()[1].is_vcs_element()) self.assertEqual('hgrepo', config.get_config_elements()[2].get_local_name()) self.assertEqual(0, cli.cmd_set(workspace, [os.path.join(workspace, 'gitrepo'), '--detached', '-y'])) config = rosinstall.multiproject_cmd.get_config(workspace, config_filename='.rosinstall') self.assertEqual(3, len(config.get_config_elements())) self.assertEqual('ros', config.get_config_elements()[0].get_local_name()) self.assertEqual('gitrepo', config.get_config_elements()[1].get_local_name()) self.assertEqual(False, config.get_config_elements()[1].is_vcs_element()) self.assertEqual('hgrepo', config.get_config_elements()[2].get_local_name())
def test_cmd_init(self): self.local_path = os.path.join(self.test_root_path, "ws5") os.makedirs(self.local_path) cli = RoswsCLI() self.assertEqual(0, cli.cmd_init([self.local_path, self.ros_path])) self.assertTrue(os.path.exists(os.path.join(self.local_path, 'setup.sh'))) self.assertTrue(os.path.exists(os.path.join(self.local_path, 'setup.bash'))) self.assertTrue(os.path.exists(os.path.join(self.local_path, 'setup.zsh'))) self.assertTrue(os.path.exists(os.path.join(self.local_path, '.rosinstall'))) self.assertEqual(0, subprocess.call(". %s" % os.path.join(self.local_path, 'setup.sh'), shell=True, env=self.new_environ)) self.assertEqual(0, subprocess.call(". %s" % os.path.join(self.local_path, 'setup.bash'), shell=True, env=self.new_environ, executable='/bin/bash')) self.assertEqual(0, cli.cmd_merge(self.local_path, [self.ros_path, "-y"])) self.assertTrue(os.path.exists(os.path.join(self.local_path, 'setup.sh'))) self.assertTrue(os.path.exists(os.path.join(self.local_path, 'setup.bash'))) self.assertTrue(os.path.exists(os.path.join(self.local_path, 'setup.zsh'))) self.assertTrue(os.path.exists(os.path.join(self.local_path, '.rosinstall'))) self.assertEqual(0, subprocess.call(". %s" % os.path.join(self.local_path, 'setup.sh'), shell=True, env=self.new_environ)) self.assertEqual(0, subprocess.call(". %s" % os.path.join(self.local_path, 'setup.bash'), shell=True, env=self.new_environ, executable='/bin/bash'))
def test_info_only(self): workspace = os.path.join(self.test_root_path, 'ws7') cli = RoswsCLI() self.assertEqual(0, cli.cmd_init([workspace, self.simple_rosinstall])) # pkg_path sys.stdout = output = StringIO() self.assertEqual(0, cli.cmd_info(workspace, ['--pkg-path-only'])) output = output.getvalue() self.assertEqual(os.path.join(workspace, 'gitrepo'), output.strip()) sys.stdout = output = StringIO() self.assertEqual(0, cli.cmd_info(workspace, ['--only=localname'])) output = output.getvalue() self.assertEqual('ros\ngitrepo', output.strip()) sys.stdout = output = StringIO() self.assertEqual(0, cli.cmd_info(workspace, ['--only=version'])) output = output.getvalue() self.assertEqual('', output.strip()) sys.stdout = output = StringIO() self.assertEqual(0, cli.cmd_info(workspace, ['--only=uri'])) output = output.getvalue() self.assertEqual('%s\n%s\n' % (os.path.join(self.test_root_path, 'ros'), os.path.join(self.test_root_path, 'gitrepo')), output) sys.stdout = output = StringIO() self.assertEqual(0, cli.cmd_info(workspace, ['--only=cur_revision'])) output = output.getvalue() self.assertEqual(82, len(output)) sys.stdout = sys.__stdout__ # pairs sys.stdout = output = StringIO(); self.assertEqual(0, cli.cmd_info(workspace, ['--only=localname,scmtype'])) output = output.getvalue() self.assertEqual('ros,git\ngitrepo,git', output.strip()) sys.stdout = output = StringIO(); self.assertEqual(0, cli.cmd_info(workspace, ['--only=scmtype,localname'])) output = output.getvalue() self.assertEqual('git,ros\ngit,gitrepo', output.strip())
def test_setup_sh_relother(self): self.local_path = os.path.join(self.test_root_path, "ws15") cli = RoswsCLI() simple_rel_rosinstall = os.path.join(self.test_root_path, "simple_rel2.rosinstall") _create_yaml_file([ _create_config_elt_dict("git", "ros", "../ros"), _create_config_elt_dict("other", "../gitrepo") ], simple_rel_rosinstall) self.assertEqual( 0, cli.cmd_init([self.local_path, simple_rel_rosinstall])) command = "echo $ROS_WORKSPACE" self.execute_check_result_allshells(command, self.local_path, expect=self.local_path) self.execute_check_result_allshells(command, '.', cwd=self.local_path, expect=self.local_path) self.execute_check_result_allshells(command, 'ws15', cwd=self.test_root_path, expect=self.local_path) local_ros_path = os.path.join(self.local_path, "ros") package_path = "%s:%s" % (self.git_path, local_ros_path) command = "echo $ROS_PACKAGE_PATH" self.execute_check_result_allshells(command, self.local_path, expect=package_path) self.execute_check_result_allshells(command, '.', cwd=self.local_path, expect=package_path) self.execute_check_result_allshells(command, 'ws15', cwd=self.test_root_path, expect=package_path)
def test_cmd_init_catkinpp(self): self.local_path = os.path.join(self.test_root_path, "ws8") os.makedirs(self.local_path) cli = RoswsCLI() self.assertEqual( 0, cli.cmd_init([ self.local_path, self.ros_path, "--catkin", "--cmake-prefix-path=foo" ])) self.assertFalse( os.path.exists(os.path.join(self.local_path, 'setup.sh'))) self.assertFalse( os.path.exists(os.path.join(self.local_path, 'setup.bash'))) self.assertFalse( os.path.exists(os.path.join(self.local_path, 'setup.zsh'))) self.assertTrue( os.path.exists(os.path.join(self.local_path, '.rosinstall'))) self.assertTrue( os.path.exists(os.path.join(self.local_path, 'CMakeLists.txt'))) self.assertTrue( os.path.exists( os.path.join(self.local_path, 'workspace-config.cmake')))
def test_init_parallel(self): workspace = os.path.join(self.test_root_path, 'ws1d') cli = RoswsCLI() self.assertEqual(0, cli.cmd_init([workspace, self.simple_rosinstall, "--parallel=5"])) self.assertTrue(os.path.exists(workspace)) self.assertTrue(os.path.exists(os.path.join(workspace, '.rosinstall')))
def test_set_add_scm(self): workspace = os.path.join(self.test_root_path, 'ws6') cli = RoswsCLI() self.assertEqual(0, cli.cmd_init([workspace, self.simple_rosinstall])) config = rosinstall.multiproject_cmd.get_config(workspace, config_filename='.rosinstall') self.assertEqual(2, len(config.get_config_elements())) self.assertEqual('ros', config.get_config_elements()[0].get_local_name()) self.assertEqual('gitrepo', config.get_config_elements()[1].get_local_name()) # scm repo self.assertEqual(0, cli.cmd_set(workspace, [os.path.join(workspace, 'hgrepo'), '../hgrepo', '-y', '--hg'])) config = rosinstall.multiproject_cmd.get_config(workspace, config_filename='.rosinstall') self.assertEqual(3, len(config.get_config_elements())) self.assertEqual('ros', config.get_config_elements()[0].get_local_name()) self.assertEqual('gitrepo', config.get_config_elements()[1].get_local_name()) self.assertTrue(config.get_config_elements()[2].is_vcs_element()) self.assertEqual('hgrepo', config.get_config_elements()[2].get_local_name()) self.assertFalse(os.path.exists(os.path.join(workspace, 'hgrepo'))) self.assertEqual(0, cli.cmd_update(workspace, [])) self.assertTrue(os.path.exists(os.path.join(workspace, 'hgrepo'))) path_spec = config.get_config_elements()[2].get_versioned_path_spec() self.assertFalse(path_spec is None) self.assertEqual(None, path_spec.get_version()) self.assertEqual(None, path_spec.get_revision()) self.assertFalse(path_spec.get_current_revision() is None) self.assertEqual(0, cli.cmd_set(workspace, [os.path.join(workspace, 'hgrepo'), '--version-new=0', '-y'])) config = rosinstall.multiproject_cmd.get_config(workspace, config_filename='.rosinstall') path_spec = config.get_config_elements()[2].get_versioned_path_spec() self.assertEqual('0', path_spec.get_version()) self.assertFalse(path_spec.get_revision() is None) self.assertFalse(path_spec.get_current_revision() is None) self.assertEqual(path_spec.get_revision(), path_spec.get_current_revision()) # change in FS to version 1 subprocess.check_call(["touch", "hgfixed2.txt"], cwd=os.path.join(workspace, 'hgrepo')) subprocess.check_call(["hg", "add", "hgfixed2.txt"], cwd=os.path.join(workspace, 'hgrepo')) subprocess.check_call(["hg", "commit", "-m", "2nd"], cwd=os.path.join(workspace, 'hgrepo')) self.assertTrue(os.path.exists(os.path.join(workspace, 'hgrepo', 'hgfixed2.txt'))) path_spec = config.get_config_elements()[2].get_versioned_path_spec() self.assertEqual('0', path_spec.get_version()) self.assertFalse(path_spec.get_revision() is None) self.assertFalse(path_spec.get_current_revision() is None) self.assertNotEqual(path_spec.get_revision(), path_spec.get_current_revision()) # revert FS to spec self.assertEqual(0, cli.cmd_update(workspace, [])) config = rosinstall.multiproject_cmd.get_config(workspace, config_filename='.rosinstall') path_spec = config.get_config_elements()[2].get_versioned_path_spec() self.assertEqual('0', path_spec.get_version()) self.assertFalse(path_spec.get_revision() is None) self.assertFalse(path_spec.get_current_revision() is None) self.assertEqual(path_spec.get_revision(), path_spec.get_current_revision()) # change spec to 1 self.assertEqual(0, cli.cmd_set(workspace, [os.path.join(workspace, 'hgrepo'), '--version-new=1', '-y'])) config = rosinstall.multiproject_cmd.get_config(workspace, config_filename='.rosinstall') path_spec = config.get_config_elements()[2].get_versioned_path_spec() self.assertEqual('1', path_spec.get_version()) self.assertFalse(path_spec.get_revision() is None) self.assertFalse(path_spec.get_current_revision() is None) self.assertNotEqual(path_spec.get_revision(), path_spec.get_current_revision()) # setting version to '' self.assertEqual(0, cli.cmd_set(workspace, [os.path.join(workspace, 'hgrepo'), "--version-new=''", '-y'])) config = rosinstall.multiproject_cmd.get_config(workspace, config_filename='.rosinstall') path_spec = config.get_config_elements()[2].get_versioned_path_spec() self.assertEqual(None, path_spec.get_version()) self.assertTrue(path_spec.get_revision() is None) self.assertFalse(path_spec.get_current_revision() is None) self.assertEqual(0, cli.cmd_update(workspace, [])) config = rosinstall.multiproject_cmd.get_config(workspace, config_filename='.rosinstall') path_spec = config.get_config_elements()[2].get_versioned_path_spec() self.assertEqual(None, path_spec.get_version()) self.assertTrue(path_spec.get_revision() is None) self.assertFalse(path_spec.get_current_revision() is None)