示例#1
0
def test_find_executable():
    original_environment = os.environ.get('PATH')
    original_parent_directory = launchers.parent_directory

    root_directory = create_unpackaged_bundle(rename=[],
                                              executables=[echo_args_glibc_32],
                                              chroot=chroot)
    try:
        binary_name = os.path.basename(echo_args_glibc_32)
        binary_symlink = os.path.join(root_directory, 'bin', binary_name)
        binary_path = os.path.realpath(binary_symlink)
        # This is a pretend directory, but it doesn't check.
        launchers.parent_directory = os.path.join(os.path.dirname(binary_path),
                                                  'somewhere', 'else')
        os.environ['PATH'] = os.path.dirname(echo_args_glibc_32)
        assert find_executable(binary_name, skip_original_for_testing=True) == binary_path, \
            'It should have found the binary path "%s".' % binary_path
    finally:
        launchers.parent_directory = original_parent_directory
        os.environ['PATH'] = original_environment
        assert root_directory.startswith('/tmp/')
        shutil.rmtree(root_directory)
 def commands_exist(self):
     """Whether or not the list and owner package manager commands can be resolved."""
     commands = {self.list_command[0], self.owner_command[0]}
     return all(
         find_executable(command) is not None for command in commands)