# Path: pymatgen/db/builders/schema.py
# DEFAULT_VERSION = "1.0.0"
# ANY_VERSION = "*.*.*"
# OPTIONAL_FLAG = "?"
# SPECIAL = "__"
# SPECIAL_LEN = len(SPECIAL)
# VALUE_RE = re.compile(r"(?:{spec})?([a-zA-Z]+)(?:{spec})?\s*(.*)".format(spec=SPECIAL))
#     FIELD_SEP = ","
#     KV_SEP = ":"
#     IS_LIST, IS_DICT, IS_SCALAR = 0, 1, 2
#     TYPES = {
#         "string": lambda x: isinstance(x, str),
#         "bool": lambda x: x is True or x is False,
#         "datetime": _is_datetime,
#         "date": _is_datetime,
#         "float": lambda x: isinstance(x, float),
#         "int": lambda x: isinstance(x, int),
#         "null": lambda x: x is None,
#         "array": lambda x: isinstance(x, list),
#         "object": lambda x: isinstance(x, dict),
#     }
#     JSTYPES = {
#         "datetime": "string",
#         "date": "string",
#         "string": "string",
#         "bool": "boolean",
#         "int": "integer",
#         "float": "number",
#         "null": "null",
#     }
# class SchemaError(Exception):
# class SchemaTypeError(SchemaError):
# class SchemaPathError(SchemaError):
# class SchemaParseError(SchemaError):
# class HasMeta:
# class Schema(HasMeta):
# class Scalar(HasMeta):
#     def __init__(self, typename):
# def add_schemas(path, ext="json"):
# def get_schema(name):
# def load_schema(file_or_fp):
#     def __init__(self, meta):
#     def add_meta(self, key, value):
#     def __init__(self, schema, optional=False, meta=""):
#     def validate(self, doc, path="(root)"):
#     def json_schema(self, **add_keys):
#     def _build_schema(self, s):
#     def _jstype(self, stype, sval):
#     def _vresult(self, path, fmt, *args):
#     def _parse(self, value):
#     def _whatis(self, obj):
#     def _typestr(self, t):
#     def __str__(self):
#     def __repr__(self):
# def _is_datetime(d):
#     def __init__(self, typecode, optional=False, meta=""):
#     def jstype(self):
#     def __str__(self):
#     def __repr__(self):


import unittest
from pymatgen.db.builders import schema
__author__ = "Dan Gunter <dkgunter@lbl.gov>"
__date__ = "11/1/13"


# most basic schema
basic = {
    "a": "__int__",
    "b": "__float__",
    "arr": ["__float__"],
    "oarr": [{"x": "__int__"}],
}

# basic schema with some optional parts
optionals = {
    "a": "__int__",
    "?b": "__float__",
    "arr": ["__float__"],
    "?oarr": [{"x": "__int__"}],
}


class MyTestCase(unittest.TestCase):
    def test_basic_validate(self):
        inputs = [
            ({"a": 1, "b": 2.3, "arr": [1.0], "oarr": []}, True),
            ({"a": 1, "b": 2.3, "arr": [1.0], "oarr": [{"x": 1}]}, True),
            ({"a": 1, "b": 2.3, "arr": [1.0], "oarr": [{"z": 1}]}, False),
            ({"a": 1, "b": 2.3, "arr": [1.0], "oarr": [{"x": [1, 2]}]}, False),
            ({"a": 1, "b": 2.3, "arr": [1.0], "oarr": [{"x": Exception}]}, False),
        ]

# Path: pymatgen/db/builders/schema.py
# DEFAULT_VERSION = "1.0.0"
# ANY_VERSION = "*.*.*"
# OPTIONAL_FLAG = "?"
# SPECIAL = "__"
# SPECIAL_LEN = len(SPECIAL)
# VALUE_RE = re.compile(r"(?:{spec})?([a-zA-Z]+)(?:{spec})?\s*(.*)".format(spec=SPECIAL))
#     FIELD_SEP = ","
#     KV_SEP = ":"
#     IS_LIST, IS_DICT, IS_SCALAR = 0, 1, 2
#     TYPES = {
#         "string": lambda x: isinstance(x, str),
#         "bool": lambda x: x is True or x is False,
#         "datetime": _is_datetime,
#         "date": _is_datetime,
#         "float": lambda x: isinstance(x, float),
#         "int": lambda x: isinstance(x, int),
#         "null": lambda x: x is None,
#         "array": lambda x: isinstance(x, list),
#         "object": lambda x: isinstance(x, dict),
#     }
#     JSTYPES = {
#         "datetime": "string",
#         "date": "string",
#         "string": "string",
#         "bool": "boolean",
#         "int": "integer",
#         "float": "number",
#         "null": "null",
#     }
# class SchemaError(Exception):
# class SchemaTypeError(SchemaError):
# class SchemaPathError(SchemaError):
# class SchemaParseError(SchemaError):
# class HasMeta:
# class Schema(HasMeta):
# class Scalar(HasMeta):
#     def __init__(self, typename):
# def add_schemas(path, ext="json"):
# def get_schema(name):
# def load_schema(file_or_fp):
#     def __init__(self, meta):
#     def add_meta(self, key, value):
#     def __init__(self, schema, optional=False, meta=""):
#     def validate(self, doc, path="(root)"):
#     def json_schema(self, **add_keys):
#     def _build_schema(self, s):
#     def _jstype(self, stype, sval):
#     def _vresult(self, path, fmt, *args):
#     def _parse(self, value):
#     def _whatis(self, obj):
#     def _typestr(self, t):
#     def __str__(self):
#     def __repr__(self):
# def _is_datetime(d):
#     def __init__(self, typecode, optional=False, meta=""):
#     def jstype(self):
#     def __str__(self):
#     def __repr__(self):


# Path: pymatgen/db/builders/tests/test_schema.py
import unittest
from pymatgen.db.builders import schema

__author__ = "Dan Gunter <dkgunter@lbl.gov>"
__date__ = "11/1/13"


# most basic schema
basic = {
    "a": "__int__",
    "b": "__float__",
    "arr": ["__float__"],
    "oarr": [{"x": "__int__"}],
}

# basic schema with some optional parts
optionals = {
    "a": "__int__",
    "?b": "__float__",
    "arr": ["__float__"],
    "?oarr": [{"x": "__int__"}],
}


class MyTestCase(unittest.TestCase):
    def test_basic_validate(self):
        inputs = [
            ({"a": 1, "b": 2.3, "arr": [1.0], "oarr": []}, True),
            ({"a": 1, "b": 2.3, "arr": [1.0], "oarr": [{"x": 1}]}, True),
            ({"a": 1, "b": 2.3, "arr": [1.0], "oarr": [{"z": 1}]}, False),
            ({"a": 1, "b": 2.3, "arr": [1.0], "oarr": [{"x": [1, 2]}]}, False),
            ({"a": 1, "b": 2.3, "arr": [1.0], "oarr": [{"x": Exception}]}, False),
        ]

        sch = schema.Schema(basic)