| 
									
										
										
										
											2025-04-01 16:29:32 +02:00
										 |  |  | import unittest | 
					
						
							|  |  |  | import os | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class TestPackages(unittest.TestCase): | 
					
						
							|  |  |  |     def test_packages_have_init(self): | 
					
						
							|  |  |  |         """Test that all world folders containing .py files also have a __init__.py file,
 | 
					
						
							|  |  |  |         to indicate full package rather than namespace package."""
 | 
					
						
							|  |  |  |         import Utils | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-27 19:57:19 -05:00
										 |  |  |         # Ignore directories with these names. | 
					
						
							|  |  |  |         ignore_dirs = {".github"} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-01 16:29:32 +02:00
										 |  |  |         worlds_path = Utils.local_path("worlds") | 
					
						
							|  |  |  |         for dirpath, dirnames, filenames in os.walk(worlds_path): | 
					
						
							| 
									
										
										
										
											2025-07-27 19:57:19 -05:00
										 |  |  |             # Drop ignored directories from dirnames, excluding them from walking. | 
					
						
							|  |  |  |             dirnames[:] = [d for d in dirnames if d not in ignore_dirs] | 
					
						
							| 
									
										
										
										
											2025-04-01 16:29:32 +02:00
										 |  |  |             with self.subTest(directory=dirpath): | 
					
						
							|  |  |  |                 self.assertEqual("__init__.py" in filenames, any(file.endswith(".py") for file in filenames)) |