def test_install(check_error): path = 'c://sagemaker-pytorch-container' _modules.install(path) cmd = [sys.executable, '-m', 'pip', 'install', '-U', '.'] check_error.assert_called_with(cmd, _errors.InstallModuleError, cwd=path) with patch('os.path.exists', return_value=True): _modules.install(path) check_error.assert_called_with(cmd + ['-r', 'requirements.txt'], _errors.InstallModuleError, cwd=path)
def test_install(check_error): path = "c://sagemaker-pytorch-container" _modules.install(path) cmd = [sys.executable, "-m", "pip", "install", "."] check_error.assert_called_with(cmd, _errors.InstallModuleError, cwd=path, capture_error=False) with patch("os.path.exists", return_value=True): _modules.install(path) check_error.assert_called_with( cmd + ["-r", "requirements.txt"], _errors.InstallModuleError, capture_error=False, cwd=path, )
def install(name, dst, capture_error=False): """Install the user provided entry point to be executed as follow: - add the path to sys path - if the user entry point is a command, gives exec permissions to the script Args: name (str): name of the script or module. dst (str): path to directory with the script or module. capture_error (bool): Default false. If True, the running process captures the stderr, and appends it to the returned Exception message in case of errors. """ if dst not in sys.path: sys.path.insert(0, dst) entrypoint_type = entry_point_type(dst, name) if entrypoint_type is EntryPointType.PYTHON_PACKAGE: _modules.install(dst, capture_error) if entrypoint_type is EntryPointType.COMMAND: os.chmod(os.path.join(dst, name), 511)
def test_install_no_python_executable(): with pytest.raises(RuntimeError) as e: _modules.install("git://aws/container-support") assert str( e.value ) == "Failed to retrieve the real path for the Python executable binary"
def test_install_fails(check_error): check_error.side_effect = _errors.ClientError() with pytest.raises(_errors.ClientError): _modules.install("git://aws/container-support")