From 84ce674e861d05bdcf478b3fd0348594fb3849b7 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Fri, 26 Nov 2010 16:23:32 +0000
Subject: [PATCH] asyncnotifier tests: simplify the setup code
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

First change is to replace "range(len(self.NOTIFIERS)))" with
self.NOTIFIERS, as range(len(range(N))) ≑ range(N).

Sencond change is switch from an explicit indexing to use of zip.
Unittests still pass :)

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
---
 test/ganeti.asyncnotifier_unittest.py | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/test/ganeti.asyncnotifier_unittest.py b/test/ganeti.asyncnotifier_unittest.py
index adef2dd20..5fdaf56c2 100755
--- a/test/ganeti.asyncnotifier_unittest.py
+++ b/test/ganeti.asyncnotifier_unittest.py
@@ -64,15 +64,12 @@ class TestSingleFileEventHandler(testutils.GanetiTestCase):
     # We need one watch manager per notifier, as those contain the file
     # descriptor which is monitored by asyncore
     self.wms = [pyinotify.WatchManager() for i in self.NOTIFIERS]
-    self.cbk = [self.OnInotifyCallback(self, i)
-                 for i in range(len(self.NOTIFIERS))]
-    self.ihandler = [asyncnotifier.SingleFileEventHandler(self.wms[i],
-                                                          self.cbk[i],
-                                                          self.chk_files[i])
-                      for i in range(len(self.NOTIFIERS))]
-    self.notifiers = [_MyErrorLoggingAsyncNotifier(self.wms[i],
-                                                   self.ihandler[i])
-                       for i in range(len(self.NOTIFIERS))]
+    self.cbk = [self.OnInotifyCallback(self, i) for i in self.NOTIFIERS]
+    self.ihandler = [asyncnotifier.SingleFileEventHandler(wm, cb, cf)
+                     for (wm, cb, cf) in
+                     zip(self.wms, self.cbk, self.chk_files)]
+    self.notifiers = [_MyErrorLoggingAsyncNotifier(wm, ih)
+                      for (wm, ih) in zip(self.wms, self.ihandler)]
     # TERM notifier is enabled by default, as we use it to get out of the loop
     self.ihandler[self.NOTIFIER_TERM].enable()
 
-- 
GitLab