-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from mlexchange/unit_tests
Add unit test and refactor TiledDataset
- Loading branch information
Showing
12 changed files
with
115 additions
and
32 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 |
---|---|---|
|
@@ -29,3 +29,6 @@ jobs: | |
- name: Test formatting with black | ||
run: | | ||
black . --check | ||
- name: pytest | ||
run: | | ||
pytest |
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 |
---|---|---|
@@ -1,2 +1,7 @@ | ||
[tool.isort] | ||
profile = "black" | ||
|
||
[tool.pytest.ini_options] | ||
pythonpath = [ | ||
"src" | ||
] |
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 |
---|---|---|
|
@@ -2,3 +2,5 @@ black==24.3.0 | |
flake8==7.0.0 | ||
isort==5.13.2 | ||
pre-commit==3.6.2 | ||
tiled[all]==0.1.0a114 | ||
pytest |
Empty file.
Empty file.
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import numpy as np | ||
import pytest | ||
from tiled.catalog import from_uri | ||
from tiled.client import Context, from_context | ||
from tiled.server.app import build_app | ||
|
||
|
||
@pytest.fixture | ||
def catalog(tmpdir): | ||
adapter = from_uri( | ||
f"sqlite+aiosqlite:///{tmpdir}/catalog.db", | ||
writable_storage=str(tmpdir), | ||
init_if_not_exists=True, | ||
) | ||
yield adapter | ||
|
||
|
||
@pytest.fixture | ||
def app(catalog): | ||
app = build_app(catalog) | ||
yield app | ||
|
||
|
||
@pytest.fixture | ||
def context(app): | ||
with Context.from_app(app) as context: | ||
yield context | ||
|
||
|
||
@pytest.fixture | ||
def client(context): | ||
"Fixture for tests which only read data" | ||
client = from_context(context) | ||
recons_container = client.create_container("reconstructions") | ||
recons_container.write_array(np.zeros((2, 3, 3), dtype=np.int8), key="recon1") | ||
masks_container = client.create_container("uid0001", metadata={"mask_idx": ["0"]}) | ||
masks_container.write_array(np.zeros((1, 3, 3), dtype=np.int8), key="mask") | ||
yield client |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from ..tiled_dataset import TiledDataset | ||
|
||
|
||
def test_tiled_dataset(client): | ||
tiled_dataset = TiledDataset( | ||
client["reconstructions"]["recon1"], | ||
) | ||
assert tiled_dataset | ||
assert tiled_dataset[0].shape == (3, 3) | ||
|
||
|
||
def test_tiled_dataset_with_masks(client): | ||
tiled_dataset = TiledDataset( | ||
client["reconstructions"]["recon1"], mask_tiled_client=client["uid0001"] | ||
) | ||
assert tiled_dataset[0].shape == (3, 3) |
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
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