def test_keys(self): sources_cache = get_cache_dir() cmd_extras = ['-c', sources_cache] try: with fakeout() as b: rosdep_main(['keys', 'rospack_fake'] + cmd_extras) stdout, stderr = b assert stdout.getvalue().strip() == 'testtinyxml', stdout.getvalue() assert not stderr.getvalue(), stderr.getvalue() with fakeout() as b: rosdep_main(['keys', 'rospack_fake', '--os', 'ubuntu:lucid', '--verbose'] + cmd_extras) stdout, stderr = b assert stdout.getvalue().strip() == 'testtinyxml', stdout.getvalue() with fakeout() as b: rosdep_main(['keys', 'another_catkin_package'] + cmd_extras + ['-i']) stdout, stderr = b assert stdout.getvalue().strip() == 'catkin', stdout.getvalue() with fakeout() as b: rosdep_main(['keys', 'multi_dep_type_catkin_package', '-t', 'test', '-t', 'doc'] + cmd_extras) stdout, stderr = b output_keys = set(stdout.getvalue().split()) expected_keys = set(['curl', 'epydoc']) assert output_keys == expected_keys, stdout.getvalue() except SystemExit: assert False, 'system exit occurred' try: rosdep_main(['keys', 'nonexistent'] + cmd_extras) assert False, 'system exit should have occurred' except SystemExit: pass
def test_invalid_package_message(self): with fakeout() as b: test_package_dir = os.path.abspath(os.path.join(get_test_dir(), 'main', 'invalid_package_version')) with patch('rosdep2.main.sys.exit') as exit_mock: rosdep_main(['install', '--from-path', test_package_dir]) exit_mock.assert_called_with(1) stdout, stderr = b output = stdout.getvalue().splitlines() assert len(output) == 2 assert test_package_dir in output[0] assert 'Package version ":{version}" does not follow version conventions' in output[1]
def test_bad_commands(self): sources_cache = get_cache_dir() cmd_extras = ['-c', sources_cache] for commands in [[], ['fake', 'something'], ['check'], ['install', '-a', 'rospack_fake'], ['check', 'rospack_fake', '--os', 'ubuntulucid'], ]: try: rosdep_main(commands+cmd_extras) assert False, "system exit should have occurred" except SystemExit: pass
def test_bad_commands(self): sources_cache = get_cache_dir() cmd_extras = ['-c', sources_cache] for commands in [[], ['fake', 'something'], ['check'], ['install', '-a', 'rospack_fake'], ['check', 'rospack_fake', '--os', 'ubuntulucid'], ]: try: rosdep_main(commands + cmd_extras) assert False, 'system exit should have occurred' except SystemExit: pass
def test_where_defined(self): try: sources_cache = get_cache_dir() expected = GITHUB_PYTHON_URL for command in (['where_defined', 'testpython'], ['where_defined', 'testpython']): with fakeout() as b: # set os to ubuntu so this test works on different platforms rosdep_main(command + ['-c', sources_cache, '--os=ubuntu:lucid']) stdout, stderr = b output = stdout.getvalue().strip() assert output == expected, output except SystemExit: assert False, 'system exit occurred'
def test_where_defined(self): try: sources_cache = get_cache_dir() expected = GITHUB_PYTHON_URL for command in (['where_defined', 'testpython'], ['where_defined', 'testpython']): with fakeout() as b: # set os to ubuntu so this test works on different platforms rosdep_main(command + ['-c', sources_cache, '--os=ubuntu:lucid']) stdout, stderr = b output = stdout.getvalue().strip() assert output == expected, output except SystemExit: assert False, "system exit occurred"
def test_install(self, mock_geteuid, mock_read_stdout): sources_cache = get_cache_dir() cmd_extras = ['-c', sources_cache] catkin_tree = get_test_catkin_tree_dir() def read_stdout(cmd, capture_stderr=False): if cmd[0] == 'apt-cache' and cmd[1] == 'showpkg': result = '' elif cmd[0] == 'dpkg-query': if cmd[-1] == 'python-dev': result = '\'python-dev install ok installed\n\'' else: result = '\n'.join([ "dpkg-query: no packages found matching %s" % f for f in cmd[3:] ]) if capture_stderr: return result, '' return result try: mock_read_stdout.side_effect = read_stdout # python must have already been installed with fakeout() as b: rosdep_main(['install', 'python_dep'] + cmd_extras) stdout, stderr = b assert 'All required rosdeps installed' in stdout.getvalue( ), stdout.getvalue() assert not stderr.getvalue(), stderr.getvalue() with fakeout() as b: rosdep_main(['install', 'python_dep', '-r'] + cmd_extras) stdout, stderr = b assert 'All required rosdeps installed' in stdout.getvalue( ), stdout.getvalue() assert not stderr.getvalue(), stderr.getvalue() with fakeout() as b: rosdep_main([ 'install', '-s', '-i', '--os', 'ubuntu:lucid', '--rosdistro', 'fuerte', '--from-paths', catkin_tree ] + cmd_extras) stdout, stderr = b expected = [ '#[apt] Installation commands:', ' sudo -H apt-get install ros-fuerte-catkin', ' sudo -H apt-get install libboost1.40-all-dev' ] lines = stdout.getvalue().splitlines() assert set(lines) == set(expected), lines assert not stderr.getvalue(), stderr.getvalue() except SystemExit: assert False, 'system exit occurred: ' + b[1].getvalue() try: rosdep_main(['install', 'nonexistent']) assert False, 'system exit should have occurred' except SystemExit: pass
def test_what_needs(self): try: sources_cache = get_cache_dir() cmd_extras = ['-c', sources_cache] expected = ['python_dep'] with fakeout() as b: rosdep_main(['what-needs', 'testpython']+cmd_extras) stdout, stderr = b output = stdout.getvalue().strip() assert output.split('\n') == expected expected = ['python_dep'] with fakeout() as b: rosdep_main(['what_needs', 'testpython', '--os', 'ubuntu:lucid', '--verbose']+cmd_extras) stdout, stderr = b output = stdout.getvalue().strip() assert output.split('\n') == expected except SystemExit: assert False, "system exit occurred"
def test_what_needs(self): try: sources_cache = get_cache_dir() cmd_extras = ['-c', sources_cache] expected = ['python_dep'] with fakeout() as b: rosdep_main(['what-needs', 'testpython'] + cmd_extras) stdout, stderr = b output = stdout.getvalue().strip() assert output.split('\n') == expected expected = ['python_dep'] with fakeout() as b: rosdep_main(['what_needs', 'testpython', '--os', 'ubuntu:lucid', '--verbose'] + cmd_extras) stdout, stderr = b output = stdout.getvalue().strip() assert output.split('\n') == expected except SystemExit: assert False, 'system exit occurred'
def test_install(self, mock_read_stdout): sources_cache = get_cache_dir() cmd_extras = ['-c', sources_cache] catkin_tree = get_test_catkin_tree_dir() def read_stdout(cmd, capture_stderr=False): if cmd[0] == 'apt-cache' and cmd[1] == 'showpkg': result = '' elif cmd[0] == 'dpkg-query': if cmd[-1] == 'python-dev': result = '\'python-dev install ok installed\n\'' else: result = '\n'.join(["dpkg-query: no packages found matching %s" % f for f in cmd[3:]]) if capture_stderr: return result, '' return result try: mock_read_stdout.side_effect = read_stdout # python must have already been installed with fakeout() as b: rosdep_main(['install', 'python_dep'] + cmd_extras) stdout, stderr = b assert 'All required rosdeps installed' in stdout.getvalue(), stdout.getvalue() assert not stderr.getvalue(), stderr.getvalue() with fakeout() as b: rosdep_main(['install', 'python_dep', '-r'] + cmd_extras) stdout, stderr = b assert 'All required rosdeps installed' in stdout.getvalue(), stdout.getvalue() assert not stderr.getvalue(), stderr.getvalue() with fakeout() as b: rosdep_main([ 'install', '-s', '-i', '--os', 'ubuntu:lucid', '--rosdistro', 'fuerte', '--from-paths', catkin_tree ] + cmd_extras) stdout, stderr = b expected = [ '#[apt] Installation commands:', ' sudo -H apt-get install ros-fuerte-catkin', ' sudo -H apt-get install libboost1.40-all-dev' ] lines = stdout.getvalue().splitlines() assert set(lines) == set(expected), lines assert not stderr.getvalue(), stderr.getvalue() except SystemExit: assert False, 'system exit occurred: ' + b[1].getvalue() try: rosdep_main(['install', 'nonexistent']) assert False, 'system exit should have occurred' except SystemExit: pass
def test_keys(self): sources_cache = get_cache_dir() cmd_extras = ['-c', sources_cache] try: with fakeout() as b: rosdep_main(['keys', 'rospack_fake'] + cmd_extras) stdout, stderr = b assert stdout.getvalue().strip( ) == 'testtinyxml', stdout.getvalue() assert not stderr.getvalue(), stderr.getvalue() with fakeout() as b: rosdep_main([ 'keys', 'rospack_fake', '--os', 'ubuntu:lucid', '--verbose' ] + cmd_extras) stdout, stderr = b assert stdout.getvalue().strip( ) == 'testtinyxml', stdout.getvalue() except SystemExit: assert False, 'system exit occurred' try: rosdep_main(['keys', 'nonexistent'] + cmd_extras) assert False, 'system exit should have occurred' except SystemExit: pass
def test_install(self): sources_cache = get_cache_dir() cmd_extras = ['-c', sources_cache] try: # python must have already been installed with fakeout() as b: rosdep_main(['install', 'python_dep'] + cmd_extras) stdout, stderr = b assert "All required rosdeps installed" in stdout.getvalue( ), stdout.getvalue() assert not stderr.getvalue(), stderr.getvalue() with fakeout() as b: rosdep_main(['install', 'python_dep', '-r'] + cmd_extras) stdout, stderr = b assert "All required rosdeps installed" in stdout.getvalue( ), stdout.getvalue() assert not stderr.getvalue(), stderr.getvalue() except SystemExit: assert False, "system exit occurred: " + b[1].getvalue() try: rosdep_main(['check', 'nonexistent']) assert False, "system exit should have occurred" except SystemExit: pass
def install_dependencies(workspace): try: from rosdep2.main import rosdep_main except ImportError: sys.stderr.write( "Cannot import rosdep libraries. Did you source setup.{sh,bash,zsh}?\n" ) sys.exit(os.EX_UNAVAILABLE) try: os.environ['ROS_PACKAGE_PATH'] except KeyError: sys.stderr.write( "ROS environment variables not set. Did you source setup.{sh,bash,zsh}?\n" ) sys.exit(os.EX_UNAVAILABLE) # super lazy, eventually should use rosdep's official API classes, but it's # a lot of work for no gain rosdep_main( ['install', '-y', '-i', '--from-path', path.join(workspace, 'src')])
def test_check(self): sources_cache = get_cache_dir() cmd_extras = ['-c', sources_cache] with fakeout() as b: try: rosdep_main(['check', 'python_dep'] + cmd_extras) except SystemExit: assert False, 'system exit occurred: %s\n%s' % ( b[0].getvalue(), b[1].getvalue()) stdout, stderr = b assert stdout.getvalue().strip( ) == 'All system dependencies have been satisfied', stdout.getvalue( ) assert not stderr.getvalue(), stderr.getvalue() try: osd = rospkg.os_detect.OsDetect() override = '%s:%s' % (osd.get_name(), osd.get_codename()) with fakeout() as b: rosdep_main(['check', 'python_dep', '--os', override] + cmd_extras) stdout, stderr = b assert stdout.getvalue().strip( ) == 'All system dependencies have been satisfied' assert not stderr.getvalue(), stderr.getvalue() except SystemExit: assert False, 'system exit occurred' # this used to abort, but now rosdep assumes validity for even empty stack args try: with fakeout() as b: rosdep_main(['check', 'packageless'] + cmd_extras) stdout, stderr = b assert stdout.getvalue().strip( ) == 'All system dependencies have been satisfied' assert not stderr.getvalue(), stderr.getvalue() except SystemExit: assert False, 'system exit occurred' try: rosdep_main(['check', 'nonexistent'] + cmd_extras) assert False, 'system exit should have occurred' except SystemExit: pass
def test_install(self): sources_cache = get_cache_dir() cmd_extras = ['-c', sources_cache] catkin_tree = get_test_catkin_tree_dir() try: # python must have already been installed with fakeout() as b: rosdep_main(['install', 'python_dep'] + cmd_extras) stdout, stderr = b assert "All required rosdeps installed" in stdout.getvalue( ), stdout.getvalue() assert not stderr.getvalue(), stderr.getvalue() with fakeout() as b: rosdep_main(['install', 'python_dep', '-r'] + cmd_extras) stdout, stderr = b assert "All required rosdeps installed" in stdout.getvalue( ), stdout.getvalue() assert not stderr.getvalue(), stderr.getvalue() with fakeout() as b: rosdep_main([ 'install', '-s', '-i', '--os', 'ubuntu:lucid', '--rosdistro', 'fuerte', '--from-paths', catkin_tree ] + cmd_extras) stdout, stderr = b expected = [ '#[apt] Installation commands:', ' sudo -H apt-get install ros-fuerte-catkin', ' sudo -H apt-get install libboost1.40-all-dev' ] lines = stdout.getvalue().splitlines() assert set(lines) == set(expected), lines assert not stderr.getvalue(), stderr.getvalue() except SystemExit: assert False, "system exit occurred: " + b[1].getvalue() try: rosdep_main(['install', 'nonexistent']) assert False, "system exit should have occurred" except SystemExit: pass
def test_install(self): sources_cache = get_cache_dir() cmd_extras = ['-c', sources_cache] catkin_tree = get_test_catkin_tree_dir() try: # python must have already been installed with fakeout() as b: rosdep_main(['install', 'python_dep'] + cmd_extras) stdout, stderr = b assert 'All required rosdeps installed' in stdout.getvalue(), stdout.getvalue() assert not stderr.getvalue(), stderr.getvalue() with fakeout() as b: rosdep_main(['install', 'python_dep', '-r'] + cmd_extras) stdout, stderr = b assert 'All required rosdeps installed' in stdout.getvalue(), stdout.getvalue() assert not stderr.getvalue(), stderr.getvalue() with fakeout() as b: rosdep_main([ 'install', '-s', '-i', '--os', 'ubuntu:lucid', '--rosdistro', 'fuerte', '--from-paths', catkin_tree ] + cmd_extras) stdout, stderr = b expected = [ '#[apt] Installation commands:', ' sudo -H apt-get install ros-fuerte-catkin', ' sudo -H apt-get install libboost1.40-all-dev' ] lines = stdout.getvalue().splitlines() assert set(lines) == set(expected), lines assert not stderr.getvalue(), stderr.getvalue() except SystemExit: assert False, 'system exit occurred: ' + b[1].getvalue() try: rosdep_main(['install', 'nonexistent']) assert False, 'system exit should have occurred' except SystemExit: pass
def test_check(self): sources_cache = get_cache_dir() cmd_extras = ['-c', sources_cache] with fakeout() as b: try: rosdep_main(['check', 'python_dep']+cmd_extras) except SystemExit: assert False, "system exit occurred: %s\n%s"%(b[0].getvalue(), b[1].getvalue()) stdout, stderr = b assert stdout.getvalue().strip() == "All system dependencies have been satisified", stdout.getvalue() assert not stderr.getvalue(), stderr.getvalue() try: osd = rospkg.os_detect.OsDetect() override = "%s:%s"%(osd.get_name(), osd.get_codename()) with fakeout() as b: rosdep_main(['check', 'python_dep', '--os', override]+cmd_extras) stdout, stderr = b assert stdout.getvalue().strip() == "All system dependencies have been satisified" assert not stderr.getvalue(), stderr.getvalue() except SystemExit: assert False, "system exit occurred" # this used to abort, but now rosdep assumes validity for even empty stack args try: with fakeout() as b: rosdep_main(['check', 'packageless']+cmd_extras) stdout, stderr = b assert stdout.getvalue().strip() == "All system dependencies have been satisified" assert not stderr.getvalue(), stderr.getvalue() except SystemExit: assert False, "system exit occurred" try: rosdep_main(['check', 'nonexistent']+cmd_extras) assert False, "system exit should have occurred" except SystemExit: pass
def test_keys(self): sources_cache = get_cache_dir() cmd_extras = ['-c', sources_cache] try: with fakeout() as b: rosdep_main(['keys', 'rospack_fake']+cmd_extras) stdout, stderr = b assert stdout.getvalue().strip() == "testtinyxml", stdout.getvalue() assert not stderr.getvalue(), stderr.getvalue() with fakeout() as b: rosdep_main(['keys', 'rospack_fake', '--os', 'ubuntu:lucid', '--verbose']+cmd_extras) stdout, stderr = b assert stdout.getvalue().strip() == "testtinyxml", stdout.getvalue() except SystemExit: assert False, "system exit occurred" try: rosdep_main(['keys', 'nonexistent']+cmd_extras) assert False, "system exit should have occurred" except SystemExit: pass
def test_install(self): sources_cache = get_cache_dir() cmd_extras = ['-c', sources_cache] try: # python must have already been installed with fakeout() as b: rosdep_main(['install', 'python_dep']+cmd_extras) stdout, stderr = b assert "All required rosdeps installed" in stdout.getvalue(), stdout.getvalue() assert not stderr.getvalue(), stderr.getvalue() with fakeout() as b: rosdep_main(['install', 'python_dep', '-r']+cmd_extras) stdout, stderr = b assert "All required rosdeps installed" in stdout.getvalue(), stdout.getvalue() assert not stderr.getvalue(), stderr.getvalue() except SystemExit: assert False, "system exit occurred: "+b[1].getvalue() try: rosdep_main(['check', 'nonexistent']) assert False, "system exit should have occurred" except SystemExit: pass
from PIL import Image from pylab import * from rosdep2.main import rosdep_main rosdep_main()