# Path: minette/serializer.py
# def dumps(obj, **kwargs):
#     """
#     Encode object/dict to JSON
# 
#     Parameters
#     ----------
#     obj : object
#         Object to encode
# 
#     Returns
#     -------
#     s : str
#         JSON string
#     """
#     if obj is None:
#         return ""
#     d = dumpd(obj)
#     return json.dumps(d, default=_encode_datetime, **kwargs)
# 
# def loads(s, obj_cls=None, **kwargs):
#     """
#     Decode JSON to dict/object
# 
#     Parameters
#     ----------
#     s : str
#         JSON string to decode
#     obj_cls : type, default None
#         Class of object to convert. If None, convert to dict
# 
#     Returns
#     -------
#     obj : object
#         Instance of obj_cls
#     """
#     if s is None or s == "":
#         return None
#     d = json.loads(s, object_hook=_decode_datetime, **kwargs)
#     if obj_cls is None:
#         return d
#     else:
#         return loadd(d, obj_cls)


import pytest
import minette.utils as u
from datetime import datetime
from pytz import timezone
from minette.serializer import dumps, loads
    assert u.str_to_date("2019-01-02T03:04:05") == naive_dt
    assert u.str_to_date("2019-01-02T03:04:05+09:00") == aware_dt


def test_date_to_unixtime():
    assert u.date_to_unixtime(aware_dt) == 1546365845


def test_unixtime_to_date():
    assert u.unixtime_to_date(1546365845) == naive_dt


def test_encode_json():
    obj = {
        "key1": "value1",
        "key2": 2,
        "key3": naive_dt,
        "key4": aware_dt
    }
    assert dumps(obj) == '{"key1": "value1", "key2": 2, "key3": "2019-01-02T03:04:05.000000", "key4": "2019-01-02T03:04:05.000000+09:00"}'
    assert dumps(None) == ""
    with pytest.raises(AttributeError):
        dumps(object())


def test_decode_json():
    obj = loads('{"key1": "value1", "key2": 2, "key3": "2019-01-02T03:04:05+09:00"}')
    assert obj["key1"] == "value1"
    assert obj["key2"] == 2
    assert obj["key3"] == aware_dt

# Path: minette/serializer.py
# def dumps(obj, **kwargs):
#     """
#     Encode object/dict to JSON
# 
#     Parameters
#     ----------
#     obj : object
#         Object to encode
# 
#     Returns
#     -------
#     s : str
#         JSON string
#     """
#     if obj is None:
#         return ""
#     d = dumpd(obj)
#     return json.dumps(d, default=_encode_datetime, **kwargs)
# 
# def loads(s, obj_cls=None, **kwargs):
#     """
#     Decode JSON to dict/object
# 
#     Parameters
#     ----------
#     s : str
#         JSON string to decode
#     obj_cls : type, default None
#         Class of object to convert. If None, convert to dict
# 
#     Returns
#     -------
#     obj : object
#         Instance of obj_cls
#     """
#     if s is None or s == "":
#         return None
#     d = json.loads(s, object_hook=_decode_datetime, **kwargs)
#     if obj_cls is None:
#         return d
#     else:
#         return loadd(d, obj_cls)


# Path: tests/test_utils.py
import pytest
import minette.utils as u
from datetime import datetime
from pytz import timezone
from minette.serializer import dumps, loads

    assert u.str_to_date("2019-01-02T03:04:05") == naive_dt
    assert u.str_to_date("2019-01-02T03:04:05+09:00") == aware_dt


def test_date_to_unixtime():
    assert u.date_to_unixtime(aware_dt) == 1546365845


def test_unixtime_to_date():
    assert u.unixtime_to_date(1546365845) == naive_dt


def test_encode_json():
    obj = {
        "key1": "value1",
        "key2": 2,
        "key3": naive_dt,
        "key4": aware_dt
    }
    assert dumps(obj) == '{"key1": "value1", "key2": 2, "key3": "2019-01-02T03:04:05.000000", "key4": "2019-01-02T03:04:05.000000+09:00"}'
    assert dumps(None) == ""
    with pytest.raises(AttributeError):
        dumps(object())


def test_decode_json():
    obj = loads('{"key1": "value1", "key2": 2, "key3": "2019-01-02T03:04:05+09:00"}')
    assert obj["key1"] == "value1"
    assert obj["key2"] == 2
    assert obj["key3"] == aware_dt

    assert loads("") is None