Merge branch 'lejenome-pythonoptimize-fix'
This commit is contained in:
commit
15b9e4d2bd
@ -235,6 +235,7 @@ Contributors, sorted by the number of commits in descending order:
|
||||
* Thiago Barroso Perrotta
|
||||
* Sorokin Alexei
|
||||
* Noah Huesser
|
||||
* Moez Bouhlel
|
||||
* Matthias Lisin
|
||||
* Marcel Schilling
|
||||
* Julie Engel
|
||||
|
@ -300,6 +300,11 @@ def init_log(args):
|
||||
log.init_log(args)
|
||||
log.init.debug("Log initialized.")
|
||||
|
||||
def check_optimize_flag():
|
||||
from qutebrowser.utils import log
|
||||
if sys.flags.optimize >= 2:
|
||||
log.init.warning("Running on optimize level higher than 1, "
|
||||
"unexpected behavior may occur.")
|
||||
|
||||
def earlyinit(args):
|
||||
"""Do all needed early initialization.
|
||||
@ -327,3 +332,4 @@ def earlyinit(args):
|
||||
remove_inputhook()
|
||||
check_libraries(args)
|
||||
check_ssl_support()
|
||||
check_optimize_flag()
|
||||
|
@ -26,7 +26,7 @@ import os.path
|
||||
import collections
|
||||
|
||||
import qutebrowser
|
||||
from qutebrowser.utils import usertypes
|
||||
from qutebrowser.utils import usertypes, log, utils
|
||||
|
||||
|
||||
def is_git_repo():
|
||||
@ -98,6 +98,15 @@ class DocstringParser:
|
||||
self.State.arg_inside: self._parse_arg_inside,
|
||||
self.State.misc: self._skip,
|
||||
}
|
||||
if doc is None:
|
||||
if sys.flags.optimize < 2:
|
||||
log.commands.warning(
|
||||
"Function {}() from {} has no docstring".format(
|
||||
utils.qualname(func),
|
||||
inspect.getsourcefile(func)))
|
||||
self.long_desc = ""
|
||||
self.short_desc = ""
|
||||
return
|
||||
for line in doc.splitlines():
|
||||
handler = handlers[self._state]
|
||||
stop = handler(line)
|
||||
|
@ -110,3 +110,16 @@ def test_no_loglines(quteproc_new):
|
||||
quteproc_new.start(args=['--temp-basedir', '--loglines=0'] + BASE_ARGS)
|
||||
quteproc_new.open_path('qute:log')
|
||||
assert quteproc_new.get_content() == 'Log output was disabled.'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('level', ['1', '2'])
|
||||
def test_optimize(quteproc_new, capfd, level):
|
||||
quteproc_new.start(args=['--temp-basedir'] + BASE_ARGS,
|
||||
env={'PYTHONOPTIMIZE': level})
|
||||
if level == '2':
|
||||
msg = ("Running on optimize level higher than 1, unexpected behavior "
|
||||
"may occur.")
|
||||
line = quteproc_new.wait_for(message=msg)
|
||||
line.expected = True
|
||||
quteproc_new.send_cmd(':quit')
|
||||
quteproc_new.wait_for_quit()
|
||||
|
@ -21,6 +21,10 @@
|
||||
|
||||
"""Tests for qutebrowser.commands.cmdutils."""
|
||||
|
||||
import sys
|
||||
import logging
|
||||
import types
|
||||
|
||||
import pytest
|
||||
|
||||
from qutebrowser.commands import cmdutils, cmdexc, argparser, command
|
||||
@ -354,6 +358,24 @@ class TestArgument:
|
||||
|
||||
assert str(excinfo.value) == "Argument marked as both count/win_id!"
|
||||
|
||||
def test_no_docstring(self, caplog):
|
||||
with caplog.at_level(logging.WARNING):
|
||||
@cmdutils.register()
|
||||
def fun():
|
||||
# no docstring
|
||||
pass
|
||||
assert len(caplog.records) == 1
|
||||
msg = caplog.records[0].message
|
||||
assert msg.endswith('test_cmdutils.py has no docstring')
|
||||
|
||||
def test_no_docstring_with_optimize(self, monkeypatch):
|
||||
"""With -OO we'd get a warning on start, but no warning afterwards."""
|
||||
monkeypatch.setattr(sys, 'flags', types.SimpleNamespace(optimize=2))
|
||||
@cmdutils.register()
|
||||
def fun():
|
||||
# no docstring
|
||||
pass
|
||||
|
||||
|
||||
class TestRun:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user