apidoc/object/source_raw.py
class ObjectNumber(Object, Constraintable):

    """Element ObjectNumber
    """

    def __init__(self):
        """Class instantiation
        """
        super().__init__()
        self.type = Object.Types("number")

    def get_default_sample(self):
        """Return default value for the element
        """
        return '13.37'
apidoc/object/source_raw.py
class ObjectType(Object, Constraintable):

    """Element ObjectType
    """

    def __init__(self):
        """Class instantiation
        """
        super().__init__()
        self.type = Object.Types("type")
        self.type_name = None
        self.type_object = None

    def get_default_sample(self):
        """Return default value for the element
        """
        if self.type_object is None:
            return super().get_default_sample()
        return self.type_object.get_sample()
apidoc/object/source_raw.py
class Sampleable():

    """Element who can provide samples
    """

    def __init__(self):
        """Class instantiation
        """
        super().__init__()
        self.sample = None

    def get_sample(self):
        """Return the a sample for the element
        """
        if self.sample is None:
            return self.get_default_sample()
        return self.sample

    def get_default_sample(self):
        """Return default value for the element
        """
        return "my_%s" % self.name
apidoc/object/source_raw.py
class ObjectArray(Object, Constraintable):

    """Element ObjectArray
    """

    def __init__(self):
        """Class instantiation
        """
        super().__init__()
        self.type = Object.Types("array")
        self.items = None
        self.sample_count = 2
apidoc/object/source_raw.py
class Object(Element, Sampleable):

    """Element Object
    """

    class Types(Enum):

        """List of availables Types for this element
        """
        object = 1
        array = 2
        number = 3
        string = 4
        boolean = 5
        none = 6
        reference = 7
        type = 8
        dynamic = 9
        const = 10
        enum = 11
        integer = 12
        any = 13

    @classmethod
    def factory(cls, str_type, version):
        """Return a proper object
        """
        type = Object.Types(str_type)

        if type is Object.Types.object:
            object = ObjectObject()
        elif type is Object.Types.array:
            object = ObjectArray()
        elif type is Object.Types.number:
            object = ObjectNumber()
        elif type is Object.Types.integer:
            object = ObjectInteger()
        elif type is Object.Types.string:
            object = ObjectString()
        elif type is Object.Types.boolean:
            object = ObjectBoolean()
        elif type is Object.Types.reference:
            object = ObjectReference()
        elif type is Object.Types.type:
            object = ObjectType()
        elif type is Object.Types.none:
            object = ObjectNone()
        elif type is Object.Types.dynamic:
            object = ObjectDynamic()
        elif type is Object.Types.const:
            object = ObjectConst()
        elif type is Object.Types.enum:
            object = ObjectEnum()
        else:
            object = Object()
        object.type = type
        object.version = version
        return object

    def __init__(self):
        """Class instantiation
        """
        super().__init__()
        self.type = None
        self.optional = False
apidoc/object/source_raw.py
class ObjectInteger(Object, Constraintable):

    """Element ObjectInteger
    """

    def __init__(self):
        """Class instantiation
        """
        super().__init__()
        self.type = Object.Types("integer")

    def get_default_sample(self):
        """Return default value for the element
        """
        return '42'
apidoc/object/source_raw.py
class ObjectObject(Object, Constraintable):

    """Element ObjectObject
    """

    def __init__(self):
        """Class instantiation
        """
        super().__init__()
        self.type = Object.Types("object")
        self.properties = {}
        self.pattern_properties = {}
        self.additional_properties = None
apidoc/object/source_raw.py
class TypeFormat():

    """Element TypeFormat
    """

    def __init__(self):
        """Class instantiation
        """
        super().__init__()
        self.pretty = None
        self.advanced = None
apidoc/object/source_raw.py
class ObjectEnum(Object, Constraintable):

    def __init__(self):
        """Class instantiation
        """
        super().__init__()
        self.type = Object.Types("enum")
        self.values = []
        self.descriptions = []

    def get_default_sample(self):
        """Return default value for the element
        """
        if not self.values:
            return super().get_default_sample()
        return self.values[0]
apidoc/object/source_raw.py
class Constraint(Comparable):

    """An oobject's constraint
    """

    def __init__(self, name, constraint):
        """Class instantiation
        """
        super().__init__()
        self.name = name
        self.constraint = constraint

    def __str__(self):
        return '%s: %s' % (self.name, str(self.constraint))

    def __repr__(self):
        return "%s(%r)" % (self.__class__, self.__dict__)

    def get_comparable_values(self):
        """Return a tupple of values representing the unicity of the object
        """
        return (str(self.name))
apidoc/object/source_raw.py
class ObjectBoolean(Object, Constraintable):

    """Element ObjectBoolean
    """

    def __init__(self):
        """Class instantiation
        """
        super().__init__()
        self.type = Object.Types("boolean")

    def get_default_sample(self):
        """Return default value for the element
        """
        return True
apidoc/object/source_raw.py
class EnumValue(Object, Comparable):

    def get_comparable_values(self):
        """Return a tupple of values representing the unicity of the object
        """
        return (str(self.name), str(self.description))
apidoc/object/source_raw.py
class ResponseCode(Element):

    """Element ResponseCode
    """

    def __init__(self):
        """Class instantiation
        """
        super().__init__()
        self.code = 200
        self.message = None
        self.generic = False
apidoc/object/source_raw.py
class Object(Element, Sampleable):

    """Element Object
    """

    class Types(Enum):

        """List of availables Types for this element
        """
        object = 1
        array = 2
        number = 3
        string = 4
        boolean = 5
        none = 6
        reference = 7
        type = 8
        dynamic = 9
        const = 10
        enum = 11
        integer = 12
        any = 13

    @classmethod
    def factory(cls, str_type, version):
        """Return a proper object
        """
        type = Object.Types(str_type)

        if type is Object.Types.object:
            object = ObjectObject()
        elif type is Object.Types.array:
            object = ObjectArray()
        elif type is Object.Types.number:
            object = ObjectNumber()
        elif type is Object.Types.integer:
            object = ObjectInteger()
        elif type is Object.Types.string:
            object = ObjectString()
        elif type is Object.Types.boolean:
            object = ObjectBoolean()
        elif type is Object.Types.reference:
            object = ObjectReference()
        elif type is Object.Types.type:
            object = ObjectType()
        elif type is Object.Types.none:
            object = ObjectNone()
        elif type is Object.Types.dynamic:
            object = ObjectDynamic()
        elif type is Object.Types.const:
            object = ObjectConst()
        elif type is Object.Types.enum:
            object = ObjectEnum()
        else:
            object = Object()
        object.type = type
        object.version = version
        return object

    def __init__(self):
        """Class instantiation
        """
        super().__init__()
        self.type = None
        self.optional = False
apidoc/object/source_raw.py
class Parameter(Element, Sampleable):

    """Element Parameter
    """

    def __init__(self):
        """Class instantiation
        """
        super().__init__()
        self.type = None
        self.optional = False
        self.generic = False
        self.type_object = None
        self.position = 0

    def get_object(self):
        object = Object.factory(self.type, None)
        object.name = self.name
        return object

    def get_default_sample(self):
        """Return default value for the element
        """
        if self.type not in Object.Types or self.type is Object.Types.type:
            return self.type_object.get_sample()
        else:
            return self.get_object().get_sample()
apidoc/object/source_raw.py
class ObjectString(Object, Constraintable):

    """Element ObjectString
    """

    def __init__(self):
        """Class instantiation
        """
        super().__init__()
        self.type = Object.Types("string")
apidoc/object/source_raw.py
class Method(Element, Displayable, Comparable):

    """Element Method
    """

    class Methods(Enum):

        """List of availables Methods for this element
        """
        get = 1
        post = 2
        put = 3
        delete = 4
        head = 5
        option = 6
        patch = 7

    @property
    def message(self):
        """Return default message for this element
        """
        if self.code != 200:
            for code in self.response_codes:
                if code.code == self.code:
                    return code.message

            raise ValueError("Unknown response code \"%s\" in \"%s\"." % (self.code, self.name))

        return "OK"

    def __init__(self):
        """Class instantiation
        """
        super().__init__()
        self.code = 200
        self.uri = None
        self.absolute_uri = None
        self.full_uri = None
        self.category = None
        self.method = Method.Methods("get")
        self.request_headers = {}
        self.request_parameters = {}
        self.request_body = None
        self.response_codes = []
        self.response_body = None

    def get_comparable_values(self):
        """Return a tupple of values representing the unicity of the object
        """
        return (str(self.name))
apidoc/object/source_raw.py
class ObjectReference(Object):

    """Element ObjectReference
    """

    def __init__(self):
        """Class instantiation
        """
        super().__init__()
        self.type = Object.Types("reference")
        self.reference_name = None
apidoc/object/source_raw.py
class ObjectDynamic(Object, Constraintable):

    """Element ObjectDynamic
    """

    def __init__(self):
        """Class instantiation
        """
        super().__init__()
        self.type = Object.Types("dynamic")
        self.items = None

    def get_default_sample(self):
        """Return default value for the element
        """
        return {
            "key1": "my_%s" % self.name,
            "key2": "sample"
        }
apidoc/object/source_raw.py
class ObjectNone(Object, Constraintable):

    """Element ObjectNone
    """

    def __init__(self):
        """Class instantiation
        """
        super().__init__()
        self.type = Object.Types("none")
apidoc/object/source_raw.py
class ObjectConst(Object, Constraintable):

    """Element ObjectConst
    """

    class Types(Enum):

        """List of availables Primaries for this element
        """
        string = 1
        boolean = 2
        number = 3
        integer = 4

    def __init__(self):
        """Class instantiation
        """
        super().__init__()
        self.type = Object.Types("const")
        self.const_type = ObjectConst.Types.string
        self.value = None

    def get_default_sample(self):
        """Return default value for the element
        """
        return self.value
apidoc/object/source_raw.py
class Type(Element, Comparable, Sampleable):

    """Element Type
    """

    def __init__(self):
        """Class instantiation
        """
        super().__init__()
        self.format = TypeFormat()
        self.category = None
        self.item = None

    def get_sample(self):
        """Return the a sample for the element
        """
        if self.item is not None:
            return self.item.get_sample()
        else:
            return super().get_sample()

    def get_comparable_values(self):
        """Return a tupple of values representing the unicity of the object
        """
        return (str(self.name))


Question: import unittest
from apidoc.object.source_raw import Sampleable
from apidoc.object.source_raw import Method
from apidoc.object.source_raw import Parameter, ResponseCode
from apidoc.object.source_raw import Type, TypeFormat
from apidoc.object.source_raw import Object, ObjectObject, ObjectArray
from apidoc.object.source_raw import ObjectNumber, ObjectInteger, ObjectString, ObjectBoolean, ObjectNone
from apidoc.object.source_raw import ObjectDynamic, ObjectReference, ObjectType, ObjectConst, ObjectEnum, EnumValue, Constraint
from apidoc.object.source_raw import Object as ObjectRaw



class TestSourceRaw(unittest.TestCase):

    def test_sampleable_get_sample(self):
        sampleable = Sampleable()
        sampleable.sample = "foo"

        self.assertEqual("foo", sampleable.get_sample())

    def test_sampleable_get_sample__return_default_sample(self):
        sampleable = Sampleable()
        sampleable.sample = None
        sampleable.name = "bar"

        self.assertEqual("my_bar", sampleable.get_sample())

    def test_type_get_sample(self):

Answer:         type = Type()