diff options
Diffstat (limited to 'cliff/tests/test_app.py')
-rw-r--r-- | cliff/tests/test_app.py | 142 |
1 files changed, 0 insertions, 142 deletions
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: |