How to use the awscli.compat.six.StringIO function in awscli

To help you get started, we’ve selected a few awscli examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aws / aws-cli / tests / functional / docs / test_help_output.py View on Github external
def assert_command_does_not_exist(self, service, command):
        # Basically try to get the help output for the removed
        # command verify that we get a SystemExit exception
        # and that we get something in stderr that says that
        # we made an invalid choice (because the operation is removed).
        stderr = six.StringIO()
        with mock.patch('sys.stderr', stderr):
            with self.assertRaises(SystemExit):
                self.driver.main([service, command, 'help'])
        # We should see an error message complaining about
        # an invalid choice because the operation has been removed.
        self.assertIn('argument operation: Invalid choice', stderr.getvalue())
github aws / aws-cli / tests / unit / customizations / configure / test_configure.py View on Github external
def setUp(self):
        self.input_patch = mock.patch('awscli.compat.raw_input')
        self.mock_raw_input = self.input_patch.start()
        self.stdout = six.StringIO()
        self.stdout_patch = mock.patch('sys.stdout', self.stdout)
        self.stdout_patch.start()
github aws / aws-cli / tests / unit / customizations / test_generatecliskeleton.py View on Github external
def test_generate_json_skeleton(self):
        parsed_args = mock.Mock()
        parsed_args.generate_cli_skeleton = 'input'
        with mock.patch('sys.stdout', six.StringIO()) as mock_stdout:
            rc = self.argument.generate_json_skeleton(
                service_operation=self.service_operation, call_parameters=None,
                parsed_args=parsed_args, parsed_globals=None
            )
            # Ensure the contents printed to standard output are correct.
            self.assertEqual(self.ref_json_output, mock_stdout.getvalue())
            # Ensure it is the correct return code of zero.
            self.assertEqual(rc, 0)
github aws / aws-cli / tests / unit / s3 / test_get_object.py View on Github external
def setUp(self):
        super(TestGetObject, self).setUp()
        self.parsed_response = {'Body': six.StringIO()}
github aws / aws-cli / tests / unit / customizations / configure / test_list.py View on Github external
}
        credentials = mock.Mock()
        credentials.access_key = 'access_key'
        credentials.secret_key = 'secret_key'
        credentials.method = 'iam-role'
        session = FakeSession(
            all_variables={'config_file': '/config/location'},
            environment_vars=env_vars,
            config_file_vars=config_file_vars,
            credentials=credentials)
        session.session_var_map = {
            'region': ('region', 'AWS_REGION'),
            'profile': ('profile', 'AWS_DEFAULT_PROFILE')}
        session.full_config = {
            'profiles': {'default': {'region': 'AWS_REGION'}}}
        stream = six.StringIO()
        self.configure_list = ConfigureListCommand(session, stream)
        self.configure_list(args=[], parsed_globals=None)
        rendered = stream.getvalue()
        # The profile came from an env var.
        self.assertRegexpMatches(
            rendered, 'profile\s+myprofilename\s+env\s+AWS_DEFAULT_PROFILE')
        # The region came from the config file.
        self.assertRegexpMatches(
            rendered, 'region\s+us-west-2\s+config-file\s+/config/location')
        # The credentials came from an IAM role.  Note how we're
        # also checking that the access_key/secret_key are masked
        # with '*' chars except for the last 4 chars.
        self.assertRegexpMatches(
            rendered, r'access_key\s+\*+_key\s+iam-role')
        self.assertRegexpMatches(
            rendered, r'secret_key\s+\*+_key\s+iam-role')
github gkrizek / bash-lambda-layer / bin / awscli / testutils.py View on Github external
def capture_output():
    stderr = six.StringIO()
    stdout = six.StringIO()
    with mock.patch('sys.stderr', stderr):
        with mock.patch('sys.stdout', stdout):
            yield CapturedOutput(stdout, stderr)
github aws / aws-cli / tests / unit / output / test_table_formatter.py View on Github external
def setUp(self):
        styler = Styler()
        self.table = MultiTable(initial_section=False,
                                column_separator='|', styler=styler,
                                auto_reformat=False)
        self.formatter = TableFormatter(Object(color='off'))
        self.formatter.table = self.table
        self.stream = six.StringIO()
github aws / aws-cli / tests / unit / test_text.py View on Github external
def format_text(self, data, stream=None):
        if stream is None:
            stream = six.StringIO()
        text.format_text(data, stream=stream)
        return stream.getvalue()
github aws / aws-cli / awscli / utils.py View on Github external
def _split_with_quotes(value):
    try:
        parts = list(csv.reader(six.StringIO(value), escapechar='\\'))[0]
    except csv.Error:
        raise ValueError("Bad csv value: %s" % value)
    iter_parts = iter(parts)
    new_parts = []
    for part in iter_parts:
        # Find the first quote
        quote_char = _find_quote_char_in_part(part)

        # Find an opening list bracket
        list_start = part.find('=[')

        if list_start >= 0 and value.find(']') != -1 and \
           (quote_char is None or part.find(quote_char) > list_start):
            # This is a list, eat all the items until the end
            if ']' in part:
                # Short circuit for only one item