-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
732 additions
and
828 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
Binary file not shown.
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,97 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Iterator | ||
|
||
import numpy as np | ||
import pytest | ||
|
||
from holonote.annotate import Annotator, SQLiteDB, UUIDHexStringKey | ||
|
||
|
||
@pytest.fixture() | ||
def conn_sqlite_uuid(tmp_path) -> Iterator[SQLiteDB]: | ||
conn = SQLiteDB(filename=str(tmp_path / "test.db"), primary_key=UUIDHexStringKey()) | ||
yield conn | ||
try: | ||
conn.cursor.close() | ||
except Exception: | ||
pass | ||
try: | ||
conn.con.close() | ||
except Exception: | ||
pass | ||
|
||
|
||
@pytest.fixture() | ||
def annotator_range1d(conn_sqlite_uuid) -> Annotator: | ||
anno = Annotator( | ||
{"TIME": np.datetime64}, | ||
fields=["description"], | ||
region_types=["Range"], | ||
connector=conn_sqlite_uuid, | ||
) | ||
return anno | ||
|
||
|
||
@pytest.fixture() | ||
def annotator_point1d(conn_sqlite_uuid) -> Annotator: | ||
anno = Annotator( | ||
{"TIME": np.datetime64}, | ||
fields=["description"], | ||
region_types=["Point"], | ||
connector=conn_sqlite_uuid, | ||
) | ||
return anno | ||
|
||
|
||
@pytest.fixture() | ||
def annotator_range2d(conn_sqlite_uuid) -> Annotator: | ||
anno = Annotator( | ||
{"x": float, "y": float}, | ||
fields=["description"], | ||
region_types=["Range"], | ||
connector=conn_sqlite_uuid, | ||
) | ||
return anno | ||
|
||
|
||
@pytest.fixture() | ||
def annotator_point2d(conn_sqlite_uuid) -> Annotator: | ||
anno = Annotator( | ||
{"x": float, "y": float}, | ||
fields=["description"], | ||
region_types=["Point"], | ||
connector=conn_sqlite_uuid, | ||
) | ||
return anno | ||
|
||
|
||
@pytest.fixture() | ||
def multiple_region_annotator(annotator_range1d) -> Annotator: | ||
annotator_range1d.region_types = ["Point", "Range"] | ||
return annotator_range1d | ||
|
||
|
||
@pytest.fixture() | ||
def multiple_annotators( | ||
conn_sqlite_uuid, annotator_range1d, annotator_range2d | ||
) -> dict[str, Annotator | SQLiteDB]: | ||
annotator_range1d.connector = conn_sqlite_uuid | ||
annotator_range2d.connector = conn_sqlite_uuid | ||
output = { | ||
"annotation1d": annotator_range1d, | ||
"annotation2d": annotator_range2d, | ||
"conn": conn_sqlite_uuid, | ||
} | ||
return output | ||
|
||
|
||
@pytest.fixture() | ||
def multiple_fields_annotator(conn_sqlite_uuid) -> Annotator: | ||
conn_sqlite_uuid.fields = ["field1", "field2"] | ||
anno = Annotator( | ||
{"TIME": np.datetime64}, | ||
fields=["field1", "field2"], | ||
connector=conn_sqlite_uuid, | ||
) | ||
return anno |
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,36 +1,24 @@ | ||
import unittest | ||
import numpy as np | ||
import pandas as pd | ||
|
||
from holonote.annotate import AnnotationTable | ||
|
||
|
||
def test_table_region_df(): | ||
table = AnnotationTable() | ||
table.load(primary_key_name='id', fields=['test_description']) | ||
assert len(table._region_df) == 0, 'Should be initialized empty' | ||
assert tuple(table._region_df.columns) == AnnotationTable.columns | ||
|
||
class TestBasicTableLoad(unittest.TestCase): | ||
start = pd.Timestamp('2022-06-17 18:32:48.623476') | ||
end = pd.Timestamp('2022-06-19 04:44:09.306402') | ||
regions = [ {'region_type': 'Range', | ||
'value': (start, end), | ||
'dim1': 'TIME', | ||
'dim2': None} ] | ||
table.add_annotation(regions, id=100, test_description='A test') | ||
|
||
def setUp(self): | ||
self.table = AnnotationTable() | ||
|
||
# Load some metadata and region data | ||
expected = pd.DataFrame([{'region_type':'Range', 'dim1':'TIME', 'dim2': None, | ||
'value':(start, end), '_id':100}]).astype({'_id':object}) | ||
|
||
def test_table_region_df(self): | ||
self.table.load(primary_key_name='id', fields=['test_description']) | ||
assert len(self.table._region_df) == 0, 'Should be initialized empty' | ||
assert tuple(self.table._region_df.columns) == AnnotationTable.columns | ||
|
||
start = pd.Timestamp('2022-06-17 18:32:48.623476') | ||
end = pd.Timestamp('2022-06-19 04:44:09.306402') | ||
regions = [ {'region_type': 'Range', | ||
'value': (start, end), | ||
'dim1': 'TIME', | ||
'dim2': None} ] | ||
self.table.add_annotation(regions, id=100, test_description='A test') | ||
|
||
|
||
expected = pd.DataFrame([{'region_type':'Range', 'dim1':'TIME', 'dim2': None, | ||
'value':(start, end), '_id':100}]).astype({'_id':object}) | ||
|
||
pd.testing.assert_frame_equal(self.table._region_df, expected) | ||
|
||
|
||
# Test other metadata field | ||
pd.testing.assert_frame_equal(table._region_df, expected) |
Oops, something went wrong.