def test_cmd_add_uris(self): # wstool to create dir self.local_path = os.path.join(self.test_root_path, "ws33") cli = MultiprojectCLI(progname='multi_cli', config_filename='.rosinstall') simple_rel_rosinstall = os.path.join(self.test_root_path, "simple_rel3.rosinstall") _create_yaml_file([ _create_config_elt_dict(scmtype="git", uri=os.path.join(self.test_root_path, "ros"), localname='ros') ], simple_rel_rosinstall) self.assertEqual( 0, cli.cmd_init([self.local_path, simple_rel_rosinstall])) config = wstool.multiproject_cmd.get_config( basepath=self.local_path, config_filename='.rosinstall') self.assertEqual(1, len(config.get_config_elements())) self.assertEqual( 'git', config.get_config_elements()[0].get_path_spec().get_scmtype()) wstool.multiproject_cmd.add_uris(config, [self.local_path]) self.assertEqual(len(config.get_config_elements()), 1, config) self.assertEqual( 'git', config.get_config_elements()[0].get_path_spec().get_scmtype()) wstool.multiproject_cmd.add_uris( config, [os.path.join(self.local_path, '.rosinstall')]) self.assertEqual(len(config.get_config_elements()), 1, config) self.assertEqual( 'git', config.get_config_elements()[0].get_path_spec().get_scmtype())
def test_init_parallel(self): self.local_path = os.path.join(self.test_root_path, "ws31") cli = MultiprojectCLI(progname='multi_cli', config_filename='.rosinstall') self.assertEqual( 0, cli.cmd_init( [self.local_path, self.simple_rosinstall, "--parallel=5"])) self.assertTrue( os.path.exists(os.path.join(self.local_path, '.rosinstall'))) self.assertTrue( os.path.exists(os.path.join(self.local_path, 'gitrepo'))) self.assertFalse( os.path.exists(os.path.join(self.local_path, 'hgrepo'))) self.assertEqual( 0, cli.cmd_merge(self.local_path, [self.simple_changed_vcs_rosinstall, "-y"])) self.assertTrue( os.path.exists(os.path.join(self.local_path, 'gitrepo'))) self.assertFalse( os.path.exists(os.path.join(self.local_path, 'hgrepo'))) self.assertEqual(0, cli.cmd_update(self.local_path, ["--parallel=5"])) self.assertTrue( os.path.exists(os.path.join(self.local_path, 'gitrepo'))) self.assertTrue(os.path.exists(os.path.join(self.local_path, 'hgrepo')))
def test_merge_dash(self): self.local_path = os.path.join(self.test_root_path, "ws35") cli = MultiprojectCLI(progname='multi_cli', config_filename='.rosinstall') self.assertEqual( 0, cli.cmd_init( [self.local_path, self.simple_rosinstall, "--parallel=5"])) self.assertTrue( os.path.exists(os.path.join(self.local_path, '.rosinstall'))) self.assertTrue( os.path.exists(os.path.join(self.local_path, 'gitrepo'))) self.assertFalse( os.path.exists(os.path.join(self.local_path, 'hgrepo'))) try: backup = sys.stdin with open(self.simple_changed_vcs_rosinstall, 'r') as fhand: contents = fhand.read() sys.stdin = Mock() sys.stdin.readlines.return_value = contents self.assertEqual(0, cli.cmd_merge(self.local_path, ["-"])) finally: sys.stdin = backup self.assertTrue( os.path.exists(os.path.join(self.local_path, 'gitrepo'))) self.assertFalse( os.path.exists(os.path.join(self.local_path, 'hgrepo'))) self.assertEqual(0, cli.cmd_update(self.local_path, ["--parallel=5"])) self.assertTrue( os.path.exists(os.path.join(self.local_path, 'gitrepo'))) self.assertTrue(os.path.exists(os.path.join(self.local_path, 'hgrepo')))
def test_scrape(self): self.local_path = os.path.join(self.test_root_path, "ws37") cli = MultiprojectCLI(progname='multi_cli', config_filename='.rosinstall') self.assertEqual(0, cli.cmd_init([self.local_path, self.simple_rosinstall, "--parallel=5"])) config = wstool.multiproject_cmd.get_config(basepath=self.local_path, config_filename='.rosinstall') try: cli.cmd_scrape(self.local_path, [], config) self.fail("expected Exception") except MultiProjectException: pass git_repo_path = os.path.join(self.local_path, 'gitrepo') hg_repo_path = os.path.join(self.local_path, 'hgrepo') subprocess.check_call(["git", "init", git_repo_path]) subprocess.check_call(["hg", "init", hg_repo_path]) for cmd in [["touch", "foo.txt"], ["hg", "add", hg_repo_path], ["hg", "commit", "-m", "foo"]]: subprocess.check_call(cmd, cwd=hg_repo_path) self.assertEqual(0, cli.cmd_scrape(self.local_path, ['-y'], config)) config = wstool.multiproject_cmd.get_config(basepath=self.local_path, config_filename='.rosinstall') # initial config has 1 element, "ros" self.assertEqual(len(config.get_config_elements()), 3, config.get_config_elements())
def __init__(self, config_filename=ROSINSTALL_FILENAME, progname=_PROGNAME): MultiprojectCLI.__init__( self, progname=progname, config_filename=config_filename, allow_other_element=True, config_generator=rosinstall_cmd.cmd_persist_config)
def test_cmd_init(self): self.local_path = os.path.join(self.test_root_path, "ws30") os.makedirs(self.local_path) cli = MultiprojectCLI(progname='multi_cli', config_filename='.rosinstall') self.assertEqual(0, cli.cmd_init([self.local_path])) 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')))
def test_cmd_set(self): self.local_path = os.path.join(self.test_root_path, "ws31b") cli = MultiprojectCLI(progname='multi_cli', config_filename='.rosinstall') self.assertEqual( 0, cli.cmd_init( [self.local_path, self.simple_rosinstall, "--parallel=5"])) self.assertEqual( 0, cli.cmd_set(self.local_path, [ os.path.join(self.local_path, 'hgrepo'), "--hg", 'http://some_uri', '-y' ])) cli.cmd_set(self.local_path, [ os.path.join(self.local_path, 'hgrepo'), self.hg_path, '--hg', '--update', '-y' ]) self.assertTrue(os.path.exists(os.path.join(self.local_path, 'hgrepo'))) self.assertRaises( SystemExit, cli.cmd_set, self.local_path, [os.path.join(self.local_path, 'hgrepo'), "--detached", '-y']) cli = MultiprojectCLI(progname='multi_cli', config_filename='.rosinstall', allow_other_element=True) self.assertEqual( 0, cli.cmd_set( self.local_path, [os.path.join(self.local_path, 'hgrepo'), "--detached", '-y']))
def test_init_parallel(self): self.local_path = os.path.join(self.test_root_path, "ws31") cli = MultiprojectCLI(progname='multi_cli', config_filename='.rosinstall') self.assertEqual(0, cli.cmd_init([self.local_path, self.simple_rosinstall, "--parallel=5"])) self.assertTrue(os.path.exists(os.path.join(self.local_path, '.rosinstall'))) self.assertTrue(os.path.exists(os.path.join(self.local_path, 'gitrepo'))) self.assertFalse(os.path.exists(os.path.join(self.local_path, 'hgrepo'))) self.assertEqual(0, cli.cmd_merge(self.local_path, [self.simple_changed_vcs_rosinstall, "-y"])) self.assertTrue(os.path.exists(os.path.join(self.local_path, 'gitrepo'))) self.assertFalse(os.path.exists(os.path.join(self.local_path, 'hgrepo'))) self.assertEqual(0, cli.cmd_update(self.local_path, ["--parallel=5"])) self.assertTrue(os.path.exists(os.path.join(self.local_path, 'gitrepo'))) self.assertTrue(os.path.exists(os.path.join(self.local_path, 'hgrepo')))
def test_cmd_remove(self): # wstool to create dir self.local_path = os.path.join(self.test_root_path, "ws32") cli = MultiprojectCLI(progname='multi_cli', config_filename='.rosinstall', allow_other_element=False) self.assertEqual(0, cli.cmd_init([self.local_path])) self.assertRaises(MultiProjectException, cli.cmd_merge, self.local_path, [self.git_path, "-y"]) self.assertRaises(MultiProjectException, cli.cmd_merge, self.local_path, [self.hg_path, "-y"]) cli = MultiprojectCLI(progname='multi_cli', config_filename='.rosinstall', allow_other_element=True) 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 = wstool.multiproject_cmd.get_config( basepath=self.local_path, config_filename='.rosinstall') self.assertEqual(len(config.get_config_elements()), 2) self.assertEqual(0, cli.cmd_remove(self.local_path, [self.git_path])) config = wstool.multiproject_cmd.get_config( basepath=self.local_path, config_filename='.rosinstall') self.assertEqual(len(config.get_config_elements()), 1)
def __init__(self, config_filename=ROSINSTALL_FILENAME, progname=_PROGNAME): def config_generator(config, filename, header=None): wstool.multiproject_cmd.cmd_persist_config( config, filename, header, pretty=True, sort_with_localname=True) MultiprojectCLI.__init__(self, progname=progname, config_filename=config_filename, config_generator=config_generator)
def __init__(self, config_filename=ROSINSTALL_FILENAME, progname=_PROGNAME): def config_generator(config, filename, header=None): wstool.multiproject_cmd.cmd_persist_config( config, filename, header, pretty=True, sort_with_localname=True) MultiprojectCLI.__init__( self, progname=progname, config_filename=config_filename, config_generator=config_generator)
def test_cmd_set(self): self.local_path = os.path.join(self.test_root_path, "ws31b") cli = MultiprojectCLI(progname='multi_cli', config_filename='.rosinstall') self.assertEqual(0, cli.cmd_init([self.local_path, self.simple_rosinstall, "--parallel=5"])) self.assertEqual(0, cli.cmd_set(self.local_path, [os.path.join(self.local_path, 'hgrepo'), "--hg", 'http://some_uri', '-y'])) self.assertRaises(SystemExit, cli.cmd_set, self.local_path, [os.path.join(self.local_path, 'hgrepo'), "--detached", '-y']) cli = MultiprojectCLI(progname='multi_cli', config_filename='.rosinstall', allow_other_element=True) self.assertEqual(0, cli.cmd_set(self.local_path, [os.path.join(self.local_path, 'hgrepo'), "--detached", '-y']))
def test_scrape(self): self.local_path = os.path.join(self.test_root_path, "ws37") cli = MultiprojectCLI(progname='multi_cli', config_filename='.rosinstall') self.assertEqual( 0, cli.cmd_init( [self.local_path, self.simple_rosinstall, "--parallel=5"])) config = wstool.multiproject_cmd.get_config( basepath=self.local_path, config_filename='.rosinstall') try: cli.cmd_scrape(self.local_path, [], config) self.fail("expected Exception") except MultiProjectException: pass git_repo_path = os.path.join(self.local_path, 'gitrepo') hg_repo_path = os.path.join(self.local_path, 'hgrepo') subprocess.check_call(["git", "init", git_repo_path]) subprocess.check_call(["hg", "init", hg_repo_path]) for cmd in [["touch", "foo.txt"], ["hg", "add", hg_repo_path], ["hg", "commit", "-m", "foo"]]: subprocess.check_call(cmd, cwd=hg_repo_path) self.assertEqual(0, cli.cmd_scrape(self.local_path, ['-y'], config)) config = wstool.multiproject_cmd.get_config( basepath=self.local_path, config_filename='.rosinstall') # initial config has 1 element, "ros" self.assertEqual(len(config.get_config_elements()), 3, config.get_config_elements())
def test_merge_dash(self): self.local_path = os.path.join(self.test_root_path, "ws35") cli = MultiprojectCLI(progname='multi_cli', config_filename='.rosinstall') self.assertEqual(0, cli.cmd_init([self.local_path, self.simple_rosinstall, "--parallel=5"])) self.assertTrue(os.path.exists(os.path.join(self.local_path, '.rosinstall'))) self.assertTrue(os.path.exists(os.path.join(self.local_path, 'gitrepo'))) self.assertFalse(os.path.exists(os.path.join(self.local_path, 'hgrepo'))) try: backup = sys.stdin with open(self.simple_changed_vcs_rosinstall, 'r') as fhand: contents = fhand.read() sys.stdin = Mock() sys.stdin.readlines.return_value = contents self.assertEqual(0, cli.cmd_merge(self.local_path, ["-"])) finally: sys.stdin = backup self.assertTrue(os.path.exists(os.path.join(self.local_path, 'gitrepo'))) self.assertFalse(os.path.exists(os.path.join(self.local_path, 'hgrepo'))) self.assertEqual(0, cli.cmd_update(self.local_path, ["--parallel=5"])) self.assertTrue(os.path.exists(os.path.join(self.local_path, 'gitrepo'))) self.assertTrue(os.path.exists(os.path.join(self.local_path, 'hgrepo')))
def test_cmd_add_uris(self): # wstool to create dir self.local_path = os.path.join(self.test_root_path, "ws33") cli = MultiprojectCLI(progname='multi_cli', config_filename='.rosinstall') simple_rel_rosinstall = os.path.join(self.test_root_path, "simple_rel3.rosinstall") _create_yaml_file([_create_config_elt_dict(scmtype="git", uri=os.path.join(self.test_root_path, "ros"), localname='ros')], simple_rel_rosinstall) self.assertEqual(0, cli.cmd_init([self.local_path, simple_rel_rosinstall])) config = wstool.multiproject_cmd.get_config(basepath=self.local_path, config_filename='.rosinstall') self.assertEqual(1, len(config.get_config_elements())) self.assertEqual('git', config.get_config_elements()[0].get_path_spec().get_scmtype()) wstool.multiproject_cmd.add_uris(config, [self.local_path]) self.assertEqual(len(config.get_config_elements()), 1, config) self.assertEqual('git', config.get_config_elements()[0].get_path_spec().get_scmtype()) wstool.multiproject_cmd.add_uris(config, [os.path.join(self.local_path, '.rosinstall')]) self.assertEqual(len(config.get_config_elements()), 1, config) self.assertEqual('git', config.get_config_elements()[0].get_path_spec().get_scmtype())
def test_cmd_foreach(self): self.local_path = os.path.join(self.test_root_path, 'foreach') cli = MultiprojectCLI(progname='multi_cli', config_filename='.rosinstall') cli.cmd_init([self.local_path, self.simple_rosinstall]) # specified localname sys.stdout = f = StringIO() cli.cmd_foreach(self.local_path, argv=['gitrepo', 'pwd']) sys.stdout = sys.__stdout__ repo_path = lambda localname: os.path.join(self.local_path, localname) self.assertEqual('[gitrepo] %s' % repo_path('gitrepo'), f.getvalue().strip()) # --git option sys.stdout = f = StringIO() cli.cmd_foreach(self.local_path, argv=['--git', 'pwd']) sys.stdout = sys.__stdout__ expected_output = '[ros] %s\n[gitrepo] %s' % (repo_path('ros'), repo_path('gitrepo')) self.assertEqual(expected_output, f.getvalue().strip())
def test_cmd_remove(self): # wstool to create dir self.local_path = os.path.join(self.test_root_path, "ws32") cli = MultiprojectCLI(progname='multi_cli', config_filename='.rosinstall', allow_other_element=False) self.assertEqual(0, cli.cmd_init([self.local_path])) self.assertRaises(MultiProjectException, cli.cmd_merge, self.local_path, [self.git_path, "-y"]) self.assertRaises(MultiProjectException, cli.cmd_merge, self.local_path, [self.hg_path, "-y"]) cli = MultiprojectCLI(progname='multi_cli', config_filename='.rosinstall', allow_other_element=True) 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 = wstool.multiproject_cmd.get_config(basepath=self.local_path, config_filename='.rosinstall') self.assertEqual(len(config.get_config_elements()), 2) self.assertEqual(0, cli.cmd_remove(self.local_path, [self.git_path])) config = wstool.multiproject_cmd.get_config(basepath=self.local_path, config_filename='.rosinstall') self.assertEqual(len(config.get_config_elements()), 1)
def __init__(self, config_filename=ROSINSTALL_FILENAME, progname=_PROGNAME): MultiprojectCLI.__init__( self, progname=progname, config_filename=config_filename, config_generator=wstool.multiproject_cmd.cmd_persist_config)
def test_cmd_info(self): self.local_path = os.path.join(self.test_root_path, "ws_test_cmd_info") cli = MultiprojectCLI(progname='multi_cli', config_filename='.rosinstall') self.assertEqual(0, cli.cmd_info(self.local_path, ['--root']))
def test_cmd_info(self): self.local_path = os.path.join(self.test_root_path, "ws_test_cmd_info") cli = MultiprojectCLI(progname='multi_cli', config_filename='.rosinstall') self.assertEqual(0, cli.cmd_info(self.local_path, [])) self.assertEqual(0, cli.cmd_info(self.local_path, ['--root'])) self.assertEqual(0, cli.cmd_info(self.local_path, ['--yaml'])) self.assertEqual(0, cli.cmd_info(self.local_path, ['--untracked'])) self.assertEqual(0, cli.cmd_init([self.local_path, self.simple_rosinstall, "--parallel=5"])) self.assertEqual(0, cli.cmd_merge(self.local_path, [self.simple_changed_vcs_rosinstall, "-y"])) self.assertEqual(0, cli.cmd_info(self.local_path, [])) self.assertEqual(0, cli.cmd_info(self.local_path, ['gitrepo'])) self.assertEqual(0, cli.cmd_info(self.local_path, ['hgrepo'])) self.assertEqual(0, cli.cmd_info(self.local_path, ['--fetch'])) self.assertEqual(0, cli.cmd_info(self.local_path, ['gitrepo', '--fetch'])) self.assertEqual(0, cli.cmd_info(self.local_path, ['hgrepo', '--fetch']))
def test_cmd_info(self): self.local_path = os.path.join(self.test_root_path, "ws_test_cmd_info") cli = MultiprojectCLI(progname='multi_cli', config_filename='.rosinstall') self.assertEqual(0, cli.cmd_info(self.local_path, [])) self.assertEqual(0, cli.cmd_info(self.local_path, ['--root'])) self.assertEqual(0, cli.cmd_info(self.local_path, ['--yaml'])) self.assertEqual(0, cli.cmd_info(self.local_path, ['--untracked'])) self.assertEqual( 0, cli.cmd_init( [self.local_path, self.simple_rosinstall, "--parallel=5"])) self.assertEqual( 0, cli.cmd_merge(self.local_path, [self.simple_changed_vcs_rosinstall, "-y"])) self.assertEqual(0, cli.cmd_info(self.local_path, [])) self.assertEqual(0, cli.cmd_info(self.local_path, ['gitrepo'])) self.assertEqual(0, cli.cmd_info(self.local_path, ['hgrepo'])) self.assertEqual(0, cli.cmd_info(self.local_path, ['--fetch'])) self.assertEqual(0, cli.cmd_info(self.local_path, ['gitrepo', '--fetch'])) self.assertEqual(0, cli.cmd_info(self.local_path, ['hgrepo', '--fetch']))
def __init__(self, config_filename=ROSINSTALL_FILENAME, progname=_PROGNAME): MultiprojectCLI.__init__(self, progname=progname, config_filename=config_filename, allow_other_element=True, config_generator=rosinstall_cmd.cmd_persist_config)