Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise exception when bad output format is given #716

Merged
merged 1 commit into from
Mar 21, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion awscli/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,4 @@ def get_formatter(format_type, args):
return TextFormatter(args)
elif format_type == 'table':
return TableFormatter(args)
return None
raise ValueError("Unknown output type: %s" % format_type)
14 changes: 7 additions & 7 deletions tests/unit/output/test_json_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,13 @@
# language governing permissions and limitations under the License.
from tests.unit import BaseAWSCommandParamsTest
import json
import os
import sys
import re

from six.moves import cStringIO
import mock


class TestGetPasswordData(BaseAWSCommandParamsTest):

prefix = 'iam add-user-to-group '

def test_empty_response_prints_nothing(self):
captured = cStringIO()
# This is the default response, but we want to be explicit
# that we're returning an empty dict.
self.parsed_response = {}
Expand Down Expand Up @@ -76,3 +69,10 @@ def test_jmespath_json_response(self):
expected_rc=0)[0]
parsed_output = json.loads(output)
self.assertEqual(parsed_output, ['testuser-50', 'testuser-51'])

def test_unknown_output_type_from_env_var(self):
# argparse already handles the case with a bad --output
# specified on the CLI, we need to verify that a bad
# output format from the env var still gives an error.
self.environ['AWS_DEFAULT_OUTPUT'] = 'bad-output-type'
self.run_cmd('iam list-users', expected_rc=255)
7 changes: 7 additions & 0 deletions tests/unit/test_clidriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from awscli.clidriver import create_clidriver
from awscli.clidriver import CustomArgument
from awscli.clidriver import CLIOperationCaller
from awscli import formatter
from botocore.hooks import HierarchicalEmitter
from botocore.provider import Provider

Expand Down Expand Up @@ -526,5 +527,11 @@ def test_verify_argument_is_none_by_default(self):
self.assertIsNone(self.recorded_args.verify_ssl)


class TestFormatter(BaseAWSCommandParamsTest):
def test_bad_output(self):
with self.assertRaises(ValueError):
formatter.get_formatter('bad-type', None)


if __name__ == '__main__':
unittest.main()