Changeset 13775


Ignore:
Timestamp:
Oct 17, 2019 10:15:50 AM (4 weeks ago)
Author:
randersson
Message:

#5819 Replaced updating class object dict with setattr because the previous way did not work in Python 3. Also updated test to use numpy asserts to get proper error messages

Location:
branches/dev-5819/Python/src/tests_jmodelica
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/dev-5819/Python/src/tests_jmodelica/__init__.py

    r13619 r13775  
    6464    """
    6565    def wrap(func):
    66         func.__dict__.update(kwargs)
     66        for key, value in kwargs.items():
     67            setattr(func, key, value)
    6768        return func
    6869    return wrap
  • branches/dev-5819/Python/src/tests_jmodelica/test_ukf.py

    r10318 r13775  
    245245        sigma = self.ukf._calc_sigma(self.ukf.x, self.ukf.P, self.ukf.P_v,
    246246            self.ukf.P_n, self.ukf.options)
    247         assert N.allclose(sigma, N.array([[1.0,   1.002000000000029, 1.0,  0.997999999999971, 1.0],
     247        N.testing.assert_allclose(sigma, N.array([[1.0,   1.002000000000029, 1.0,  0.997999999999971, 1.0],
    248248            [0.0, 0.0,   0.001414213562393, 0.0, -0.001414213562393]]))
    249249           
     
    254254        yp = N.array([[1.18]])
    255255        y = N.array([[1.24]])
    256         assert N.allclose(self.ukf._update(y, xp, yp, K), N.array([[1.206000000000000],
     256        N.testing.assert_allclose(self.ukf._update(y, xp, yp, K), N.array([[1.206000000000000],
    257257            [0.118000000000000]]))
    258258   
     
    263263        self.ukf.yp = N.array([[1.18]])
    264264        x = self.ukf.update({'x1':1.24})
    265         assert N.allclose(x['x1'], 1.206000000000000)
    266         assert N.allclose(x['x2'], 0.118000000000000)
     265        N.testing.assert_allclose(x['x1'], 1.206000000000000)
     266        N.testing.assert_allclose(x['x2'], 0.118000000000000)
    267267   
    268268    def test_predict_private(self):
     
    280280       
    281281        #Assert predicted mean and measurement
    282         assert N.allclose(xp, [[1.00988634], [0.0172094]])
    283         assert N.allclose(yp, N.array([[1.00988634]]))
     282        N.testing.assert_allclose(xp, [[1.00988634], [0.0172094]])
     283        N.testing.assert_allclose(yp, N.array([[1.00988634]]))
    284284       
    285285        #Assert covariance and gain
    286         assert N.allclose(K, [[0.99995099], [0.00497003]])
    287         assert N.allclose(P, [[1.00099995e-01, 4.97003235e-07],
     286        N.testing.assert_allclose(K, [[0.99995099], [0.00497003]])
     287        N.testing.assert_allclose(P, [[1.00099995e-01, 4.97003235e-07],
    288288                              [4.97003235e-07, 1.00115269e+00]])
    289289   
     
    295295        self.ukf.predict(u, known_values)
    296296        #Assert predicted mean and measurement
    297         assert N.allclose(self.ukf.xp, [[1.00988634], [0.0172094]])
    298         assert N.allclose(self.ukf.yp, [[1.00988634]])
     297        N.testing.assert_allclose(self.ukf.xp, [[1.00988634], [0.0172094]])
     298        N.testing.assert_allclose(self.ukf.yp, [[1.00988634]])
    299299       
    300300        #Assert covariance and gain
    301         assert N.allclose(self.ukf.K, [[0.99995099], [0.00497003]])
    302         assert N.allclose(self.ukf.P, [[1.00099995e-01, 4.97003235e-07],
     301        N.testing.assert_allclose(self.ukf.K, [[0.99995099], [0.00497003]])
     302        N.testing.assert_allclose(self.ukf.P, [[1.00099995e-01, 4.97003235e-07],
    303303                                       [4.97003235e-07, 1.00115269e+00]])
Note: See TracChangeset for help on using the changeset viewer.