summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChangBo Guo(gcb) <eric.guo@easystack.cn>2015-12-30 15:58:00 +0800
committerSteve Martinelli <stevemar@ca.ibm.com>2016-02-11 01:55:34 -0500
commit12a544a0912d33519465c51c30545d3a7a800376 (patch)
tree22f17ad59aab0208ed26acabdffbf17a945a7f88
parent87075d698e855ba1f131fcbf8d42f73c14ccfcac (diff)
downloadcliff-12a544a0912d33519465c51c30545d3a7a800376.tar.gz
Drop Python 2.6 support
* Remove py2.6 from tox.ini * Use itertools.compress(added in python 2.7) directly * Use logging.NullHandler(added in python 2.7) directly * Remove python 2.6 bug work around and related tests Change-Id: Ie56a1590b9d4f0c544ebc5e7a4d40624e1ef4359
-rw-r--r--cliff/app.py40
-rw-r--r--cliff/display.py10
-rw-r--r--cliff/tests/test_app.py142
-rw-r--r--tox.ini3
4 files changed, 5 insertions, 190 deletions
diff --git a/cliff/app.py b/cliff/app.py
index 6edb842..30286c1 100644
--- a/cliff/app.py
+++ b/cliff/app.py
@@ -1,7 +1,6 @@
"""Application base class.
"""
-import codecs
import inspect
import locale
import logging
@@ -14,24 +13,8 @@ from .complete import CompleteCommand
from .help import HelpAction, HelpCommand
from .utils import damerau_levenshtein, COST
-# Make sure the cliff library has a logging handler
-# in case the app developer doesn't set up logging.
-# For py26 compat, create a NullHandler
-if hasattr(logging, 'NullHandler'):
- NullHandler = logging.NullHandler
-else:
- class NullHandler(logging.Handler):
- def handle(self, record):
- pass
-
- def emit(self, record):
- pass
-
- def createLock(self):
- self.lock = None
-
-logging.getLogger('cliff').addHandler(NullHandler())
+logging.getLogger('cliff').addHandler(logging.NullHandler())
class App(object):
@@ -87,24 +70,9 @@ class App(object):
locale.setlocale(locale.LC_ALL, '')
except locale.Error:
pass
- if sys.version_info[:2] == (2, 6):
- # Configure the input and output streams. If a stream is
- # provided, it must be configured correctly by the
- # caller. If not, make sure the versions of the standard
- # streams used by default are wrapped with encodings. This
- # works around a problem with Python 2.6 fixed in 2.7 and
- # later (http://hg.python.org/cpython/rev/e60ef17561dc/).
- lang, encoding = locale.getdefaultlocale()
- encoding = (getattr(sys.stdout, 'encoding', None) or
- encoding or
- self.DEFAULT_OUTPUT_ENCODING)
- self.stdin = stdin or codecs.getreader(encoding)(sys.stdin)
- self.stdout = stdout or codecs.getwriter(encoding)(sys.stdout)
- self.stderr = stderr or codecs.getwriter(encoding)(sys.stderr)
- else:
- self.stdin = stdin or sys.stdin
- self.stdout = stdout or sys.stdout
- self.stderr = stderr or sys.stderr
+ self.stdin = stdin or sys.stdin
+ self.stdout = stdout or sys.stdout
+ self.stderr = stderr or sys.stderr
def build_option_parser(self, description, version,
argparse_kwargs=None):
diff --git a/cliff/display.py b/cliff/display.py
index 833ebb7..31e5abf 100644
--- a/cliff/display.py
+++ b/cliff/display.py
@@ -1,15 +1,7 @@
"""Application base class for displaying data.
"""
import abc
-
-try:
- from itertools import compress
-except ImportError:
- # for py26 compat
- from itertools import izip
-
- def compress(data, selectors):
- return (d for d, s in izip(data, selectors) if s)
+from itertools import compress
import six
import stevedore
diff --git a/cliff/tests/test_app.py b/cliff/tests/test_app.py
index 19ff46b..718e1a2 100644
--- a/cliff/tests/test_app.py
+++ b/cliff/tests/test_app.py
@@ -4,9 +4,7 @@ try:
from StringIO import StringIO
except ImportError:
from io import StringIO
-import sys
-import nose
import mock
from cliff.app import App
@@ -274,146 +272,6 @@ def test_option_parser_abbrev_issue():
app.run(['--debug', 'mycommand', '--end', '123'])
-def test_output_encoding_default():
- # The encoding should come from getdefaultlocale() because
- # stdout has no encoding set.
- if sys.version_info[:2] != (2, 6):
- raise nose.SkipTest('only needed for python 2.6')
- data = '\xc3\xa9'
- u_data = data.decode('utf-8')
-
- class MyApp(App):
- def __init__(self):
- super(MyApp, self).__init__(
- description='testing',
- version='0.1',
- command_manager=CommandManager('tests'),
- )
-
- stdout = StringIO()
-
- getdefaultlocale = mock.Mock(return_value=('ignored', 'utf-8'))
-
- with mock.patch('sys.stdout', stdout):
- with mock.patch('locale.getdefaultlocale', getdefaultlocale):
- app = MyApp()
- app.stdout.write(u_data)
- actual = stdout.getvalue()
- assert data == actual
-
-
-def test_output_encoding_cliff_default():
- # The encoding should come from cliff.App.DEFAULT_OUTPUT_ENCODING
- # because the other values are missing or None
- if sys.version_info[:2] != (2, 6):
- raise nose.SkipTest('only needed for python 2.6')
- data = '\xc3\xa9'
- u_data = data.decode('utf-8')
-
- class MyApp(App):
- def __init__(self):
- super(MyApp, self).__init__(
- description='testing',
- version='0.1',
- command_manager=CommandManager('tests'),
- )
-
- stdout = StringIO()
- getdefaultlocale = mock.Mock(return_value=('ignored', None))
-
- with mock.patch('sys.stdout', stdout):
- with mock.patch('locale.getdefaultlocale', getdefaultlocale):
- app = MyApp()
- app.stdout.write(u_data)
- actual = stdout.getvalue()
- assert data == actual
-
-
-def test_output_encoding_sys():
- # The encoding should come from sys.stdout because it is set
- # there.
- if sys.version_info[:2] != (2, 6):
- raise nose.SkipTest('only needed for python 2.6')
- data = '\xc3\xa9'
- u_data = data.decode('utf-8')
-
- class MyApp(App):
- def __init__(self):
- super(MyApp, self).__init__(
- description='testing',
- version='0.1',
- command_manager=CommandManager('tests'),
- )
-
- stdout = StringIO()
- stdout.encoding = 'utf-8'
- getdefaultlocale = mock.Mock(return_value=('ignored', 'utf-16'))
-
- with mock.patch('sys.stdout', stdout):
- with mock.patch('locale.getdefaultlocale', getdefaultlocale):
- app = MyApp()
- app.stdout.write(u_data)
- actual = stdout.getvalue()
- assert data == actual
-
-
-def test_error_encoding_default():
- # The encoding should come from getdefaultlocale() because
- # stdout has no encoding set.
- if sys.version_info[:2] != (2, 6):
- raise nose.SkipTest('only needed for python 2.6')
- data = '\xc3\xa9'
- u_data = data.decode('utf-8')
-
- class MyApp(App):
- def __init__(self):
- super(MyApp, self).__init__(
- description='testing',
- version='0.1',
- command_manager=CommandManager('tests'),
- )
-
- stderr = StringIO()
- getdefaultlocale = mock.Mock(return_value=('ignored', 'utf-8'))
-
- with mock.patch('sys.stderr', stderr):
- with mock.patch('locale.getdefaultlocale', getdefaultlocale):
- app = MyApp()
- app.stderr.write(u_data)
- actual = stderr.getvalue()
- assert data == actual
-
-
-def test_error_encoding_sys():
- # The encoding should come from sys.stdout (not sys.stderr)
- # because it is set there.
- if sys.version_info[:2] != (2, 6):
- raise nose.SkipTest('only needed for python 2.6')
- data = '\xc3\xa9'
- u_data = data.decode('utf-8')
-
- class MyApp(App):
- def __init__(self):
- super(MyApp, self).__init__(
- description='testing',
- version='0.1',
- command_manager=CommandManager('tests'),
- )
-
- stdout = StringIO()
- stdout.encoding = 'utf-8'
- stderr = StringIO()
- getdefaultlocale = mock.Mock(return_value=('ignored', 'utf-16'))
-
- with mock.patch('sys.stdout', stdout):
- with mock.patch('sys.stderr', stderr):
- with mock.patch('locale.getdefaultlocale', getdefaultlocale):
- app = MyApp()
- app.stderr.write(u_data)
- actual = stderr.getvalue()
- assert data == actual
-
-
def _test_help(deferred_help):
app, _ = make_app(deferred_help=deferred_help)
with mock.patch.object(app, 'initialize_app') as init:
diff --git a/tox.ini b/tox.ini
index 6a60568..28bd0fc 100644
--- a/tox.ini
+++ b/tox.ini
@@ -11,9 +11,6 @@ deps = -r{toxinidir}/test-requirements.txt
deps = flake8
commands = flake8 cliff doc/source/conf.py setup.py
-[testenv:py26]
-basepython=python2.6
-
[testenv:venv]
commands = {posargs}