parent
							
								
									05eee78aaa
								
							
						
					
					
						commit
						ca40380e99
					
				|  | @ -0,0 +1 @@ | ||||||
|  | Fix :func:`pytest.approx` handling of dictionaries containing one or more values of `0.0` in class ApproxMapping. | ||||||
|  | @ -269,10 +269,16 @@ class ApproxMapping(ApproxBase): | ||||||
|                 max_abs_diff = max( |                 max_abs_diff = max( | ||||||
|                     max_abs_diff, abs(approx_value.expected - other_value) |                     max_abs_diff, abs(approx_value.expected - other_value) | ||||||
|                 ) |                 ) | ||||||
|                 max_rel_diff = max( |                 if approx_value.expected == 0.0: | ||||||
|                     max_rel_diff, |                     max_rel_diff = math.inf | ||||||
|                     abs((approx_value.expected - other_value) / approx_value.expected), |                 else: | ||||||
|                 ) |                     max_rel_diff = max( | ||||||
|  |                         max_rel_diff, | ||||||
|  |                         abs( | ||||||
|  |                             (approx_value.expected - other_value) | ||||||
|  |                             / approx_value.expected | ||||||
|  |                         ), | ||||||
|  |                     ) | ||||||
|                 different_ids.append(approx_key) |                 different_ids.append(approx_key) | ||||||
| 
 | 
 | ||||||
|         message_data = [ |         message_data = [ | ||||||
|  |  | ||||||
|  | @ -630,6 +630,19 @@ class TestApprox: | ||||||
|     def test_dict_vs_other(self): |     def test_dict_vs_other(self): | ||||||
|         assert 1 != approx({"a": 0}) |         assert 1 != approx({"a": 0}) | ||||||
| 
 | 
 | ||||||
|  |     def test_dict_for_div_by_zero(self, assert_approx_raises_regex): | ||||||
|  |         assert_approx_raises_regex( | ||||||
|  |             {"foo": 42.0}, | ||||||
|  |             {"foo": 0.0}, | ||||||
|  |             [ | ||||||
|  |                 r"  comparison failed. Mismatched elements: 1 / 1:", | ||||||
|  |                 rf"  Max absolute difference: {SOME_FLOAT}", | ||||||
|  |                 r"  Max relative difference: inf", | ||||||
|  |                 r"  Index \| Obtained\s+\| Expected   ", | ||||||
|  |                 rf"  foo   | {SOME_FLOAT} \| {SOME_FLOAT} ± {SOME_FLOAT}", | ||||||
|  |             ], | ||||||
|  |         ) | ||||||
|  | 
 | ||||||
|     def test_numpy_array(self): |     def test_numpy_array(self): | ||||||
|         np = pytest.importorskip("numpy") |         np = pytest.importorskip("numpy") | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue