mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	bpo-44784: Apply changes from importlib_metadata 4.6.3 (GH-27508)
Addressing issues with tests under error on warnings. Automerge-Triggered-By: GH:jaraco
This commit is contained in:
		
							parent
							
								
									302cf35505
								
							
						
					
					
						commit
						1cf8424a62
					
				
					 2 changed files with 14 additions and 6 deletions
				
			
		|  | @ -3,6 +3,7 @@ | ||||||
| import unittest | import unittest | ||||||
| import warnings | import warnings | ||||||
| import importlib | import importlib | ||||||
|  | import contextlib | ||||||
| 
 | 
 | ||||||
| from . import fixtures | from . import fixtures | ||||||
| from importlib.metadata import ( | from importlib.metadata import ( | ||||||
|  | @ -17,6 +18,13 @@ | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @contextlib.contextmanager | ||||||
|  | def suppress_known_deprecation(): | ||||||
|  |     with warnings.catch_warnings(record=True) as ctx: | ||||||
|  |         warnings.simplefilter('default') | ||||||
|  |         yield ctx | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| class APITests( | class APITests( | ||||||
|     fixtures.EggInfoPkg, |     fixtures.EggInfoPkg, | ||||||
|     fixtures.DistInfoPkg, |     fixtures.DistInfoPkg, | ||||||
|  | @ -118,8 +126,7 @@ def test_entry_points_dict_construction(self): | ||||||
|         # Prior versions of entry_points() returned simple lists and |         # Prior versions of entry_points() returned simple lists and | ||||||
|         # allowed casting those lists into maps by name using ``dict()``. |         # allowed casting those lists into maps by name using ``dict()``. | ||||||
|         # Capture this now deprecated use-case. |         # Capture this now deprecated use-case. | ||||||
|         with warnings.catch_warnings(record=True) as caught: |         with suppress_known_deprecation() as caught: | ||||||
|             warnings.filterwarnings("default", category=DeprecationWarning) |  | ||||||
|             eps = dict(entry_points(group='entries')) |             eps = dict(entry_points(group='entries')) | ||||||
| 
 | 
 | ||||||
|         assert 'main' in eps |         assert 'main' in eps | ||||||
|  | @ -138,8 +145,7 @@ def test_entry_points_by_index(self): | ||||||
|         See python/importlib_metadata#300 and bpo-44246. |         See python/importlib_metadata#300 and bpo-44246. | ||||||
|         """ |         """ | ||||||
|         eps = distribution('distinfo-pkg').entry_points |         eps = distribution('distinfo-pkg').entry_points | ||||||
|         with warnings.catch_warnings(record=True) as caught: |         with suppress_known_deprecation() as caught: | ||||||
|             warnings.filterwarnings("default", category=DeprecationWarning) |  | ||||||
|             eps[0] |             eps[0] | ||||||
| 
 | 
 | ||||||
|         # check warning |         # check warning | ||||||
|  | @ -151,7 +157,7 @@ def test_entry_points_groups_getitem(self): | ||||||
|         # Prior versions of entry_points() returned a dict. Ensure |         # Prior versions of entry_points() returned a dict. Ensure | ||||||
|         # that callers using '.__getitem__()' are supported but warned to |         # that callers using '.__getitem__()' are supported but warned to | ||||||
|         # migrate. |         # migrate. | ||||||
|         with warnings.catch_warnings(record=True): |         with suppress_known_deprecation(): | ||||||
|             entry_points()['entries'] == entry_points(group='entries') |             entry_points()['entries'] == entry_points(group='entries') | ||||||
| 
 | 
 | ||||||
|             with self.assertRaises(KeyError): |             with self.assertRaises(KeyError): | ||||||
|  | @ -161,7 +167,7 @@ def test_entry_points_groups_get(self): | ||||||
|         # Prior versions of entry_points() returned a dict. Ensure |         # Prior versions of entry_points() returned a dict. Ensure | ||||||
|         # that callers using '.get()' are supported but warned to |         # that callers using '.get()' are supported but warned to | ||||||
|         # migrate. |         # migrate. | ||||||
|         with warnings.catch_warnings(record=True): |         with suppress_known_deprecation(): | ||||||
|             entry_points().get('missing', 'default') == 'default' |             entry_points().get('missing', 'default') == 'default' | ||||||
|             entry_points().get('entries', 'default') == entry_points()['entries'] |             entry_points().get('entries', 'default') == entry_points()['entries'] | ||||||
|             entry_points().get('missing', ()) == () |             entry_points().get('missing', ()) == () | ||||||
|  |  | ||||||
|  | @ -0,0 +1,2 @@ | ||||||
|  | In importlib.metadata tests, override warnings behavior under expected | ||||||
|  | DeprecationWarnings (importlib_metadata 4.6.3). | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Jason R. Coombs
						Jason R. Coombs