# Path: snakeguice/decorators.py
# class GuiceData(object):
# 
#     def __init__(self):
#         self.init = None
#         self.methods = {}
# 
#     @classmethod
#     def from_class(cls, target_class):
#         if '__guice__' not in target_class.__dict__:
#             guice_data = cls()
#             try:
#                 target_class.__guice__ = guice_data
#             except TypeError: # special case for builtin/extension types
#                 return guice_data
#         return target_class.__guice__
# 
#     @classmethod
#     def composite_from_class(cls, target_class):
#         composite_data = GuiceData()
#         for _cls in target_class.__mro__[-1::-1]:
#             data = GuiceData.from_class(_cls)
#             if data.init: # only the last class in the chain
#                 composite_data.init = data.init
#             for name, method in data.methods.items():
#                 composite_data.methods[name] = method
# 
#         return composite_data
# 
#     @classmethod
#     def from_class_dict(cls, class_dict):
#         if '__guice__' not in class_dict:
#             class_dict['__guice__'] = cls()
#         return class_dict['__guice__']


from nose.tools import raises
from snakeguice.decorators import GuiceData


def describe_getting_GuiceData_from_a_dict():
    d = dict(__guice__=object())
    data = GuiceData.from_class_dict(d)

    def should_get_the_same_instance():
        assert d['__guice__'] is data


def describe_compositing_GuiceData_instances():

    class GrandDaddy(object): pass
    g_data = GuiceData.from_class(GrandDaddy)
    g_data.init = object()
    g_data.methods = {'g_method': object(),'method': object()}

    class Daddy(GrandDaddy): pass
    d_data = GuiceData.from_class(Daddy)
    d_data.init = object()
    d_data.methods = {'d_method': object(),'method': object()}

    class Son(Daddy): pass
    s_data = GuiceData.from_class(Son)
    s_data.init = object()
    s_data.methods = {'s_method': object()}

    data = GuiceData.composite_from_class(Son)

    def should_have_create_a_new_GuiceData_instance():

# Path: snakeguice/decorators.py
# class GuiceData(object):
# 
#     def __init__(self):
#         self.init = None
#         self.methods = {}
# 
#     @classmethod
#     def from_class(cls, target_class):
#         if '__guice__' not in target_class.__dict__:
#             guice_data = cls()
#             try:
#                 target_class.__guice__ = guice_data
#             except TypeError: # special case for builtin/extension types
#                 return guice_data
#         return target_class.__guice__
# 
#     @classmethod
#     def composite_from_class(cls, target_class):
#         composite_data = GuiceData()
#         for _cls in target_class.__mro__[-1::-1]:
#             data = GuiceData.from_class(_cls)
#             if data.init: # only the last class in the chain
#                 composite_data.init = data.init
#             for name, method in data.methods.items():
#                 composite_data.methods[name] = method
# 
#         return composite_data
# 
#     @classmethod
#     def from_class_dict(cls, class_dict):
#         if '__guice__' not in class_dict:
#             class_dict['__guice__'] = cls()
#         return class_dict['__guice__']


# Path: specs/GuiceData_spec.py
from nose.tools import raises
from snakeguice.decorators import GuiceData



def describe_getting_GuiceData_from_a_dict():
    d = dict(__guice__=object())
    data = GuiceData.from_class_dict(d)

    def should_get_the_same_instance():
        assert d['__guice__'] is data


def describe_compositing_GuiceData_instances():

    class GrandDaddy(object): pass
    g_data = GuiceData.from_class(GrandDaddy)
    g_data.init = object()
    g_data.methods = {'g_method': object(),'method': object()}

    class Daddy(GrandDaddy): pass
    d_data = GuiceData.from_class(Daddy)
    d_data.init = object()
    d_data.methods = {'d_method': object(),'method': object()}

    class Son(Daddy): pass
    s_data = GuiceData.from_class(Son)
    s_data.init = object()
    s_data.methods = {'s_method': object()}

    data = GuiceData.composite_from_class(Son)

    def should_have_create_a_new_GuiceData_instance():

        assert isinstance(data, GuiceData)