Remove redundant hasattr checks

This commit is contained in:
Hugo 2017-11-28 10:22:02 +02:00
parent de6b6a3532
commit 1f2afd3e35
3 changed files with 4 additions and 46 deletions

View File

@ -214,8 +214,7 @@ or with the pg_config option in 'setup.cfg'.
# Support unicode paths, if this version of Python provides the # Support unicode paths, if this version of Python provides the
# necessary infrastructure: # necessary infrastructure:
if sys.version_info[0] < 3 \ if sys.version_info[0] < 3:
and hasattr(sys, 'getfilesystemencoding'):
pg_config_path = pg_config_path.encode( pg_config_path = pg_config_path.encode(
sys.getfilesystemencoding()) sys.getfilesystemencoding())

View File

@ -27,8 +27,7 @@ import pickle
import psycopg2 import psycopg2
import psycopg2.extensions import psycopg2.extensions
from testutils import (unittest, ConnectingTestCase, skip_before_postgres, from testutils import (unittest, ConnectingTestCase, skip_before_postgres,
skip_if_no_getrefcount, slow, skip_if_no_superuser, slow, skip_if_no_superuser, skip_if_windows)
skip_if_windows)
import psycopg2.extras import psycopg2.extras
@ -105,7 +104,6 @@ class CursorTests(ConnectingTestCase):
self.assertEqual(b'SELECT 10.3;', self.assertEqual(b'SELECT 10.3;',
cur.mogrify("SELECT %s;", (Decimal("10.3"),))) cur.mogrify("SELECT %s;", (Decimal("10.3"),)))
@skip_if_no_getrefcount
def test_mogrify_leak_on_multiple_reference(self): def test_mogrify_leak_on_multiple_reference(self):
# issue #81: reference leak when a parameter value is referenced # issue #81: reference leak when a parameter value is referenced
# more than once from a dict. # more than once from a dict.

View File

@ -32,38 +32,9 @@ from functools import wraps
from testconfig import dsn, repl_dsn from testconfig import dsn, repl_dsn
if hasattr(unittest, 'skipIf'):
skip = unittest.skip skip = unittest.skip
skipIf = unittest.skipIf skipIf = unittest.skipIf
else:
import warnings
def skipIf(cond, msg):
def skipIf_(f):
@wraps(f)
def skipIf__(self):
if cond:
with warnings.catch_warnings():
warnings.simplefilter('always', UserWarning)
warnings.warn(msg)
return
else:
return f(self)
return skipIf__
return skipIf_
def skip(msg):
return skipIf(True, msg)
def skipTest(self, msg):
with warnings.catch_warnings():
warnings.simplefilter('always', UserWarning)
warnings.warn(msg)
return
unittest.TestCase.skipTest = skipTest
# Silence warnings caused by the stubbornness of the Python unittest # Silence warnings caused by the stubbornness of the Python unittest
# maintainers # maintainers
# http://bugs.python.org/issue9424 # http://bugs.python.org/issue9424
@ -382,16 +353,6 @@ def skip_if_green(reason):
skip_copy_if_green = skip_if_green("copy in async mode currently not supported") skip_copy_if_green = skip_if_green("copy in async mode currently not supported")
def skip_if_no_getrefcount(f):
@wraps(f)
def skip_if_no_getrefcount_(self):
if not hasattr(sys, 'getrefcount'):
return self.skipTest('skipped, no sys.getrefcount()')
else:
return f(self)
return skip_if_no_getrefcount_
def skip_if_windows(f): def skip_if_windows(f):
"""Skip a test if run on windows""" """Skip a test if run on windows"""
@wraps(f) @wraps(f)