mirror of
https://github.com/httpie/cli.git
synced 2024-11-22 07:43:20 +01:00
Aesthetic changes
This commit is contained in:
parent
7e38f9ccf0
commit
69e1067a2c
@ -112,14 +112,12 @@ class Environment:
|
||||
self.log_error(e, level='warning')
|
||||
return config
|
||||
|
||||
|
||||
@property
|
||||
def devnull(self) -> IO:
|
||||
if self._devnull is None:
|
||||
self._devnull = open(os.devnull, 'w+')
|
||||
return self._devnull
|
||||
|
||||
#For ease of testing
|
||||
@devnull.setter
|
||||
def devnull(self, value):
|
||||
self._devnull = value
|
||||
|
@ -199,4 +199,3 @@ class TestDownloads:
|
||||
assert r.stderr == ''
|
||||
assert env.devnull == env.stderr
|
||||
assert env.devnull == env.stdout
|
||||
|
||||
|
@ -54,18 +54,18 @@ class TestQuietFlag:
|
||||
assert env.stdout == env.devnull
|
||||
assert env.stderr == env.devnull
|
||||
assert r.stderr == ''
|
||||
assert HTTP_OK in r.devnull.decode()
|
||||
assert HTTP_OK in r.devnull
|
||||
assert str(r) == ''
|
||||
|
||||
@mock.patch('httpie.cli.argtypes.AuthCredentials._getpass',
|
||||
new=lambda self, prompt:'password')
|
||||
new=lambda self, prompt: 'password')
|
||||
def test_quiet_password_prompt(self, httpbin):
|
||||
""" Tests whether httpie still prompts for password when request
|
||||
requires authetication and only username is provided"""
|
||||
env = MockEnvironment(stdin_isatty=True, stdout_isatty=True)
|
||||
env.devnull = io.BytesIO()
|
||||
r = http('--quiet', '--auth', 'user','GET', httpbin.url + '/basic-auth/user/password', env=env)
|
||||
assert HTTP_OK in r.devnull.decode()
|
||||
r = http('--quiet', '--auth', 'user', 'GET', httpbin.url + '/basic-auth/user/password', env=env)
|
||||
assert HTTP_OK in r.devnull
|
||||
assert env.stdout == env.devnull
|
||||
assert env.stderr == env.devnull
|
||||
assert str(r) == ''
|
||||
@ -80,6 +80,7 @@ class TestQuietFlag:
|
||||
assert str(r) == ''
|
||||
assert r.stderr == ''
|
||||
|
||||
|
||||
class TestVerboseFlag:
|
||||
def test_verbose(self, httpbin):
|
||||
r = http('--verbose',
|
||||
|
@ -163,20 +163,21 @@ def http(
|
||||
# noinspection PyUnresolvedReferences
|
||||
"""
|
||||
Run HTTPie and capture stderr/out and exit status.
|
||||
Content writtent to devnull will be captured if
|
||||
env.devnull in env does not correspond to os.devnull file.
|
||||
Content writtent to devnull will be captured only if
|
||||
env.devnull is set manually.
|
||||
|
||||
Invoke `httpie.core.main()` with `args` and `kwargs`,
|
||||
and return a `CLIResponse` subclass instance.
|
||||
|
||||
The return value is either a `StrCLIResponse`, or `BytesCLIResponse`
|
||||
if unable to decode the output.
|
||||
if unable to decode the output. Devnull is string when possible,
|
||||
bytes otherwise.
|
||||
|
||||
The response has the following attributes:
|
||||
|
||||
`stdout` is represented by the instance itself (print r)
|
||||
`stderr`: text written to stderr
|
||||
`devnull` text written to devnull. String if possible bytes otherwise
|
||||
`devnull` text written to devnull.
|
||||
`exit_status`: the exit status
|
||||
`json`: decoded JSON (if possible) or `None`
|
||||
|
||||
@ -265,6 +266,10 @@ def http(
|
||||
else:
|
||||
r = StrCLIResponse(output)
|
||||
|
||||
try:
|
||||
devnull_output = devnull_output.decode('utf8')
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
r.devnull = devnull_output
|
||||
r.stderr = stderr.read()
|
||||
|
Loading…
Reference in New Issue
Block a user