def test_pretty_options_with_and_without_stream_with_converter(pretty, stream): plugin_manager.register(SortJSONConverterPlugin) try: # Cover PluginManager.__repr__() assert 'SortJSONConverterPlugin' in str(plugin_manager) body = b'\x00{"foo":42,\n"bar":"baz"}' responses.add(responses.GET, DUMMY_URL, body=body, stream=True, content_type='json/bytes') args = ['--pretty=' + pretty, 'GET', DUMMY_URL] if stream: args.insert(0, '--stream') r = http(*args) assert 'json/bytes' in r if pretty == 'none': assert BINARY_SUPPRESSED_NOTICE.decode() in r else: # Ensure the plugin was effectively used and the resulting JSON is sorted assert '"bar": "baz",' in r assert '"foo": 42' in r finally: plugin_manager.unregister(SortJSONConverterPlugin)
def test_binary_suppresses_when_not_terminal_but_pretty(self, httpbin): env = MockEnvironment(stdin_isatty=True, stdout_isatty=False) r = http('--pretty=all', 'GET', httpbin + '/bytes/1024?seed=1', env=env) assert BINARY_SUPPRESSED_NOTICE.decode() in r
def test_encoded_stream(httpbin): """Test that --stream works with non-prettified redirected terminal output.""" with open(BIN_FILE_PATH, 'rb') as f: env = TestEnvironment(stdin=f, stdin_isatty=False) r = http('--pretty=none', '--stream', '--verbose', 'GET', httpbin.url + '/get', env=env) assert BINARY_SUPPRESSED_NOTICE.decode() in r
def test_encoded_stream(self): """Test that --stream works with non-prettified redirected terminal output.""" with open(BIN_FILE_PATH, 'rb') as f: env = TestEnvironment(stdin=f, stdin_isatty=False) r = http('--pretty=none', '--stream', '--verbose', 'GET', httpbin('/get'), env=env) assert BINARY_SUPPRESSED_NOTICE.decode() in r
def test_pretty_redirected_stream(self): """Test that --stream works with prettified redirected output.""" with open(BIN_FILE_PATH, 'rb') as f: env = TestEnvironment(colors=256, stdin=f, stdin_isatty=False, stdout_isatty=False) r = http('--verbose', '--pretty=all', '--stream', 'GET', httpbin('/get'), env=env) assert BINARY_SUPPRESSED_NOTICE.decode() in r
def test_pretty_redirected_stream(self, httpbin): """Test that --stream works with prettified redirected output.""" with open(BIN_FILE_PATH, 'rb') as f: env = TestEnvironment(colors=256, stdin=f, stdin_isatty=False, stdout_isatty=False) r = http('--verbose', '--pretty=all', '--stream', 'GET', httpbin.url + '/get', env=env) assert BINARY_SUPPRESSED_NOTICE.decode() in r
def test_encoded_stream(httpbin): """Test that --stream works with non-prettified redirected terminal output.""" env = MockEnvironment( stdin=StdinBytesIO(BIN_FILE_PATH.read_bytes()), stdin_isatty=False, ) r = http('--pretty=none', '--stream', '--verbose', 'GET', httpbin.url + '/get', env=env) assert BINARY_SUPPRESSED_NOTICE.decode() in r
def test_binary_suppresses_when_terminal(self, httpbin): r = http('GET', httpbin + '/bytes/1024') assert BINARY_SUPPRESSED_NOTICE.decode() in r
def test_binary_suppresses_when_not_terminal_but_pretty(self): env = TestEnvironment(stdin_isatty=True, stdout_isatty=False) r = http('--pretty=all', 'GET', self.url, env=env) assert BINARY_SUPPRESSED_NOTICE.decode() in r
def test_binary_suppresses_when_terminal(self): r = http('GET', self.url) assert BINARY_SUPPRESSED_NOTICE.decode() in r
def test_binary_suppresses_when_not_terminal_but_pretty(self): env = MockEnvironment(stdin_isatty=True, stdout_isatty=False) r = http('--pretty=all', 'GET', self.url, env=env) assert BINARY_SUPPRESSED_NOTICE.decode() in r