Coder Social home page Coder Social logo

mass-production's Introduction

Build Status

Mass Production with Conveyor

The Conveyor class enables calling a single function a specified number of times with keyword arguments that change according to a pattern specified by chaining method calls.

Example

This library was orginally developed for use with factory-boy factories:

class Person(object):
    def __init__(self, name=None, hair_color=None, job=None, age=None):
        self.name = name
        self.hair_color = hair_color
        self.job = job
        self.age = age

    def __repr__(self):
        return ('Person(name={}, hair_color={}, job={}, age={})'
                .format(self.name, self.hair_color, self.job, self.age))


from factory import Factory

class PersonFactory(Factory):
    class Meta:
        model = Person

    name = 'Jane Doe'
    hair_color = 'blond'
    job = 'Developer'
    age = 25


from mass_production import Conveyor

people = (Conveyor.create_batch_from(PersonFactory)
          .cycling(job=['Developer', 'Designer'],
                   hair_color=['blond', 'black', 'brown'])
          .from_table(['name', 'age'],
                      [['Eva', 25],
                       ['Arno', 28],
                       ['Margaux', 31],
                       ['George', 46],
                       ['Mary', 52],
                       ['Sander', 22]]))

# returns:
[Person(name='Eva', hair_color='blond', job='Developer', age=25),
 Person(name='Arno', hair_color='black', job='Designer', age=28),
 Person(name='Margaux', hair_color='brown', job='Developer', age=31),
 Person(name='George', hair_color='blond', job='Designer', age=46),
 Person(name='Mary', hair_color='black', job='Developer', age=52),
 Person(name='Sander', hair_color='brown', job='Designer', age=22)]

You don't have to use factory-boy though, you can specify any function using Converyor.call: The above is equivalent when Conveyor.call(PersonFactory.create) is used instead of Conveyor.create_batch_from(PersonFactory)

Notice

Look. This utility was developed to make repeating code a little easier to read by avoiding huge blocks of almost-repeating statements. Using it is a balancing act, though, it's very easy to change a slightly unreadable block of code into a completely unreadable Conveyor statement. Think. Do I need to use Conveyor or is it readable without it? Does a single for loop suffice?

Installation

pip install mass-production

mass-production's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.