Resolve CLI script paths and keep notebook conversion files beside their source
This commit is contained in:
parent
bc37483b1a
commit
034108e636
1 changed files with 36 additions and 6 deletions
|
|
@ -1,11 +1,11 @@
|
|||
import importlib
|
||||
from pathlib import Path
|
||||
from threading import Event
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
from watchdog.events import FileClosedEvent, FileModifiedEvent, FileMovedEvent
|
||||
|
||||
from great_ai.deploy.reload_event_handler import ReloadEventHandler
|
||||
from watchdog.events import FileClosedEvent, FileModifiedEvent, FileMovedEvent
|
||||
|
||||
|
||||
def test_reload_debounces_edit_and_replacement_events() -> None:
|
||||
|
|
@ -43,3 +43,22 @@ def test_cli_operational_errors_exit_nonzero(module_name: str, operation: str) -
|
|||
with pytest.raises(SystemExit) as error:
|
||||
module.main()
|
||||
assert error.value.code == 1
|
||||
|
||||
|
||||
def test_cli_resolves_nested_scripts_and_notebooks(
|
||||
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
from great_ai.__main__ import get_script_name, get_script_name_of_notebook
|
||||
|
||||
monkeypatch.syspath_prepend(str(tmp_path))
|
||||
package = tmp_path / "nested"
|
||||
package.mkdir()
|
||||
(package / "__init__.py").write_text("")
|
||||
(package / "service.py").write_text("value = 7\n")
|
||||
monkeypatch.chdir(tmp_path)
|
||||
assert get_script_name("nested/service.py") == "nested.service"
|
||||
assert importlib.import_module("nested.service").value == 7
|
||||
assert get_script_name(str(package / "service.py")) == "nested.service"
|
||||
assert (
|
||||
get_script_name_of_notebook("nested/service.ipynb") == "nested/__service__.py"
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue