def test_to_dict(self): node = schema.Time() node_dict = node.to_dict() assert 'node_type' in node_dict assert node_dict['node_type'] == 'Time' assert 'config' in node_dict assert node_dict['config'] == {'set_on_create': False}
def test_default_value_set_on_create(self, backend): data_node = backend.module.Time(schema.Time(set_on_create=True), parent=None, new_params=backend.new_params) assert data_node._storage is not None dt = datetime.datetime.now().time() assert ((data_node.value.hour, data_node.value.minute) == (dt.hour, dt.minute))
class TestTime(ItemNodeTestBase): class_name = 'Time' schema_node = schema.Time() valid_data = datetime.time(13, 37, 42, 23) def test_default_value(self, data_node): assert data_node._storage is None def test_default_value_set_on_create(self, backend): data_node = backend.module.Time(schema.Time(set_on_create=True), parent=None, new_params=backend.new_params) assert data_node._storage is not None dt = datetime.datetime.now().time() assert ((data_node.value.hour, data_node.value.minute) == (dt.hour, dt.minute))
import numpy as np import pytest from dsch import data, schema from dsch.backends import npz @pytest.mark.parametrize('schema_node,valid_data', ( (schema.Array(dtype='int32'), np.array([23, 42], dtype='int32')), (schema.Bool(), True), (schema.Date(), datetime.date.today()), (schema.DateTime(), datetime.datetime.now()), (schema.Scalar(dtype='int32'), np.int32(42)), (schema.String(), 'spam'), (schema.Time(), datetime.datetime.now().time()), )) def test_save_item_node(schema_node, valid_data): data_node = data.data_node_from_schema(schema_node, module_name='dsch.backends.npz', parent=None) data_node.value = valid_data assert np.all(data_node.save() == data_node._storage) class TestCompilation: def test_init_from_storage(self): schema_node = schema.Compilation({'spam': schema.Bool(), 'eggs': schema.Bool()}) data_storage = {'spam': np.array([True]), 'eggs': np.array([False])}
class TestBool(ItemNodeTestBase): class_name = 'Bool' schema_node = schema.Bool() valid_data = True @pytest.mark.parametrize('schema_subnode,valid_subnode_data', ( (schema.Array(dtype='int32'), np.array([23, 42], dtype='int32')), (schema.Bytes(), b'spam'), (schema.Bool(), True), (schema.Date(), datetime.date.today()), (schema.DateTime(), datetime.datetime.now()), (schema.Scalar(dtype='int32'), np.int32(42)), (schema.String(), 'spam'), (schema.Time(), datetime.time(13, 37, 42, 23)), )) class TestCompilation: @pytest.fixture() def data_node(self, backend, schema_subnode): schema_node = schema.Compilation({ 'spam': schema_subnode, 'eggs': schema_subnode }) data_node = backend.module.Compilation(schema_node, parent=None, new_params=backend.new_params) return data_node def test_clear(self, data_node, valid_subnode_data): data_node.spam.value = valid_subnode_data
def test_validate_fail(self, test_data): node = schema.Time() with pytest.raises(ValidationError): node.validate(test_data)
def test_validate(self): node = schema.Time() node.validate(datetime.time(13, 37, 42))
def test_init_defaults(self): node = schema.Time() assert not node.set_on_create
def test_init(self): node = schema.Time(set_on_create=True) assert node.set_on_create
import datetime import json import numpy as np import pytest from dsch import schema from dsch.exceptions import ValidationError @pytest.mark.parametrize( 'node', (schema.Array(dtype='int32'), schema.Bool(), schema.Bytes(), schema.Compilation({'spam': schema.Bool()}), schema.Date(), schema.DateTime(), schema.List(schema.Bool()), schema.Scalar(dtype='int32'), schema.String(), schema.Time())) class TestGenericSchemaNode: def test_to_json(self, node): json_str = node.to_json() node_dict = json.loads(json_str) assert isinstance(node_dict, dict) def test_hash(self, node): hash = node.hash() assert len(hash) == 64 @pytest.mark.parametrize('node1, node2', ( (schema.Array(dtype='float'), schema.Array(dtype='float')), (schema.Bool(), schema.Bool()), (schema.Bytes(), schema.Bytes()), (schema.Compilation({'spam': schema.Bool()