def __init__(self, schema: Callable) -> None:
        """Initialize schema.

        :param schema: A schema.
        """
        if callable(schema):
            self.schema = schema
        else:
            raise UndefinedSchema()
Ejemplo n.º 2
0
    def __init__(self, schema: LambdaType) -> None:
        """Initialize schema.

        :param schema: A schema.
        """
        if isinstance(schema, LambdaType):
            self.schema = schema
        else:
            raise UndefinedSchema()
Ejemplo n.º 3
0
    def __init__(self, schema: SchemaType) -> None:
        """Initialize schema.

        :param schema: A schema (must be a callable object).
        """
        if callable(schema):
            self.schema = schema
        else:
            raise UndefinedSchema()
Ejemplo n.º 4
0
    def create(self, iterations=1):
        """Fill schema using data generators of mimesis.

        :param iterations: Count of iterations.
        :return: Filled schema.
        """
        if self.schema:
            return map(lambda _: self.__generate(self.schema),
                       range(iterations))
        else:
            raise UndefinedSchema('The schema is empty or do not loaded.')
Ejemplo n.º 5
0
    def fill(schema: LambdaType, iterations: int = 1) -> List[Any]:
        """Fill schema with data.

        :param lambda schema: Lambda function with schema.
        :param int iterations: Count of iterations.
        :return: Filled schema.
        :rtype: list
        :raises UndefinedSchema: if schema is empty dict.
        """
        if schema() and isinstance(schema, LambdaType):
            result = map(lambda _: schema(), range(iterations))
            return list(result)
        else:
            raise UndefinedSchema('Schema should be defined in lambda.')
Ejemplo n.º 6
0
 def create(self, iterations=1):
     if self.schema:
         return map(lambda _: self.__generate(self.schema),
                    range(iterations))
     else:
         raise UndefinedSchema('The schema is empty or do not loaded.')
Ejemplo n.º 7
0
 def __init__(self, schema: LambdaType) -> None:
     if callable(schema) and isinstance(schema, LambdaType):
         self.schema = schema
     else:
         raise UndefinedSchema()