# Path: uchroma/traits.py
# class FrozenDict(WriteOnceMixin, Dict):
#     """
#     Subclass of Dict which converts the value to a frozendict on
#     the first setting.
#     """
#     def validate(self, obj, value):
#         return frozendict(super().validate(obj, value))


from collections import OrderedDict
from frozendict import frozendict
from traitlets import HasTraits
from uchroma.traits import FrozenDict
import pytest





class FrozenDictTest(HasTraits):
    popsicle = FrozenDict()

    def __init__(self, *args, **kwargs):
        super(FrozenDictTest, self).__init__(*args, **kwargs)


obj = FrozenDictTest()


def test_frozendict_init_write_once():
    odict = OrderedDict()
    odict['test'] = 'best value ever'

    obj.popsicle = odict

    assert isinstance(obj.popsicle, frozendict)

    assert obj.popsicle is not None
    assert 'test' in obj.popsicle
    assert obj.popsicle['test'] == 'best value ever'


def test_frozendict_is_not_writable():
    with pytest.raises(KeyError):

# Path: uchroma/traits.py
# class FrozenDict(WriteOnceMixin, Dict):
#     """
#     Subclass of Dict which converts the value to a frozendict on
#     the first setting.
#     """
#     def validate(self, obj, value):
#         return frozendict(super().validate(obj, value))


# Path: tests/test_traits.py
from collections import OrderedDict
from frozendict import frozendict
from traitlets import HasTraits
from uchroma.traits import FrozenDict
import pytest






class FrozenDictTest(HasTraits):
    popsicle = FrozenDict()

    def __init__(self, *args, **kwargs):
        super(FrozenDictTest, self).__init__(*args, **kwargs)


obj = FrozenDictTest()


def test_frozendict_init_write_once():
    odict = OrderedDict()
    odict['test'] = 'best value ever'

    obj.popsicle = odict

    assert isinstance(obj.popsicle, frozendict)

    assert obj.popsicle is not None
    assert 'test' in obj.popsicle
    assert obj.popsicle['test'] == 'best value ever'


def test_frozendict_is_not_writable():
    with pytest.raises(KeyError):

        obj.popsicle['test_write'] == 'should fail'