Merge remote-tracking branch 'origin/pr/3313'
This commit is contained in:
commit
a2c549b954
@ -229,18 +229,33 @@ def debug_trace(expr=""):
|
||||
|
||||
|
||||
@cmdutils.register(maxsplit=0, debug=True, no_cmd_split=True)
|
||||
def debug_pyeval(s, quiet=False):
|
||||
def debug_pyeval(s, file=False, quiet=False):
|
||||
"""Evaluate a python string and display the results as a web page.
|
||||
|
||||
Args:
|
||||
s: The string to evaluate.
|
||||
file: Interpret s as a path to file, also implies --quiet.
|
||||
quiet: Don't show the output in a new tab.
|
||||
"""
|
||||
try:
|
||||
r = eval(s)
|
||||
out = repr(r)
|
||||
except Exception:
|
||||
out = traceback.format_exc()
|
||||
if file:
|
||||
quiet = True
|
||||
path = os.path.expanduser(s)
|
||||
try:
|
||||
with open(path, 'r', encoding='utf-8') as f:
|
||||
s = f.read()
|
||||
except OSError as e:
|
||||
raise cmdexc.CommandError(str(e))
|
||||
try:
|
||||
exec(s)
|
||||
out = "No error"
|
||||
except Exception:
|
||||
out = traceback.format_exc()
|
||||
else:
|
||||
try:
|
||||
r = eval(s)
|
||||
out = repr(r)
|
||||
except Exception:
|
||||
out = traceback.format_exc()
|
||||
|
||||
qutescheme.pyeval_output = out
|
||||
if quiet:
|
||||
|
6
tests/end2end/data/misc/pyeval_file.py
Normal file
6
tests/end2end/data/misc/pyeval_file.py
Normal file
@ -0,0 +1,6 @@
|
||||
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
||||
|
||||
"""Simple test file for :debug-pyeval."""
|
||||
|
||||
from qutebrowser.utils import message
|
||||
message.info("Hello World")
|
@ -171,6 +171,15 @@ Feature: Special qute:// pages
|
||||
And I wait until qute://pyeval/ is loaded
|
||||
Then the page should contain the plaintext "ZeroDivisionError"
|
||||
|
||||
Scenario: Running :pyveal with --file using a file that exists as python code
|
||||
When I run :debug-pyeval --file (testdata)/misc/pyeval_file.py
|
||||
Then the message "Hello World" should be shown
|
||||
And "pyeval output: No error" should be logged
|
||||
|
||||
Scenario: Running :pyeval --file using a non existing file
|
||||
When I run :debug-pyeval --file nonexistentfile
|
||||
Then the error "[Errno 2] No such file or directory: 'nonexistentfile'" should be shown
|
||||
|
||||
Scenario: Running :pyeval with --quiet
|
||||
When I run :debug-pyeval --quiet 1+1
|
||||
Then "pyeval output: 2" should be logged
|
||||
|
Loading…
Reference in New Issue
Block a user