-
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.
- Loading branch information
Showing
2 changed files
with
42 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from typing import Dict, Optional, Union | ||
|
||
from omnipy.data.dataset import Dataset | ||
from omnipy.data.model import Model | ||
from omnipy.modules.json.datasets import JsonDataset, JsonDictOfAnyDataset | ||
from omnipy.modules.json.models import (JsonDictModel, | ||
JsonDictOfAnyModel, | ||
JsonListModel, | ||
JsonModel, | ||
JsonSubModel) | ||
from omnipy.modules.json.types import JsonScalar | ||
|
||
|
||
def test_json_dataset(): | ||
test_data = {'a': {'123': 2312}, 'b': {'sd': 'df'}} | ||
assert JsonDataset(test_data)['a'] == JsonDictModel['JsonSubModel']({'123': 2312}) | ||
assert Dataset[Model[JsonSubModel]](test_data)['a'] == JsonDictModel['JsonSubModel']({ | ||
'123': 2312 | ||
}) | ||
assert Dataset[Model[JsonDictModel['JsonSubModel']]]( | ||
test_data)['a'] == JsonDictModel['JsonSubModel']({ | ||
'123': 2312 | ||
}) | ||
# assert Dataset[Model[Dict[str, str]]](test_data)['a'] == JsonDictModel['JsonSubModel']({ | ||
# '123': 2312 | ||
# }) | ||
assert Dataset[JsonDictModel['JsonSubModel']](test_data)['a'] == JsonDictModel['JsonSubModel']({ | ||
'123': 2312 | ||
}) | ||
assert JsonDictOfAnyDataset(test_data)['a'] == JsonDictModel['JsonSubModel']({'123': 2312}) | ||
assert Dataset[Model[Dict[str, int]]](test_data)['a'] == JsonDictModel['JsonSubModel']({ | ||
'123': 2312 | ||
}) |
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,9 @@ | ||
from omnipy.modules.json.datasets import JsonDictOfAnyDataset | ||
from omnipy.modules.json.tasks import transpose_dataset_of_dicts_to_lists | ||
|
||
|
||
def test_transpose_dataset_of_dicts_to_lists(): | ||
transpose = transpose_dataset_of_dicts_to_lists | ||
assert transpose.run(JsonDictOfAnyDataset(dict(abc={'a': 123}, bcd={'a': 456}))).to_data() == { | ||
'a': [123, 234] | ||
} |