Changeset 13483


Ignore:
Timestamp:
Sep 16, 2019 8:04:48 AM (3 months ago)
Author:
randersson
Message:

#5819 Updated tests with error messages in order to debug what is wrong with the tests properly since they are simply failing now with AssertionError. I did also replace some asserts from other python packages with the standard assert

File:
1 edited

Legend:

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

    r13461 r13483  
    129129        log = parse_jmi_log(self.log_file_name)
    130130        solves = gather_solves(log)
    131         nose.tools.assert_equals(solves, [])
     131        assert not solves, "Failed in assert (1/6) because list is not empty, got solves={}".format(solves)
    132132       
    133133        self.setUp()
     
    137137        log = parse_jmi_log(self.log_file_name)
    138138        solves = gather_solves(log)
    139         nose.tools.assert_equals(solves, [])
     139        assert not solves, "Failed in assert (2/6) because list is not empty, got solves={}".format(solves)
    140140       
    141141        self.setUp()
     
    145145        log = parse_jmi_log(self.log_file_name)
    146146        solves = gather_solves(log)
    147         nose.tools.assert_equals(solves, [])
     147        assert not solves, "Failed in assert (3/6) because list is not empty, got solves={}".format(solves)
    148148       
    149149        self.setUp()
     
    153153        log = parse_jmi_log(self.log_file_name)
    154154        solves = gather_solves(log)
    155         nose.tools.assert_equals(solves, [])
     155        assert not solves, "Failed in assert (4/6) because list is not empty, got solves={}".format(solves)
    156156       
    157157        self.setUp()
     
    161161        log = parse_jmi_log(self.log_file_name)
    162162        solves = gather_solves(log)
    163         nose.tools.assert_equals(len(solves), 4)
     163        assert len(solves) == 4, "Failed in assert (5/6) because result is not of length 4, got solves={}, with length {}".format(solves, len(solves))
    164164       
    165165        self.setUp()
     
    169169        log = parse_jmi_log(self.log_file_name)
    170170        solves = gather_solves(log)
    171         nose.tools.assert_equals(len(solves), 4)
     171        assert len(solves) == 4, "Failed in assert (6/6) because result is not of length 4, got solves={}, with length {}".format(solves, len(solves))
    172172   
    173173    @testattr(stddist_full = True)
     
    181181        log = parse_jmi_log(self.log_file_name)
    182182        solves = gather_solves(log)
    183         N.testing.assert_array_almost_equal(solves[0].block_solves[0].iterations[-1].ivs, N.array([N.sqrt(11), 5. ]))
     183        result = solves[0].block_solves[0].iterations[-1].ivs
     184        expected = N.array([N.sqrt(11), 5. ])
     185        err_msg = "Arrays not equal, expected {} but got {}".format(expected, result)
     186        assert N.allclose(result, expected), err_msg
    184187       
    185188       
     
    227230        log = parse_jmi_log(self.log_file_name)
    228231        solves = gather_solves(log)
    229         nose.tools.assert_true(N.array_equal(solves[0].block_solves[0].nominal,
    230                                              N.array([1.,1.])))
     232        result = solves[0].block_solves[0].nominal
     233        expected = N.array([1.,1.])
     234        err_msg = "Arrays not equal, expected {} but got {}".format(expected, result)
     235        assert N.allclose(result, expected), err_msg
    231236       
    232237    @testattr(stddist_full = True)
     
    239244        log = parse_jmi_log(self.log_file_name)
    240245        solves = gather_solves(log)
    241         nose.tools.assert_false(N.array_equal(solves[0].block_solves[0].iterations[0].residual_scaling,
    242                                              N.array([1., 1.])))
     246        result = solves[0].block_solves[0].iterations[0].residual_scaling
     247        expected = N.array([1., 1.])
     248        err_msg = "Arrays are supposed to be different but are actually equal. Result={}\nExpected={}".format(result, expected)
     249        assert not N.allclose(result, expected), err_msg
    243250       
    244251#        self.setUp()
     
    257264        solves = gather_solves(log)
    258265        #residual scaling is not logged when turned off.
    259         nose.tools.assert_false('residual_scaling' in solves[0].block_solves[0].iterations[0])
     266        condition = 'residual_scaling' in solves[0].block_solves[0].iterations[0]
     267        assert not condition, "Test failed because string residual_scaling was found in {}".format(solves[0].block_solves[0].iterations[0])
    260268   
    261269    @testattr(stddist_full = True)
     
    283291        log = parse_jmi_log(self.log_file_name)
    284292        solves = gather_solves(log)
    285         nose.tools.assert_equals(solves, [])
     293        assert not solves, "Failed in assert (1/6) because list is not empty, got solves={}".format(solves)
    286294       
    287295        self.setUp('test_KINsolver_options_log_ll2.txt')
     
    290298        log = parse_jmi_log(self.log_file_name)
    291299        solves = gather_solves(log)
    292         nose.tools.assert_equals(solves, [])
     300        assert not solves, "Failed in assert (2/6) because list is not empty, got solves={}".format(solves)
    293301       
    294302        self.setUp('test_KINsolver_options_log_ll3.txt')
     
    297305        log = parse_jmi_log(self.log_file_name)
    298306        solves = gather_solves(log)
    299         nose.tools.assert_equals(solves, [])
     307        assert not solves, "Failed in assert (3/6) because list is not empty, got solves={}".format(solves)
    300308       
    301309        self.setUp('test_KINsolver_options_log_ll4.txt')
     
    304312        log = parse_jmi_log(self.log_file_name)
    305313        solves = gather_solves(log)
    306         nose.tools.assert_equals(solves, [])
     314        assert not solves, "Failed in assert (4/6) because list is not empty, got solves={}".format(solves)
    307315       
    308316        self.setUp('test_KINsolver_options_log_ll5.txt')
     
    311319        log = parse_jmi_log(self.log_file_name)
    312320        solves = gather_solves(log)
    313         nose.tools.assert_equals(len(solves), 2)
     321        assert len(solves) == 2, "Failed in assert (5/6) because result is not of length 2, got solves={}, with length {}".format(solves, len(solves))
    314322       
    315323        self.setUp('test_KINsolver_options_log_ll6.txt')
     
    318326        log = parse_jmi_log(self.log_file_name)
    319327        solves = gather_solves(log)
    320         print(solves)
    321         nose.tools.assert_equals(len(solves), 2)
     328        assert len(solves) == 2, "Failed in assert (6/6) because result is not of length 2, got solves={}, with length {}".format(solves, len(solves))
    322329   
    323330    @testattr(stddist_full = True)
     
    331338        log = parse_jmi_log(self.log_file_name)
    332339        solves = gather_solves(log)
    333         N.testing.assert_array_almost_equal(solves[0].block_solves[0].iterations[-1].ivs, N.array([N.sqrt(11), 5. ]))
    334        
    335    
    336        
    337        
    338        
    339        
    340        
    341        
    342        
    343 
     340        result = solves[0].block_solves[0].iterations[-1].ivs
     341        expected = N.array([N.sqrt(11), 5. ])
     342        err_msg = "Arrays are not almost equal:\nEXPECTED: {}\nACTUAL: {}".format(expected, result)
     343        N.testing.assert_array_almost_equal(result, expected, err_msg=err_msg)
     344       
     345   
     346       
     347       
     348       
     349       
     350       
     351       
     352       
     353
Note: See TracChangeset for help on using the changeset viewer.