-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added tests for summarize status method
- Loading branch information
Showing
2 changed files
with
305 additions
and
5 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
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,300 @@ | ||
import pytest | ||
import numpy as np | ||
|
||
|
||
@pytest.fixture() | ||
def dummy_repo(repo): | ||
dummyData = np.arange(50) | ||
co1 = repo.checkout(write=True, branch='master') | ||
co1.arraysets.init_arrayset( | ||
name='dummy', prototype=dummyData, named_samples=True) | ||
for idx in range(10): | ||
dummyData[:] = idx | ||
co1.arraysets['dummy'][idx] = dummyData | ||
co1.metadata['hello'] = 'world' | ||
co1.metadata['somemetadatakey'] = 'somemetadatavalue' | ||
co1.commit('first commit adding dummy data and hello meta') | ||
co1.close() | ||
return repo | ||
|
||
|
||
def test_add_metadata_and_samples_to_existing_aset(dummy_repo): | ||
from hangar.records.summarize import status | ||
expected = '============ \n'\ | ||
'| ADDED \n'\ | ||
'|---------- \n'\ | ||
'| Schema: 0 \n'\ | ||
'|---------- \n'\ | ||
'| Samples: 20 \n'\ | ||
'| - "dummy": 20 \n'\ | ||
'|---------- \n'\ | ||
'| Metadata: 1 \n'\ | ||
' \n'\ | ||
'============ \n'\ | ||
'| DELETED \n'\ | ||
'|---------- \n'\ | ||
'| Schema: 0 \n'\ | ||
'|---------- \n'\ | ||
'| Samples: 0 \n'\ | ||
'|---------- \n'\ | ||
'| Metadata: 0 \n'\ | ||
' \n'\ | ||
'============ \n'\ | ||
'| MUTATED \n'\ | ||
'|---------- \n'\ | ||
'| Schema: 0 \n'\ | ||
'|---------- \n'\ | ||
'| Samples: 0 \n'\ | ||
'|---------- \n'\ | ||
'| Metadata: 0 \n'\ | ||
' \n' | ||
dummyData = np.arange(50) | ||
co2 = dummy_repo.checkout(write=True) | ||
for idx in range(10, 20): | ||
dummyData[:] = idx | ||
co2.arraysets['dummy'][str(idx)] = dummyData | ||
co2.arraysets['dummy'][idx] = dummyData | ||
co2.metadata['foo'] = 'bar' | ||
df = co2.diff.staged() | ||
co2.close() | ||
assert status(df.diff).getvalue() == expected | ||
|
||
|
||
def test_mutate_metadata_and_sample_values(dummy_repo): | ||
from hangar.records.summarize import status | ||
expected = '============ \n'\ | ||
'| ADDED \n'\ | ||
'|---------- \n'\ | ||
'| Schema: 0 \n'\ | ||
'|---------- \n'\ | ||
'| Samples: 0 \n'\ | ||
'|---------- \n'\ | ||
'| Metadata: 0 \n'\ | ||
' \n'\ | ||
'============ \n'\ | ||
'| DELETED \n'\ | ||
'|---------- \n'\ | ||
'| Schema: 0 \n'\ | ||
'|---------- \n'\ | ||
'| Samples: 0 \n'\ | ||
'|---------- \n'\ | ||
'| Metadata: 0 \n'\ | ||
' \n'\ | ||
'============ \n'\ | ||
'| MUTATED \n'\ | ||
'|---------- \n'\ | ||
'| Schema: 0 \n'\ | ||
'|---------- \n'\ | ||
'| Samples: 5 \n'\ | ||
'| - "dummy": 5 \n'\ | ||
'|---------- \n'\ | ||
'| Metadata: 1 \n'\ | ||
' \n' | ||
dummyData = np.arange(50) | ||
co2 = dummy_repo.checkout(write=True) | ||
for idx in range(5, 10): | ||
dummyData[:] = idx + 10 | ||
co2.arraysets['dummy'][idx] = dummyData | ||
co2.metadata['hello'] = 'bar' | ||
df = co2.diff.staged() | ||
co2.close() | ||
assert status(df.diff).getvalue() == expected | ||
|
||
|
||
def test_delete_metadata_and_samples(dummy_repo): | ||
from hangar.records.summarize import status | ||
expected = '============ \n'\ | ||
'| ADDED \n'\ | ||
'|---------- \n'\ | ||
'| Schema: 0 \n'\ | ||
'|---------- \n'\ | ||
'| Samples: 0 \n'\ | ||
'|---------- \n'\ | ||
'| Metadata: 0 \n'\ | ||
' \n'\ | ||
'============ \n'\ | ||
'| DELETED \n'\ | ||
'|---------- \n'\ | ||
'| Schema: 0 \n'\ | ||
'|---------- \n'\ | ||
'| Samples: 5 \n'\ | ||
'| - "dummy": 5 \n'\ | ||
'|---------- \n'\ | ||
'| Metadata: 1 \n'\ | ||
' \n'\ | ||
'============ \n'\ | ||
'| MUTATED \n'\ | ||
'|---------- \n'\ | ||
'| Schema: 0 \n'\ | ||
'|---------- \n'\ | ||
'| Samples: 0 \n'\ | ||
'|---------- \n'\ | ||
'| Metadata: 0 \n'\ | ||
' \n' | ||
co2 = dummy_repo.checkout(write=True) | ||
for idx in range(5, 10): | ||
del co2.arraysets['dummy'][idx] | ||
del co2.metadata['hello'] | ||
df = co2.diff.staged() | ||
co2.close() | ||
assert status(df.diff).getvalue() == expected | ||
|
||
|
||
def test_add_new_aset_schema_and_samples(dummy_repo): | ||
from hangar.records.summarize import status | ||
expected = '============ \n'\ | ||
'| ADDED \n'\ | ||
'|---------- \n'\ | ||
'| Schema: 1 \n'\ | ||
'| - "new_aset": \n'\ | ||
'| named: True \n'\ | ||
'| dtype: float32 \n'\ | ||
'| (max) shape: (10, 10) \n'\ | ||
'| variable shape: False \n'\ | ||
'| backend: 00 \n'\ | ||
"| backend opts: {'shuffle': None, 'complib': 'blosc:zstd', 'complevel': 3} \n"\ | ||
'|---------- \n'\ | ||
'| Samples: 5 \n'\ | ||
'| - "new_aset": 5 \n'\ | ||
'|---------- \n'\ | ||
'| Metadata: 0 \n'\ | ||
' \n'\ | ||
'============ \n'\ | ||
'| DELETED \n'\ | ||
'|---------- \n'\ | ||
'| Schema: 0 \n'\ | ||
'|---------- \n'\ | ||
'| Samples: 0 \n'\ | ||
'|---------- \n'\ | ||
'| Metadata: 0 \n'\ | ||
' \n'\ | ||
'============ \n'\ | ||
'| MUTATED \n'\ | ||
'|---------- \n'\ | ||
'| Schema: 0 \n'\ | ||
'|---------- \n'\ | ||
'| Samples: 0 \n'\ | ||
'|---------- \n'\ | ||
'| Metadata: 0 \n'\ | ||
' \n' | ||
co2 = dummy_repo.checkout(write=True) | ||
co2.arraysets.init_arrayset('new_aset', shape=(10, 10), dtype=np.float32) | ||
for idx in range(5): | ||
dummyData = np.random.randn(10, 10).astype(np.float32) | ||
co2.arraysets['new_aset'][idx] = dummyData | ||
df = co2.diff.staged() | ||
co2.close() | ||
assert status(df.diff).getvalue() == expected | ||
|
||
|
||
def test_add_new_aset_schema_and_sample_and_delete_old_aset(dummy_repo): | ||
from hangar.records.summarize import status | ||
expected = '============ \n'\ | ||
'| ADDED \n'\ | ||
'|---------- \n'\ | ||
'| Schema: 1 \n'\ | ||
'| - "new_aset": \n'\ | ||
'| named: True \n'\ | ||
'| dtype: float32 \n'\ | ||
'| (max) shape: (10, 10) \n'\ | ||
'| variable shape: False \n'\ | ||
'| backend: 00 \n'\ | ||
"| backend opts: {'shuffle': None, 'complib': 'blosc:zstd', 'complevel': 3} \n"\ | ||
'|---------- \n'\ | ||
'| Samples: 5 \n'\ | ||
'| - "new_aset": 5 \n'\ | ||
'|---------- \n'\ | ||
'| Metadata: 0 \n'\ | ||
' \n'\ | ||
'============ \n'\ | ||
'| DELETED \n'\ | ||
'|---------- \n'\ | ||
'| Schema: 1 \n'\ | ||
'| - "dummy": \n'\ | ||
'| named: True \n'\ | ||
'| dtype: int64 \n'\ | ||
'| (max) shape: (50,) \n'\ | ||
'| variable shape: False \n'\ | ||
'| backend: 10 \n'\ | ||
'| backend opts: {} \n'\ | ||
'|---------- \n'\ | ||
'| Samples: 10 \n'\ | ||
'| - "dummy": 10 \n'\ | ||
'|---------- \n'\ | ||
'| Metadata: 0 \n'\ | ||
' \n'\ | ||
'============ \n'\ | ||
'| MUTATED \n'\ | ||
'|---------- \n'\ | ||
'| Schema: 0 \n'\ | ||
'|---------- \n'\ | ||
'| Samples: 0 \n'\ | ||
'|---------- \n'\ | ||
'| Metadata: 0 \n'\ | ||
' \n' | ||
co2 = dummy_repo.checkout(write=True) | ||
new = co2.arraysets.init_arrayset('new_aset', shape=(10, 10), dtype=np.float32) | ||
for idx in range(5): | ||
dummyData = np.random.randn(10, 10).astype(np.float32) | ||
co2.arraysets['new_aset'][idx] = dummyData | ||
del co2.arraysets['dummy'] | ||
df = co2.diff.staged() | ||
co2.close() | ||
assert status(df.diff).getvalue() == expected | ||
|
||
|
||
def test_add_new_schema_and_samples_and_change_old_backend(dummy_repo): | ||
from hangar.records.summarize import status | ||
expected = '============ \n'\ | ||
'| ADDED \n'\ | ||
'|---------- \n'\ | ||
'| Schema: 1 \n'\ | ||
'| - "new_aset": \n'\ | ||
'| named: True \n'\ | ||
'| dtype: float32 \n'\ | ||
'| (max) shape: (10, 10) \n'\ | ||
'| variable shape: False \n'\ | ||
'| backend: 00 \n'\ | ||
"| backend opts: {'shuffle': None, 'complib': 'blosc:zstd', 'complevel': 3} \n"\ | ||
'|---------- \n'\ | ||
'| Samples: 5 \n'\ | ||
'| - "new_aset": 5 \n'\ | ||
'|---------- \n'\ | ||
'| Metadata: 0 \n'\ | ||
' \n'\ | ||
'============ \n'\ | ||
'| DELETED \n'\ | ||
'|---------- \n'\ | ||
'| Schema: 0 \n'\ | ||
'|---------- \n'\ | ||
'| Samples: 0 \n'\ | ||
'|---------- \n'\ | ||
'| Metadata: 0 \n'\ | ||
' \n'\ | ||
'============ \n'\ | ||
'| MUTATED \n'\ | ||
'|---------- \n'\ | ||
'| Schema: 1 \n'\ | ||
'| - "dummy": \n'\ | ||
'| named: True \n'\ | ||
'| dtype: int64 \n'\ | ||
'| (max) shape: (50,) \n'\ | ||
'| variable shape: False \n'\ | ||
'| backend: 00 \n'\ | ||
"| backend opts: {'shuffle': None, 'complib': 'blosc:zstd', 'complevel': 3} \n"\ | ||
'|---------- \n'\ | ||
'| Samples: 5 \n'\ | ||
'| - "dummy": 5 \n'\ | ||
'|---------- \n'\ | ||
'| Metadata: 0 \n'\ | ||
' \n' | ||
co2 = dummy_repo.checkout(write=True) | ||
co2.arraysets['dummy'].change_backend('00') | ||
co2.arraysets.init_arrayset('new_aset', shape=(10, 10), dtype=np.float32) | ||
for idx in range(5): | ||
dummyData = np.random.randn(10, 10).astype(np.float32) | ||
co2.arraysets['new_aset'][idx] = dummyData | ||
co2.arraysets['dummy'][idx] = np.arange(50) + idx | ||
df = co2.diff.staged() | ||
co2.close() | ||
assert status(df.diff).getvalue() == expected |