StreamedYAMLFormatter is tested above since it doesn't inherit from FullyBufferedFormatter, this is implicitly testing all other formatters that do.
(self, env_vars)
| 157 | ], |
| 158 | ) |
| 159 | def test_encoding_override(self, env_vars): |
| 160 | """ |
| 161 | StreamedYAMLFormatter is tested above since it doesn't inherit from |
| 162 | FullyBufferedFormatter, this is implicitly testing all other |
| 163 | formatters that do. |
| 164 | """ |
| 165 | response = {'TableNames': ['桌子']} |
| 166 | stdout_b = io.BytesIO() |
| 167 | stdout = io.TextIOWrapper(stdout_b, encoding="cp1252", newline='\n') |
| 168 | |
| 169 | with mock.patch.dict(os.environ, env_vars): |
| 170 | with contextlib.redirect_stdout(stdout): |
| 171 | assert 'cp1252' == sys.stdout.encoding |
| 172 | self.formatter('list-tables', response, sys.stdout) |
| 173 | # we expect the formatter to have changed the output stream |
| 174 | # encoding based on AWS_CLI_OUTPUT_ENCODING |
| 175 | assert 'UTF-8' == sys.stdout.encoding |
| 176 | stdout.flush() |
| 177 | |
| 178 | assert ( |
| 179 | stdout_b.getvalue() |
| 180 | == ( |
| 181 | '{\n' |
| 182 | ' "TableNames": [\n' |
| 183 | ' "桌子"\n' |
| 184 | ' ]\n' |
| 185 | '}\n' |
| 186 | ).encode() |
| 187 | ) |
| 188 | |
| 189 | |
| 190 | class TestOffFormatter: |