mardi 29 mars 2016

Pythonic Way To Test All Combinations Of Function Parameters

I have a given function (which I cannot change) of the form:

def foo(bar=False, baz=False, ban=False, baf=False, bal=False):
    ...

In some unittest code, I'd like to perform tests on all the 25 calls:

foo(bar=False, baz=False, ban=False, baf=False, bal=False)
foo(bar=False, baz=False, ban=False, baf=False, bal=True)
foo(bar=False, baz=False, ban=False, baf=True, bal=False)
foo(bar=False, baz=False, ban=False, baf=True, bal=True)
...
foo(bar=True, baz=True, ban=True, baf=True, bal=True)

(for the sake of the question, run each call, and assertEqual that the result is 10.)

What is a pythonic way of doing so?

Aucun commentaire:

Enregistrer un commentaire