Skip to content

Commit

Permalink
Tmp json model + transpose tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sveinugu committed Nov 9, 2023
1 parent 4d477bb commit 8216bcf
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/modules/json/test_json_models.py
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
})
9 changes: 9 additions & 0 deletions tests/modules/json/test_json_tasks.py
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]
}

0 comments on commit 8216bcf

Please sign in to comment.