actually some monkey patching is still needed for predictability
authorsylvain.thenault@logilab.fr
Sat, 04 Apr 2009 14:54:04 +0200
changeset 1235 9c081452efc2
parent 1233 9f2760f15000
child 1236 aeb46e43138d
actually some monkey patching is still needed for predictability
devtools/repotest.py
--- a/devtools/repotest.py	Sat Apr 04 14:46:03 2009 +0200
+++ b/devtools/repotest.py	Sat Apr 04 14:54:04 2009 +0200
@@ -258,38 +258,28 @@
     class PartPlanInformation(object):
         def merge_input_maps(*args):
             pass
-#         def _choose_term(self, sourceterms):
-#             pass    
+        def _choose_term(self, sourceterms):
+            pass    
 _orig_merge_input_maps = PartPlanInformation.merge_input_maps
-# _orig_choose_term = PartPlanInformation._choose_term
+_orig_choose_term = PartPlanInformation._choose_term
 
 def _merge_input_maps(*args):
     return sorted(_orig_merge_input_maps(*args))
 
-# def _choose_term(self, sourceterms):
-#     # predictable order for test purpose
-#     def get_key(x):
-#         try:
-#             # variable
-#             return x.name
-#         except AttributeError:
-#             try:
-#                 # relation
-#                 return x.r_type
-#             except AttributeError:
-#                 # const
-#                 return x.value
-#     varsinorder = sorted(sourceterms, key=get_key)
-#     if len(self._sourcesterms) > 1:
-#         for var in varsinorder:
-#             if not var.scope is self.rqlst:
-#                 return var, sourceterms.pop(var)
-#     else:
-#         for var in varsinorder:
-#             if var.scope is self.rqlst:
-#                 return var, sourceterms.pop(var)
-#     var = varsinorder[0]
-#     return var, sourceterms.pop(var)
+def _choose_term(self, sourceterms):
+    # predictable order for test purpose
+    def get_key(x):
+        try:
+            # variable
+            return x.name
+        except AttributeError:
+            try:
+                # relation
+                return x.r_type
+            except AttributeError:
+                # const
+                return x.value
+    return _orig_choose_term(self, sorted(sourceterms, key=get_key))
 
 
 def do_monkey_patch():
@@ -299,7 +289,7 @@
     ExecutionPlan.tablesinorder = None
     ExecutionPlan.init_temp_table = _init_temp_table
     PartPlanInformation.merge_input_maps = _merge_input_maps
-    #PartPlanInformation._choose_term = _choose_term
+    PartPlanInformation._choose_term = _choose_term
 
 def undo_monkey_patch():
     RQLRewriter.insert_snippets = _orig_insert_snippets
@@ -307,5 +297,5 @@
     ExecutionPlan._check_permissions = _orig_check_permissions
     ExecutionPlan.init_temp_table = _orig_init_temp_table
     PartPlanInformation.merge_input_maps = _orig_merge_input_maps
-    #PartPlanInformation._choose_term = _orig_choose_term
+    PartPlanInformation._choose_term = _orig_choose_term