Exemplo n.º 1
0
 def test_default_value_set_on_create(self, backend):
     data_node = backend.module.DateTime(
         schema.DateTime(set_on_create=True),
         parent=None,
         new_params=backend.new_params)
     assert data_node._storage is not None
     assert (data_node.value - datetime.datetime.now()).total_seconds() < 1
Exemplo n.º 2
0
 def test_to_dict(self):
     node = schema.DateTime()
     node_dict = node.to_dict()
     assert 'node_type' in node_dict
     assert node_dict['node_type'] == 'DateTime'
     assert 'config' in node_dict
     assert node_dict['config'] == {'set_on_create': False}
Exemplo n.º 3
0
class TestDateTime(ItemNodeTestBase):
    class_name = 'DateTime'
    schema_node = schema.DateTime()
    valid_data = datetime.datetime.now()

    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.DateTime(
            schema.DateTime(set_on_create=True),
            parent=None,
            new_params=backend.new_params)
        assert data_node._storage is not None
        assert (data_node.value - datetime.datetime.now()).total_seconds() < 1
Exemplo n.º 4
0
import datetime
import json

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()})
Exemplo n.º 5
0
 def test_validate_fail(self, test_data):
     node = schema.DateTime()
     with pytest.raises(ValidationError):
         node.validate(test_data)
Exemplo n.º 6
0
 def test_validate(self):
     node = schema.DateTime()
     node.validate(datetime.datetime.now())
Exemplo n.º 7
0
 def test_init_defaults(self):
     node = schema.DateTime()
     assert not node.set_on_create
Exemplo n.º 8
0
 def test_init(self):
     node = schema.DateTime(set_on_create=True)
     assert node.set_on_create
Exemplo n.º 9
0
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()