Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run doctests in pytest. Add linters to pre-commit. Add a pre-commit workflow. #96

Merged
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9774ec4
add test_docs.py
aliddell Oct 6, 2023
0013842
doctest all python files
aliddell Oct 6, 2023
f8b98fa
add pre-commit.yml
aliddell Oct 6, 2023
9035cba
always_run: false, types are markdown, text, and python
aliddell Oct 6, 2023
82e293f
.md/.py
aliddell Oct 6, 2023
f13049a
remove doctest from pyproject.toml (part of the standard library �)
aliddell Oct 6, 2023
0d00968
check rust files in doctests
aliddell Oct 6, 2023
03245c8
Install dependencies for pre-commit workflow
aliddell Oct 6, 2023
cf6ee4d
don't forget test_rust_sources
aliddell Oct 6, 2023
edd81ab
reformat test_spinnaker.py
aliddell Oct 6, 2023
0961751
add ruff and cargo-fmt to pre-commit
aliddell Oct 9, 2023
39d81fe
remove 'triggered' label from 'Finite triggered acquisition'
aliddell Oct 9, 2023
5f1452e
install ruff with testing dependencies
aliddell Oct 9, 2023
8b4f482
wip
aliddell Oct 9, 2023
a9c8135
wip
aliddell Oct 9, 2023
5690cd7
wip
aliddell Oct 9, 2023
419b48d
skip .pyi files when ruff linting
aliddell Oct 9, 2023
07a3fcb
permit from acquire import * in __init__.py, instruct ruff to ignore it.
aliddell Oct 9, 2023
199ccb0
Update doctest name
aliddell Oct 9, 2023
b6fbf45
update submodules
aliddell Nov 15, 2023
565c78e
Remove doctests from pre-commit. Add them to test_pr.yml. Check .pyi …
aliddell Nov 15, 2023
f74b2bc
Revert "update submodules"
aliddell Nov 15, 2023
e0ef3b3
Merge remote-tracking branch 'upstream/main' into 92-run-tests-on-doc…
aliddell Dec 12, 2023
e6fced1
Cargo format.
aliddell Dec 12, 2023
dfbfaab
Update ruff config to ignore __init__.py (from .acquire import *) is …
aliddell Dec 12, 2023
afcfa05
Fix pyi files to make ruff happy.
aliddell Dec 12, 2023
f3b6a43
Update pre-commit job name.
aliddell Dec 12, 2023
a5c0718
Remove test_docs.py. Update `add_opts` entry in pytest config. Trunca…
aliddell Dec 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: pre-commit

on:
pull_request:
push:
branches: [ main ]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true

- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"

- name: Install
run: |
pip install --upgrade pip
pip install -e '.[testing]'

- name: Run pre-commit
uses: pre-commit/[email protected]
10 changes: 9 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,12 @@ repos:
rev: v1.2.7
hooks:
- id: import-linter
stages: [manual]
stages: [manual]
- repo: local
hooks:
- id: doctest
name: Document tests
entry: python tests/test_docs.py
language: system
types: [file]
files: \.(md|py|rs)$
44 changes: 22 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,30 @@ The provided [napari][] plugin is a good example of how to stream for visualizat

### List devices

```python
import acquire
print(acquire.Runtime().device_manager().devices())
```python-repl
>>> import acquire
>>> print(acquire.Runtime().device_manager().devices()) # doctest: +SKIP
```

### Finite triggered acquisition

```python
import acquire
runtime = acquire.Runtime()
dm = runtime.device_manager()

props = runtime.get_configuration()
# select the first Hamamatsu camera
props.video[0].camera.identifier = dm.select(DeviceKind.Camera, "hamamatsu.*")
# stream to zarr
props.video[0].storage.identifier = dm.select(DeviceKind.Storage, "zarr")
props.video[0].storage.settings.filename = "out.zarr"
props.video[0].camera.settings.shape = (2304, 2304)
props.video[0].camera.settings.pixel_type = SampleType.U16
props.video[0].max_frame_count = 100
props = runtime.set_configuration(props)

runtime.start()
runtime.stop() # wait for acquisition to complete
```python-repl
>>> import acquire
>>> runtime = acquire.Runtime()
>>> dm = runtime.device_manager()
>>> props = runtime.get_configuration()
>>> # select the first Hamamatsu camera
>>> props.video[0].camera.identifier = dm.select(acquire.DeviceKind.Camera, "hamamatsu.*")
>>> # stream to zarr
>>> props.video[0].storage.identifier = dm.select(acquire.DeviceKind.Storage, "zarr")
>>> props.video[0].storage.settings.filename = "out.zarr"
>>> props.video[0].camera.settings.shape = (2304, 2304)
>>> props.video[0].camera.settings.pixel_type = acquire.SampleType.U16
>>> props.video[0].max_frame_count = 100
>>> props = runtime.set_configuration(props)
>>> runtime.start() # doctest: +SKIP
>>> # wait for acquisition to complete
>>> runtime.stop() # doctest: +SKIP
aliddell marked this conversation as resolved.
Show resolved Hide resolved
```

# Development
Expand Down Expand Up @@ -122,7 +121,8 @@ In order to configure which release of each driver to use, you can set the value
"acquire-driver-common": "0.1.0",
"acquire-driver-hdcam": "0.1.0",
"acquire-driver-egrabber": "0.1.0",
"acquire-driver-zarr": "0.1.0"
"acquire-driver-zarr": "0.1.0",
"acquire-driver-spinnaker": "0.1.0"
}
```

Expand Down
34 changes: 34 additions & 0 deletions tests/test_docs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import doctest
aliddell marked this conversation as resolved.
Show resolved Hide resolved
import pytest

from pathlib import Path


@pytest.fixture(autouse=True)
def base_dir():
return Path(__file__).parent.parent


def test_readme(base_dir):
readme_path = base_dir / "README.md"
assert (
doctest.testfile(str(readme_path), module_relative=False).failed == 0
)


def test_modules(base_dir):
for module in base_dir.glob("python/**/*.py"):
assert doctest.testfile(str(module), module_relative=False).failed == 0


def test_rust_sources(base_dir):
for f in base_dir.glob("src/**/*.rs"):
aliddell marked this conversation as resolved.
Show resolved Hide resolved
assert doctest.testfile(str(f), module_relative=False).failed == 0


if __name__ == "__main__":
base = Path(__file__).parent.parent
test_readme(base)
test_modules(base)
test_rust_sources(base)
print("Done.")
2 changes: 1 addition & 1 deletion tests/test_spinnaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ def test_blackfly_camera_is_present(runtime: acquire.Runtime):

def test_oryx_camera_is_present(runtime: acquire.Runtime):
dm = runtime.device_manager()
assert dm.select(DeviceKind.Camera, ".*ORX-10GS-51S5M.*")
assert dm.select(DeviceKind.Camera, ".*ORX-10GS-51S5M.*")