mercredi 3 mai 2017

How to initialize large list of variables inside Doctest?

I'm aware of several python modules (doctest, unittest, pytest and nose.) to test my code.

I choose doctest and I know how to create the tests inside the function or call it from a file.

My problem is that in some functions I have several variables which are 1D and 2D numpy.arrays with different dimensions, which results in a lots of lines if I have to manually initialize those variables for each test case. I would like to know if there is a way, to initialize those variables in a separate file so that they can be used for the tests. In my research I didn't found any example of it.

Below is a draft of a function with the variables and respective shape:

def evaluateFunction(t, nCoordinates, nConstraints, dataConst, q, qpto, Phi, dPhidq, niu, gamma):


  >>>
    t = np.array([...]),             # shape (n,)
    nCoordinates = np.array([...]),  # shape (n,)
    nConstraints = np.array([...]),  # shape (n,)
    dataConst = np.array([...]),     # shape (n,m)
    q = np.array([...]),             # shape (n,)
    qpto = np.array([...]),          # shape (n,)
    phi = np.array([...]),           # shape (n,)
    dPhidq = np.array([...]),        # shape (n,m)
    niu = np.array([...]),           # shape (n,)
    gamma = np.array([])             # shape (n,)
    ...
    evaluateFunction(t, nCoordinates, nConstraints, dataConst, q, qpto, Phi, 
    dPhidq, niu, gamma)
    >>>

If this approach is not correct I would appreciate any suggestion. Thank you very much for your assistance in this matter. Sincerely, Ivo

Aucun commentaire:

Enregistrer un commentaire