]> granicus.if.org Git - python/commitdiff
Save and restore the global asyncore.socket_map, and warn if a test modified it
authorAntoine Pitrou <solipsis@pitrou.net>
Mon, 16 Aug 2010 00:28:05 +0000 (00:28 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Mon, 16 Aug 2010 00:28:05 +0000 (00:28 +0000)
Lib/test/regrtest.py

index 48bfb5b675cb1583c88b9c901170f25167bb9c6c..9c4584c54c55727b58e36e9b40a5127de53f7678 100755 (executable)
@@ -814,7 +814,7 @@ class saved_test_environment:
 
     resources = ('sys.argv', 'cwd', 'sys.stdin', 'sys.stdout', 'sys.stderr',
                  'os.environ', 'sys.path', 'sys.path_hooks', '__import__',
-                 'warnings.filters')
+                 'warnings.filters', 'asyncore.socket_map')
 
     def get_sys_argv(self):
         return id(sys.argv), sys.argv, sys.argv[:]
@@ -872,6 +872,15 @@ class saved_test_environment:
         warnings.filters = saved_filters[1]
         warnings.filters[:] = saved_filters[2]
 
+    def get_asyncore_socket_map(self):
+        asyncore = sys.modules.get('asyncore')
+        return asyncore and asyncore.socket_map or {}
+    def restore_asyncore_socket_map(self, saved_map):
+        asyncore = sys.modules.get('asyncore')
+        if asyncore is not None:
+            asyncore.socket_map.clear()
+            asyncore.socket_map.update(saved_map)
+
     def resource_info(self):
         for name in self.resources:
             method_suffix = name.replace('.', '_')