Merge remote-tracking branch 'origin/pr/3313'

This commit is contained in:
Florian Bruhin 2017-11-19 21:09:19 +01:00
commit a2c549b954
3 changed files with 36 additions and 6 deletions

View File

@ -229,18 +229,33 @@ def debug_trace(expr=""):
@cmdutils.register(maxsplit=0, debug=True, no_cmd_split=True) @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. """Evaluate a python string and display the results as a web page.
Args: Args:
s: The string to evaluate. 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. quiet: Don't show the output in a new tab.
""" """
try: if file:
r = eval(s) quiet = True
out = repr(r) path = os.path.expanduser(s)
except Exception: try:
out = traceback.format_exc() 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 qutescheme.pyeval_output = out
if quiet: if quiet:

View 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")

View File

@ -171,6 +171,15 @@ Feature: Special qute:// pages
And I wait until qute://pyeval/ is loaded And I wait until qute://pyeval/ is loaded
Then the page should contain the plaintext "ZeroDivisionError" 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 Scenario: Running :pyeval with --quiet
When I run :debug-pyeval --quiet 1+1 When I run :debug-pyeval --quiet 1+1
Then "pyeval output: 2" should be logged Then "pyeval output: 2" should be logged