| 
									
										
										
										
											2019-05-24 19:59:01 -04:00
										 |  |  | import sys | 
					
						
							|  |  |  | import unittest | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-22 21:38:26 -05:00
										 |  |  | from . import fixtures | 
					
						
							| 
									
										
										
										
											2019-07-28 14:59:24 -04:00
										 |  |  | from importlib.metadata import ( | 
					
						
							| 
									
										
										
										
											2020-12-31 12:56:43 -05:00
										 |  |  |     PackageNotFoundError, | 
					
						
							|  |  |  |     distribution, | 
					
						
							|  |  |  |     distributions, | 
					
						
							|  |  |  |     entry_points, | 
					
						
							|  |  |  |     files, | 
					
						
							|  |  |  |     version, | 
					
						
							| 
									
										
										
										
											2019-07-28 14:59:24 -04:00
										 |  |  | ) | 
					
						
							| 
									
										
										
										
											2019-05-24 19:59:01 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-05 16:34:16 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-16 15:49:42 -05:00
										 |  |  | class TestZip(fixtures.ZipFixtures, unittest.TestCase): | 
					
						
							| 
									
										
										
										
											2019-05-24 19:59:01 -04:00
										 |  |  |     def setUp(self): | 
					
						
							| 
									
										
										
										
											2021-12-16 15:49:42 -05:00
										 |  |  |         super().setUp() | 
					
						
							| 
									
										
										
										
											2020-06-05 16:34:16 -04:00
										 |  |  |         self._fixture_on_path('example-21.12-py3-none-any.whl') | 
					
						
							| 
									
										
										
										
											2019-05-24 19:59:01 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def test_zip_version(self): | 
					
						
							|  |  |  |         self.assertEqual(version('example'), '21.12') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-28 14:59:24 -04:00
										 |  |  |     def test_zip_version_does_not_match(self): | 
					
						
							|  |  |  |         with self.assertRaises(PackageNotFoundError): | 
					
						
							|  |  |  |             version('definitely-not-installed') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-24 19:59:01 -04:00
										 |  |  |     def test_zip_entry_points(self): | 
					
						
							| 
									
										
										
										
											2021-03-13 11:31:45 -05:00
										 |  |  |         scripts = entry_points(group='console_scripts') | 
					
						
							| 
									
										
										
										
											2019-05-24 19:59:01 -04:00
										 |  |  |         entry_point = scripts['example'] | 
					
						
							|  |  |  |         self.assertEqual(entry_point.value, 'example:main') | 
					
						
							| 
									
										
										
										
											2019-06-07 14:23:39 -07:00
										 |  |  |         entry_point = scripts['Example'] | 
					
						
							|  |  |  |         self.assertEqual(entry_point.value, 'example:main') | 
					
						
							| 
									
										
										
										
											2019-05-24 19:59:01 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def test_missing_metadata(self): | 
					
						
							|  |  |  |         self.assertIsNone(distribution('example').read_text('does not exist')) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_case_insensitive(self): | 
					
						
							|  |  |  |         self.assertEqual(version('Example'), '21.12') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_files(self): | 
					
						
							|  |  |  |         for file in files('example'): | 
					
						
							|  |  |  |             path = str(file.dist.locate_file(file)) | 
					
						
							|  |  |  |             assert '.whl/' in path, path | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-05 16:34:16 -04:00
										 |  |  |     def test_one_distribution(self): | 
					
						
							|  |  |  |         dists = list(distributions(path=sys.path[:1])) | 
					
						
							|  |  |  |         assert len(dists) == 1 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-24 19:59:01 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | class TestEgg(TestZip): | 
					
						
							|  |  |  |     def setUp(self): | 
					
						
							| 
									
										
										
										
											2021-12-16 15:49:42 -05:00
										 |  |  |         super().setUp() | 
					
						
							| 
									
										
										
										
											2020-06-05 16:34:16 -04:00
										 |  |  |         self._fixture_on_path('example-21.12-py3.6.egg') | 
					
						
							| 
									
										
										
										
											2019-05-24 19:59:01 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def test_files(self): | 
					
						
							|  |  |  |         for file in files('example'): | 
					
						
							|  |  |  |             path = str(file.dist.locate_file(file)) | 
					
						
							|  |  |  |             assert '.egg/' in path, path | 
					
						
							| 
									
										
										
										
											2021-05-31 11:52:29 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def test_normalized_name(self): | 
					
						
							|  |  |  |         dist = distribution('example') | 
					
						
							|  |  |  |         assert dist._normalized_name == 'example' |