def test_install_and_run(self): install_dir = install_test_helper.get_install_dir() resource_subfolder = "share/drake/" installed_sentinel = os.path.join(install_dir, resource_subfolder, ".drake-find_resource-sentinel") # Verifies that the sentinel file exists in the installed directory. # If it has been removed, we need to update this test. self.assertTrue(os.path.isfile(installed_sentinel)) # Create a resource in the temporary directory. tmp_dir = install_test_helper.create_temporary_dir() resource_folder = os.path.join(tmp_dir, resource_subfolder) test_folder = os.path.join(resource_folder, "common/test") os.makedirs(test_folder) # Create sentinel file. sentinel = os.path.join(resource_folder, os.path.basename(installed_sentinel)) os.symlink(installed_sentinel, sentinel) # Create resource file. resource = os.path.join(test_folder, "tmp_resource") resource_data = "tmp_resource" with open(resource, "w") as f: f.write(resource_data) # Cross-check the resource root environment variable name. env_name = "DRAKE_RESOURCE_ROOT" resource_tool = os.path.join(install_dir, "share/drake/common/resource_tool") output_name = install_test_helper.check_output([ resource_tool, "--print_resource_root_environment_variable_name", ], ).strip() self.assertEqual(output_name, env_name) # Use the installed resource_tool to find a resource. tool_env = dict(os.environ) tool_env[env_name] = os.path.join(tmp_dir, "share") absolute_path = install_test_helper.check_output( [ resource_tool, "--print_resource_path", "drake/common/test/tmp_resource", ], env=tool_env, ).strip() with open(absolute_path, 'r') as data: self.assertEqual(data.read(), resource_data) # Use --add_resource_search_path instead of environment variable # to find resources. absolute_path = install_test_helper.check_output([ resource_tool, "--print_resource_path", "drake/common/test/tmp_resource", "--add_resource_search_path", os.path.join(tmp_dir, "share"), ], ).strip() with open(absolute_path, 'r') as data: self.assertEqual(data.read(), resource_data)
def test_install(self): # Get install directory. install_dir = install_test_helper.get_install_dir() executable_folder = os.path.join(install_dir, "bin") try: install_test_helper.check_output( [os.path.join(executable_folder, "drake-lcm-spy"), "--help"], stderr=subprocess.STDOUT) # If the process doesn't fail, we cannot test the string # returned in the exception output. Since this should not # happen, we fail here. If lcm is updated to return 0 when # "--help" is called, this test will fail and will need to be # updated. self.fail( "drake-lcm-spy execution passed instead of failing. Update test" # noqa ) except subprocess.CalledProcessError as e: self.assertIn("usage: lcm-spy [options]", e.output.decode("utf8"))
def test_install(self): # Get install directory. install_dir = install_test_helper.get_install_dir() executable_folder = os.path.join(install_dir, "bin") try: install_test_helper.check_output( [os.path.join(executable_folder, "drake-lcm-spy"), "--help"], stderr=subprocess.STDOUT ) # If the process doesn't fail, we cannot test the string # returned in the exception output. Since this should not # happen, we fail here. If lcm is updated to return 0 when # "--help" is called, this test will fail and will need to be # updated. self.fail( "drake-lcm-spy execution passed instead of failing. Update test" # noqa ) except subprocess.CalledProcessError as e: self.assertIn("usage: lcm-spy [options]", e.output)
def testDrakeFindResourceOrThrowInInstall(self): # Override PYTHONPATH to only use the installed `pydrake` module. install_dir = install_test_helper.get_install_dir() env_python_path = "PYTHONPATH" tool_env = dict(os.environ) tool_env[env_python_path] = \ install_test_helper.get_python_site_packages_dir(install_dir) data_folder = os.path.join(install_dir, "share", "drake") # Calling `pydrake.getDrakePath()` twice verifies that there # is no memory allocation issue in the C code. output_path = install_test_helper.check_output( [install_test_helper.get_python_executable(), "-c", "import pydrake; print(pydrake.getDrakePath());\ import pydrake; print(pydrake.getDrakePath())" ], env=tool_env, ).strip() self.assertIn(data_folder, output_path)
def test_help(self): """Ensures we can call `./bin/drake-visualizer --help` from install.""" # Get install directory. install_dir = install_test_helper.get_install_dir() # N.B. Do not update PYTHONPATH, as the script should handle that # itself. bin_path = join(install_dir, "bin", "drake-visualizer") text = install_test_helper.check_output([bin_path, "--help"]) # N.B. This should be kept in sync with # `drake_visualizer_bazel_test`. print(text) # Test for nominal help string. self.assertIn("usage: drake-visualizer ", text) self.assertNotIn("drake-visualizer: error: unrecognized arguments", text) # Test for modifications in help text. self.assertIn("--use_builtin_scripts", text) self.assertIn("Options: all,", text)
def testDrakeFindResourceOrThrowInInstall(self): # Override PYTHONPATH to only use the installed `pydrake` module. install_dir = install_test_helper.get_install_dir() env_python_path = "PYTHONPATH" tool_env = dict(os.environ) tool_env[env_python_path] = \ install_test_helper.get_python_site_packages_dir(install_dir) data_folder = os.path.join(install_dir, "share", "drake") # Calling `pydrake.getDrakePath()` twice verifies that there # is no memory allocation issue in the C code. output_path = install_test_helper.check_output( [ install_test_helper.get_python_executable(), "-c", "import pydrake; print(pydrake.getDrakePath());\ import pydrake; print(pydrake.getDrakePath())" ], env=tool_env, ).strip() self.assertIn(data_folder, output_path)
def test_install_and_run(self): install_dir = install_test_helper.get_install_dir() resource_subfolder = "share/drake/" installed_sentinel = os.path.join(install_dir, resource_subfolder, ".drake-find_resource-sentinel") # Verifies that the sentinel file exists in the installed directory. # If it has been removed, we need to update this test. self.assertTrue(os.path.isfile(installed_sentinel)) # Create a resource in the temporary directory. tmp_dir = install_test_helper.create_temporary_dir() resource_folder = os.path.join(tmp_dir, resource_subfolder) test_folder = os.path.join(resource_folder, "common/test") os.makedirs(test_folder) # Create sentinel file. sentinel = os.path.join(resource_folder, os.path.basename(installed_sentinel)) os.symlink(installed_sentinel, sentinel) # Create resource file. resource = os.path.join(test_folder, "tmp_resource") resource_data = "tmp_resource" with open(resource, "w") as f: f.write(resource_data) # Cross-check the resource root environment variable name. env_name = "DRAKE_RESOURCE_ROOT" resource_tool = os.path.join( install_dir, "share/drake/common/resource_tool") output_name = install_test_helper.check_output( [resource_tool, "--print_resource_root_environment_variable_name", ], ).strip() self.assertEqual(output_name, env_name) # Use the installed resource_tool to find a resource. tool_env = dict(os.environ) tool_env[env_name] = os.path.join(tmp_dir, "share") absolute_path = install_test_helper.check_output( [resource_tool, "--print_resource_path", "drake/common/test/tmp_resource", ], env=tool_env, ).strip() with open(absolute_path, 'r') as data: self.assertEqual(data.read(), resource_data) # Use the installed resource_tool to find a directory. # (This feature is deprecated and will eventually be removed.) absolute_path = install_test_helper.check_output( [resource_tool, "--print_resource_path", "drake/common/test", ], env=tool_env, ).strip() with open(absolute_path + '/tmp_resource', 'r') as data: self.assertEqual(data.read(), resource_data) # Use the installed resource_tool to find a resource, but with a bogus # DRAKE_RESOURCE_ROOT that should be ignored. tool_env[env_name] = os.path.join(tmp_dir, "share", "drake") full_text = install_test_helper.check_output( [resource_tool, "--print_resource_path", "drake/examples/pendulum/Pendulum.urdf", ], env=tool_env, stderr=subprocess.STDOUT, ).strip() warning = full_text.splitlines()[0] absolute_path = full_text.splitlines()[-1] self.assertIn("FindResource ignoring DRAKE_RESOURCE_ROOT", warning) self.assertTrue(os.path.exists(absolute_path), absolute_path + " does not exist") # Use --add_resource_search_path instead of environment variable # to find resources. # (This feature is deprecated and will eventually be removed.) absolute_path = install_test_helper.check_output( [resource_tool, "--print_resource_path", "drake/common/test/tmp_resource", "--add_resource_search_path", os.path.join(tmp_dir, "share"), ], ).strip() with open(absolute_path, 'r') as data: self.assertEqual(data.read(), resource_data)
def test_install_and_run(self): install_dir = install_test_helper.get_install_dir() resource_subfolder = "share/drake/" installed_sentinel = os.path.join(install_dir, resource_subfolder, ".drake-find_resource-sentinel") # Verifies that the sentinel file exists in the installed directory. # If it has been removed, we need to update this test. self.assertTrue(os.path.isfile(installed_sentinel)) # Create a resource in the temporary directory. tmp_dir = install_test_helper.create_temporary_dir() resource_folder = os.path.join(tmp_dir, resource_subfolder) test_folder = os.path.join(resource_folder, "common/test") os.makedirs(test_folder) # Create sentinel file. sentinel = os.path.join(resource_folder, os.path.basename(installed_sentinel)) os.symlink(installed_sentinel, sentinel) # Create resource file. resource = os.path.join(test_folder, "tmp_resource") resource_data = "tmp_resource" with open(resource, "w") as f: f.write(resource_data) # Cross-check the resource root environment variable name. env_name = "DRAKE_RESOURCE_ROOT" resource_tool = os.path.join( install_dir, "share/drake/common/resource_tool") output_name = install_test_helper.check_output( [resource_tool, "--print_resource_root_environment_variable_name", ], ).strip() self.assertEqual(output_name, env_name) # Use the installed resource_tool to find a resource. tool_env = dict(os.environ) tool_env[env_name] = os.path.join(tmp_dir, "share") absolute_path = install_test_helper.check_output( [resource_tool, "--print_resource_path", "drake/common/test/tmp_resource", ], env=tool_env, ).strip() with open(absolute_path, 'r') as data: self.assertEqual(data.read(), resource_data) # Use --add_resource_search_path instead of environment variable # to find resources. absolute_path = install_test_helper.check_output( [resource_tool, "--print_resource_path", "drake/common/test/tmp_resource", "--add_resource_search_path", os.path.join(tmp_dir, "share"), ], ).strip() with open(absolute_path, 'r') as data: self.assertEqual(data.read(), resource_data)
def test_check_output(self): python = install_test_helper.get_python_executable() output = install_test_helper.check_output([python, "--help"]) self.assertIn('PYTHONPATH', output)