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