def test_cmd_add(self): # rosinstall 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 = rosinstall.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()) rosinstall.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()) rosinstall.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_get_element_diff(self): cli = MultiprojectCLI(progname='multi_cli', config_filename='.rosinstall') self.assertEqual('', cli._get_element_diff(None, None)) self.assertEqual('', cli._get_element_diff(None, 42)) self.assertEqual('', cli._get_element_diff(42, None)) spec = PathSpec('foolocalname', scmtype='fooscm', uri='foouri', version='fooversion', path='foopath') spec2 = PathSpec('foolocalname') element2 = MockConfigElement(local_name='foolocalname', spec=spec2) elements = [element2] config = FakeConfig(celts=elements) output = cli._get_element_diff(spec, config) self.assertEqual(' foolocalname', output) output = cli._get_element_diff(spec, config, extra_verbose=True) snippets = [' foolocalname', 'version = fooversion', 'specified uri = foouri', 'scmtype = fooscm'] for s in snippets: self.assertTrue(s in output, "missing snippet: '%s' in '%s'" % (s, output))
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_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 __init__(self, config_filename=ROSINSTALL_FILENAME, progname=_PROGNAME): MultiprojectCLI.__init__( self, progname=progname, config_filename=config_filename, config_generator=rosinstall_cmd.cmd_persist_config)
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.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.assertRaises(SystemExit, cli.cmd_set, os.path.join(self.local_path, 'hgrepo'), ["--detached"]) cli = MultiprojectCLI(progname='multi_cli', config_filename='.rosinstall', allow_other_element=True)
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_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): # rosinstall 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 = rosinstall.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 = rosinstall.multiproject_cmd.get_config( basepath=self.local_path, config_filename='.rosinstall') self.assertEqual(len(config.get_config_elements()), 1)
def test_cmd_remove(self): # rosinstall to create dir self.local_path = os.path.join(self.test_root_path, "ws32") cli = MultiprojectCLI(progname='multi_cli', config_filename='.rosinstall') self.assertEqual(0, cli.cmd_init([self.local_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()), 2) 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()), 1)
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' ])) 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_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_get_element_diff(self): cli = MultiprojectCLI(progname='multi_cli', config_filename='.rosinstall') self.assertEqual('', cli._get_element_diff(None, None)) self.assertEqual('', cli._get_element_diff(None, 42)) self.assertEqual('', cli._get_element_diff(42, None)) spec = PathSpec('foolocalname', scmtype='fooscm', uri='foouri', version='fooversion', path='foopath') spec2 = PathSpec('foolocalname') element2 = MockConfigElement(local_name='foolocalname', spec=spec2) elements = [element2] config = FakeConfig(celts=elements) output = cli._get_element_diff(spec, config) self.assertEqual(' foolocalname', output) output = cli._get_element_diff(spec, config, extra_verbose=True) snippets = [ ' foolocalname', 'version = fooversion', 'specified uri = foouri', 'scmtype = fooscm' ] for s in snippets: self.assertTrue(s in output, "missing snippet: '%s' in '%s'" % (s, output))
def test_cmd_add(self): # rosinstall 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 = rosinstall.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()) rosinstall.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()) rosinstall.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_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 __init__(self, config_filename=ROSINSTALL_FILENAME, progname=_PROGNAME): MultiprojectCLI.__init__( self, progname=progname, config_filename=config_filename, config_generator=rosinstall.multiproject_cmd.cmd_persist_config)