# Path: sacred/serializer.py
# def flatten(obj):
#     return _json.loads(json.encode(obj, keys=True))
# 
# def restore(flat):
#     return json.decode(_json.dumps(flat), keys=True)


import pytest
import sacred.optional as opt
from sacred.serializer import flatten, restore
        12,
        3.14,
        "mystring",
        "αβγδ",
        [1, 2.0, "3", [4]],
        {"foo": "bar", "answer": 42},
        None,
        True,
    ],
)
def test_restore_on_json_is_noop(obj):
    assert flatten(obj) == obj


def test_serialize_non_str_keys():
    d = {1: "one", 2: "two"}
    assert restore(flatten(d)) == d


@pytest.mark.skipif(not opt.has_numpy, reason="requires numpy")
def test_serialize_numpy_arrays():
    a = opt.np.array([[1, 2, 3], [4, 5, 6]], dtype=opt.np.float32)
    b = restore(flatten(a))
    assert opt.np.all(b == a)
    assert b.dtype == a.dtype
    assert b.shape == a.shape


def test_serialize_tuples():
    t = (1, "two")

# Path: sacred/serializer.py
# def flatten(obj):
#     return _json.loads(json.encode(obj, keys=True))
# 
# def restore(flat):
#     return json.decode(_json.dumps(flat), keys=True)


# Path: tests/test_serializer.py
import pytest
import sacred.optional as opt
from sacred.serializer import flatten, restore

        12,
        3.14,
        "mystring",
        "αβγδ",
        [1, 2.0, "3", [4]],
        {"foo": "bar", "answer": 42},
        None,
        True,
    ],
)
def test_restore_on_json_is_noop(obj):
    assert flatten(obj) == obj


def test_serialize_non_str_keys():
    d = {1: "one", 2: "two"}
    assert restore(flatten(d)) == d


@pytest.mark.skipif(not opt.has_numpy, reason="requires numpy")
def test_serialize_numpy_arrays():
    a = opt.np.array([[1, 2, 3], [4, 5, 6]], dtype=opt.np.float32)
    b = restore(flatten(a))
    assert opt.np.all(b == a)
    assert b.dtype == a.dtype
    assert b.shape == a.shape


def test_serialize_tuples():
    t = (1, "two")

    assert restore(flatten(t)) == t