-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NotebookRunner: Run all notebooks in repo directory
* NotebookRunner business now runs all notebooks in a repo by default * Add `disable_run_in_subdirs` option to NotebookRunner business config. This is `False` by default, so the default going forward is that all notebooks in a repo are run by this business. [This phalanx PR] sets this option to `true` in all existing configurations so as not to break any existing workflows. * Add `exclude_dirs` option to NotebookRunner business to list directories in which notebooks will NOT be run
- Loading branch information
Showing
8 changed files
with
1,430 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
# Testing | ||
asgi-lifespan | ||
coverage[toml] | ||
documenteer[guide] | ||
mypy | ||
pre-commit | ||
pytest | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,9 +59,10 @@ async def test_run( | |
"options": { | ||
"spawn_settle_time": 0, | ||
"execution_idle_time": 0, | ||
"max_executions": 1, | ||
"max_executions": 10, | ||
"repo_url": str(repo_path), | ||
"repo_branch": "main", | ||
"disable_run_in_subdirs": True, | ||
"working_directory": str(repo_path), | ||
}, | ||
}, | ||
|
@@ -76,7 +77,7 @@ async def test_run( | |
"business": { | ||
"failure_count": 0, | ||
"name": "NotebookRunner", | ||
"notebook": "test-notebook.ipynb", | ||
"notebook": ANY, | ||
"success_count": 1, | ||
"timings": ANY, | ||
}, | ||
|
@@ -93,9 +94,221 @@ async def test_run( | |
# Get the log and check the cell output. | ||
r = await client.get("/mobu/flocks/test/monkeys/testuser1/log") | ||
assert r.status_code == 200 | ||
|
||
# Root notebook | ||
assert "This is a test" in r.text | ||
assert "This is another test" in r.text | ||
assert "Final test" in r.text | ||
|
||
# some-dir notebook | ||
assert "Test some-dir" not in r.text | ||
|
||
# some-other-dir notebook | ||
assert "Test some-other-dir" not in r.text | ||
|
||
# double-nested-dir notebook | ||
assert "Test double-nested-dir" not in r.text | ||
|
||
# Exceptions | ||
assert "Exception thrown" not in r.text | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_run_subdirs( | ||
client: AsyncClient, respx_mock: respx.Router, tmp_path: Path | ||
) -> None: | ||
mock_gafaelfawr(respx_mock) | ||
cwd = Path.cwd() | ||
|
||
# Set up a notebook repository. | ||
source_path = Path(__file__).parent.parent / "notebooks" | ||
repo_path = tmp_path / "notebooks" | ||
|
||
shutil.copytree(str(source_path), str(repo_path)) | ||
# Remove exception notebook | ||
(repo_path / "exception.ipynb").unlink() | ||
|
||
# Set up git client | ||
git = Git(repo=repo_path) | ||
await git.init("--initial-branch=main") | ||
await git.config("user.email", "[email protected]") | ||
await git.config("user.name", "Git User") | ||
for path in repo_path.iterdir(): | ||
if not path.name.startswith("."): | ||
await git.add(str(path)) | ||
await git.commit("-m", "Initial commit") | ||
|
||
# Start a monkey. We have to do this in a try/finally block since the | ||
# runner will change working directories, which because working | ||
# directories are process-global may mess up future tests. | ||
try: | ||
r = await client.put( | ||
"/mobu/flocks", | ||
json={ | ||
"name": "test", | ||
"count": 1, | ||
"user_spec": {"username_prefix": "testuser"}, | ||
"scopes": ["exec:notebook"], | ||
"business": { | ||
"type": "NotebookRunner", | ||
"options": { | ||
"spawn_settle_time": 0, | ||
"execution_idle_time": 0, | ||
"max_executions": 10, | ||
"repo_url": str(repo_path), | ||
"repo_branch": "main", | ||
"working_directory": str(repo_path), | ||
}, | ||
}, | ||
}, | ||
) | ||
assert r.status_code == 201 | ||
|
||
# Wait until we've finished one loop and check the results. | ||
data = await wait_for_business(client, "testuser1") | ||
assert data == { | ||
"name": "testuser1", | ||
"business": { | ||
"failure_count": 0, | ||
"name": "NotebookRunner", | ||
"notebook": ANY, | ||
"success_count": 1, | ||
"timings": ANY, | ||
}, | ||
"state": "RUNNING", | ||
"user": { | ||
"scopes": ["exec:notebook"], | ||
"token": ANY, | ||
"username": "testuser1", | ||
}, | ||
} | ||
finally: | ||
os.chdir(cwd) | ||
|
||
# Get the log and check the cell output. | ||
r = await client.get("/mobu/flocks/test/monkeys/testuser1/log") | ||
assert r.status_code == 200 | ||
|
||
# Root notebook | ||
assert "This is a test" in r.text | ||
assert "This is another test" in r.text | ||
assert "Final test" in r.text | ||
|
||
# some-dir notebook | ||
assert "Test some-dir" in r.text | ||
assert "Another test some-dir" in r.text | ||
assert "Final test some-dir" in r.text | ||
|
||
# some-other-dir notebook | ||
assert "Test some-other-dir" in r.text | ||
assert "Another test some-other-dir" in r.text | ||
assert "Final test some-other-dir" in r.text | ||
|
||
# double-nested-dir notebook | ||
assert "Test double-nested-dir" in r.text | ||
assert "Another test double-nested-dir" in r.text | ||
assert "Final test double-nested-dir" in r.text | ||
|
||
# Exceptions | ||
assert "Exception thrown" not in r.text | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_exclude_dirs( | ||
client: AsyncClient, respx_mock: respx.Router, tmp_path: Path | ||
) -> None: | ||
mock_gafaelfawr(respx_mock) | ||
cwd = Path.cwd() | ||
|
||
# Set up a notebook repository. | ||
source_path = Path(__file__).parent.parent / "notebooks" | ||
repo_path = tmp_path / "notebooks" | ||
|
||
shutil.copytree(str(source_path), str(repo_path)) | ||
# Remove exception notebook | ||
(repo_path / "exception.ipynb").unlink() | ||
|
||
# Set up git client | ||
git = Git(repo=repo_path) | ||
await git.init("--initial-branch=main") | ||
await git.config("user.email", "[email protected]") | ||
await git.config("user.name", "Git User") | ||
for path in repo_path.iterdir(): | ||
if not path.name.startswith("."): | ||
await git.add(str(path)) | ||
await git.commit("-m", "Initial commit") | ||
|
||
# Start a monkey. We have to do this in a try/finally block since the | ||
# runner will change working directories, which because working | ||
# directories are process-global may mess up future tests. | ||
try: | ||
r = await client.put( | ||
"/mobu/flocks", | ||
json={ | ||
"name": "test", | ||
"count": 1, | ||
"user_spec": {"username_prefix": "testuser"}, | ||
"scopes": ["exec:notebook"], | ||
"business": { | ||
"type": "NotebookRunner", | ||
"options": { | ||
"spawn_settle_time": 0, | ||
"execution_idle_time": 0, | ||
"max_executions": 10, | ||
"repo_url": str(repo_path), | ||
"repo_branch": "main", | ||
"working_directory": str(repo_path), | ||
"exclude_dirs": ["some-other-dir/nested-dir"], | ||
}, | ||
}, | ||
}, | ||
) | ||
assert r.status_code == 201 | ||
|
||
# Wait until we've finished one loop and check the results. | ||
data = await wait_for_business(client, "testuser1") | ||
assert data == { | ||
"name": "testuser1", | ||
"business": { | ||
"failure_count": 0, | ||
"name": "NotebookRunner", | ||
"notebook": ANY, | ||
"success_count": 1, | ||
"timings": ANY, | ||
}, | ||
"state": "RUNNING", | ||
"user": { | ||
"scopes": ["exec:notebook"], | ||
"token": ANY, | ||
"username": "testuser1", | ||
}, | ||
} | ||
finally: | ||
os.chdir(cwd) | ||
|
||
# Get the log and check the cell output. | ||
r = await client.get("/mobu/flocks/test/monkeys/testuser1/log") | ||
assert r.status_code == 200 | ||
|
||
# Root notebook | ||
assert "This is a test" in r.text | ||
assert "This is another test" in r.text | ||
assert "Final test" in r.text | ||
|
||
# some-dir notebook | ||
assert "Test some-dir" in r.text | ||
assert "Another test some-dir" in r.text | ||
assert "Final test some-dir" in r.text | ||
|
||
# some-other-dir notebook | ||
assert "Test some-other-dir" in r.text | ||
assert "Another test some-other-dir" in r.text | ||
assert "Final test some-other-dir" in r.text | ||
|
||
# nested-dir notebook | ||
assert "Test double-nested-dir" not in r.text | ||
|
||
# Exceptions | ||
assert "Exception thrown" not in r.text | ||
|
||
|
||
|
@@ -145,6 +358,7 @@ async def test_alert( | |
"max_executions": 1, | ||
"repo_url": str(repo_path), | ||
"repo_branch": "main", | ||
"disable_run_in_subdirs": True, | ||
}, | ||
}, | ||
}, | ||
|
Oops, something went wrong.