# Path: hydra_base/exceptions.py
# class HydraError(Exception):
#     __error_code__ = None
# 
#     def __init__(self, message="A hydra error has occurred"):
#         # Call the base class constructor with the parameters it needs
#         self.code = error_codes.get(self.__error_code__, '0000')
#         self.message = message # Added for Py3
#         super(HydraError, self).__init__({"message": message, "code": self.code})
# 
# Path: hydra_base/lib/HydraTypes/Registry.py
# class HydraObjectFactory(object):
#     """
#       Abstract class serving as a factory for the creation of Hydra Types
#     """
#     @staticmethod
#     def fromJSON(encstr, tmap=None):
#         if tmap is None:
#             tmap = typemap
#         pass
# 
#     @classmethod
#     def valueFromDataset(cls, datatype, value, metadata=None, tmap=None):
#         """
#           Return the value contained by dataset argument, after casting to
#           correct type and performing type-specific validation
#         """
#         if tmap is None:
#             tmap = typemap
#         obj = cls.fromDataset(datatype, value, metadata=metadata, tmap=tmap)
#         return obj.value
# 
#     @staticmethod
#     def fromDataset(datatype, value, metadata=None, tmap=None):
#         """
#           Return a representation of dataset argument as an instance
# 
#           of the class corresponding to its datatype
#         """
#         if tmap is None:
#             tmap = typemap
#         return tmap[datatype.upper()].fromDataset(value, metadata=metadata)
# 
# Path: hydra_base/lib/HydraTypes/Types.py
# class Scalar(DataType):
#     tag      = "SCALAR"
#     name     = "Scalar"
#     skeleton = "[%f]"
#     json     = ScalarJSON()
# 
#     def __init__(self, value):
#         super(Scalar, self).__init__()
#         self.value = value
#         self.validate()
# 
#     @classmethod
#     def fromDataset(cls, value, metadata=None):
#         return cls(value)
# 
#     def validate(self):
#         f = float(self.value)
#         assert not math.isnan(f) # Excludes NaN etc
# 
#     def get_value(self):
#         return str(self._value)
# 
#     def set_value(self, val):
#         self._value = val
# 
#     value = property(get_value, set_value)
# 
# class Array(DataType):
#     tag      = "ARRAY"
#     name     = "Array"
#     skeleton = "[%f, ...]"
#     json     = ArrayJSON()
# 
#     def __init__(self, encstr):
#         super(Array, self).__init__()
#         self.value = encstr
#         self.validate()
# 
#     @classmethod
#     def fromDataset(cls, value, metadata=None):
#         return cls(value)
# 
#     def validate(self):
#         j = json.loads(self.value)
#         assert len(j) > 0           # Sized
#         assert iter(j) is not None  # Iterable
#         assert j.__getitem__        # Container
#         assert not isinstance(j, six.string_types) # Exclude strs
# 
#     def get_value(self):
#         return self._value
# 
#     def set_value(self, val):
#         self._value = val
# 
#     value = property(get_value, set_value)


import pytest
import json
import datetime
import collections
import hydra_base as hb
import pandas as pd
import logging
from hydra_base.exceptions import HydraError
from hydra_base.lib.HydraTypes.Registry import HydraObjectFactory
from hydra_base.lib.HydraTypes.Types import Scalar, Array
    assert make_scalar.obj.validate() is None



""" Array type tests """

@pytest.mark.parametrize("value", array_valid_values)
def test_create_array(value):
    array_dataset = hb.lib.objects.Dataset({'type':'array', 'value': json.dumps(value)})
    value = array_dataset.parse_value()


@pytest.mark.parametrize("value", array_invalid_values)
def test_fail_create_array(value):
    with pytest.raises( (HydraError, TypeError) ):
        print(value)
        array_dataset = hb.lib.objects.Dataset({'type':'array', 'value': json.dumps(value)})
        value = array_dataset.parse_value()


@pytest.fixture(params=array_valid_values)
def make_array(request):
    array_dataset = hb.lib.objects.Dataset({'type':'array', 'value': json.dumps(request.param) })
    o = HydraObjectFactory.fromDataset(array_dataset.type, array_dataset.value)
    Fixret = collections.namedtuple("fixret", ("obj", "fixarg"))
    yield Fixret(o, request.param)     # Expose current fixture arg to test


def test_raw_array(make_array):
    assert type(make_array.obj) == Array

# Path: hydra_base/exceptions.py
# class HydraError(Exception):
#     __error_code__ = None
# 
#     def __init__(self, message="A hydra error has occurred"):
#         # Call the base class constructor with the parameters it needs
#         self.code = error_codes.get(self.__error_code__, '0000')
#         self.message = message # Added for Py3
#         super(HydraError, self).__init__({"message": message, "code": self.code})
# 
# Path: hydra_base/lib/HydraTypes/Registry.py
# class HydraObjectFactory(object):
#     """
#       Abstract class serving as a factory for the creation of Hydra Types
#     """
#     @staticmethod
#     def fromJSON(encstr, tmap=None):
#         if tmap is None:
#             tmap = typemap
#         pass
# 
#     @classmethod
#     def valueFromDataset(cls, datatype, value, metadata=None, tmap=None):
#         """
#           Return the value contained by dataset argument, after casting to
#           correct type and performing type-specific validation
#         """
#         if tmap is None:
#             tmap = typemap
#         obj = cls.fromDataset(datatype, value, metadata=metadata, tmap=tmap)
#         return obj.value
# 
#     @staticmethod
#     def fromDataset(datatype, value, metadata=None, tmap=None):
#         """
#           Return a representation of dataset argument as an instance
# 
#           of the class corresponding to its datatype
#         """
#         if tmap is None:
#             tmap = typemap
#         return tmap[datatype.upper()].fromDataset(value, metadata=metadata)
# 
# Path: hydra_base/lib/HydraTypes/Types.py
# class Scalar(DataType):
#     tag      = "SCALAR"
#     name     = "Scalar"
#     skeleton = "[%f]"
#     json     = ScalarJSON()
# 
#     def __init__(self, value):
#         super(Scalar, self).__init__()
#         self.value = value
#         self.validate()
# 
#     @classmethod
#     def fromDataset(cls, value, metadata=None):
#         return cls(value)
# 
#     def validate(self):
#         f = float(self.value)
#         assert not math.isnan(f) # Excludes NaN etc
# 
#     def get_value(self):
#         return str(self._value)
# 
#     def set_value(self, val):
#         self._value = val
# 
#     value = property(get_value, set_value)
# 
# class Array(DataType):
#     tag      = "ARRAY"
#     name     = "Array"
#     skeleton = "[%f, ...]"
#     json     = ArrayJSON()
# 
#     def __init__(self, encstr):
#         super(Array, self).__init__()
#         self.value = encstr
#         self.validate()
# 
#     @classmethod
#     def fromDataset(cls, value, metadata=None):
#         return cls(value)
# 
#     def validate(self):
#         j = json.loads(self.value)
#         assert len(j) > 0           # Sized
#         assert iter(j) is not None  # Iterable
#         assert j.__getitem__        # Container
#         assert not isinstance(j, six.string_types) # Exclude strs
# 
#     def get_value(self):
#         return self._value
# 
#     def set_value(self, val):
#         self._value = val
# 
#     value = property(get_value, set_value)


# Path: tests/test_datatypes.py
import pytest
import json
import datetime
import collections
import hydra_base as hb
import pandas as pd
import logging
from hydra_base.exceptions import HydraError
from hydra_base.lib.HydraTypes.Registry import HydraObjectFactory
from hydra_base.lib.HydraTypes.Types import Scalar, Array

    assert make_scalar.obj.validate() is None



""" Array type tests """

@pytest.mark.parametrize("value", array_valid_values)
def test_create_array(value):
    array_dataset = hb.lib.objects.Dataset({'type':'array', 'value': json.dumps(value)})
    value = array_dataset.parse_value()


@pytest.mark.parametrize("value", array_invalid_values)
def test_fail_create_array(value):
    with pytest.raises( (HydraError, TypeError) ):
        print(value)
        array_dataset = hb.lib.objects.Dataset({'type':'array', 'value': json.dumps(value)})
        value = array_dataset.parse_value()


@pytest.fixture(params=array_valid_values)
def make_array(request):
    array_dataset = hb.lib.objects.Dataset({'type':'array', 'value': json.dumps(request.param) })
    o = HydraObjectFactory.fromDataset(array_dataset.type, array_dataset.value)
    Fixret = collections.namedtuple("fixret", ("obj", "fixarg"))
    yield Fixret(o, request.param)     # Expose current fixture arg to test


def test_raw_array(make_array):
    assert type(make_array.obj) == Array

    assert make_array.obj.tag == Array.tag