changeset 14971:0b21ae0a2366

tests: use getattr instead of hasattr
author Augie Fackler <durin42@gmail.com>
date Mon, 25 Jul 2011 16:37:18 -0500
parents 592e45b7d43e
children bcba68e81a81
files tests/run-tests.py tests/sitecustomize.py tests/test-symlink-os-yes-fs-no.py tests/test-walkrepo.py tests/tinyproxy.py
diffstat 5 files changed, 6 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/tests/run-tests.py	Mon Jul 25 16:05:01 2011 -0500
+++ b/tests/run-tests.py	Mon Jul 25 16:37:18 2011 -0500
@@ -340,10 +340,7 @@
     """Terminate subprocess (with fallback for Python versions < 2.6)"""
     vlog('# Terminating process %d' % proc.pid)
     try:
-        if hasattr(proc, 'terminate'):
-            proc.terminate()
-        else:
-            os.kill(proc.pid, signal.SIGTERM)
+        getattr(proc, 'terminate', lambda : os.kill(proc.pid, signal.SIGTERM))()
     except OSError:
         pass
 
--- a/tests/sitecustomize.py	Mon Jul 25 16:05:01 2011 -0500
+++ b/tests/sitecustomize.py	Mon Jul 25 16:37:18 2011 -0500
@@ -1,6 +1,5 @@
 try:
     import coverage
-    if hasattr(coverage, 'process_startup'):
-        coverage.process_startup()
+    getattr(coverage, 'process_startup', lambda: None)()
 except ImportError:
     pass
--- a/tests/test-symlink-os-yes-fs-no.py	Mon Jul 25 16:05:01 2011 -0500
+++ b/tests/test-symlink-os-yes-fs-no.py	Mon Jul 25 16:37:18 2011 -0500
@@ -5,7 +5,7 @@
 BUNDLEPATH = os.path.join(TESTDIR, 'bundles', 'test-no-symlinks.hg')
 
 # only makes sense to test on os which supports symlinks
-if not hasattr(os, "symlink"):
+if not getattr(os, "symlink", False):
     sys.exit(80) # SKIPPED_STATUS defined in run-tests.py
 
 # clone with symlink support
--- a/tests/test-walkrepo.py	Mon Jul 25 16:05:01 2011 -0500
+++ b/tests/test-walkrepo.py	Mon Jul 25 16:37:18 2011 -0500
@@ -5,7 +5,7 @@
 from os.path import join as pjoin
 
 u = ui.ui()
-sym = hasattr(os, 'symlink') and hasattr(os.path, 'samestat')
+sym = getattr(os, 'symlink', False) and getattr(os.path, 'samestat', False)
 
 hg.repository(u, 'top1', create=1)
 mkdir('subdir')
--- a/tests/tinyproxy.py	Mon Jul 25 16:05:01 2011 -0500
+++ b/tests/tinyproxy.py	Mon Jul 25 16:37:18 2011 -0500
@@ -23,7 +23,8 @@
 
     def handle(self):
         (ip, port) =  self.client_address
-        if hasattr(self, 'allowed_clients') and ip not in self.allowed_clients:
+        allowed = getattr(self, 'allowed_clients', None)
+        if allowed is not None and ip not in allowed:
             self.raw_requestline = self.rfile.readline()
             if self.parse_request():
                 self.send_error(403)