|
2 | 2 | import os |
3 | 3 | import re |
4 | 4 | import shutil |
| 5 | +import sys |
5 | 6 | from os.path import join |
| 7 | +from types import SimpleNamespace |
6 | 8 | from unittest import TestCase, mock |
7 | 9 |
|
8 | 10 | import click |
|
13 | 15 | from rsconnect import VERSION |
14 | 16 | from rsconnect.api import RSConnectClient, RSConnectServer |
15 | 17 | from rsconnect.json_web_token import SECRET_KEY_ENV |
16 | | -from rsconnect.main import cli, env_management_callback |
| 18 | +from rsconnect.main import cli, env_management_callback, make_notebook_html_bundle |
17 | 19 |
|
18 | 20 | from .utils import ( |
19 | 21 | apply_common_args, |
@@ -303,6 +305,33 @@ def post_application_deploy_callback(request, uri, response_headers): |
303 | 305 | if original_server_value: |
304 | 306 | os.environ["CONNECT_SERVER"] = original_server_value |
305 | 307 |
|
| 308 | + def test_deploy_notebook_static_passes_interpreter_not_version(self): |
| 309 | + # Regression test for #721: deploy_notebook must hand make_notebook_html_bundle |
| 310 | + # the local interpreter *path* (used to run nbconvert), not environment.python, |
| 311 | + # which is only a version string and made nbconvert fail with "No such file or |
| 312 | + # directory". |
| 313 | + fake_env = SimpleNamespace(python="3.12.1", python_interpreter=sys.executable) |
| 314 | + |
| 315 | + with mock.patch("rsconnect.main.Environment.create_python_environment", return_value=fake_env), mock.patch( |
| 316 | + "rsconnect.main.RSConnectExecutor" |
| 317 | + ) as MockExecutor: |
| 318 | + ce = MockExecutor.return_value |
| 319 | + |
| 320 | + runner = CliRunner() |
| 321 | + args = apply_common_args( |
| 322 | + ["deploy", "notebook", get_dir(join("pip1", "dummy.ipynb"))], |
| 323 | + server="http://fake_server", |
| 324 | + key="FAKE_API_KEY", |
| 325 | + ) |
| 326 | + args += ["--static", "--no-verify"] |
| 327 | + result = runner.invoke(cli, args) |
| 328 | + |
| 329 | + assert result.exit_code == 0, result.output |
| 330 | + # make_bundle(make_notebook_html_bundle, file, <python>, hide_all, hide_tagged) |
| 331 | + bundle_args = ce.make_bundle.call_args.args |
| 332 | + assert bundle_args[0] is make_notebook_html_bundle |
| 333 | + assert bundle_args[2] == sys.executable |
| 334 | + |
306 | 335 | @httpretty.activate(verbose=True, allow_net_connect=False) |
307 | 336 | def test_deploy_verify_before_activate(self, caplog): |
308 | 337 | # Without --draft or --no-verify, the default flow deploys the bundle as a |
|
0 commit comments