Skip to content

Commit

Permalink
New option: --report-level
Browse files Browse the repository at this point in the history
Change default report level to 2; make --strict imply halt level 2 as
well.

Fixes #49.
  • Loading branch information
mgedmin committed Dec 7, 2017
1 parent 8085689 commit 704714c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
8 changes: 7 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
Changelog
=========

2.7.1 (unreleased)
2.8.0 (unreleased)
------------------

- Claim Python 3.6 support.

- Drop Python 3.3 support.

- New option ``--report-level`` that defaults to 2 (previously this was
hardcoded to 0). See `#49 <https://github.com/mgedmin/restview/issues/49>`_.

- Relax ``--strict`` to mean ``--halt-level=2`` (previously it meant
``--halt-level=1``). See `#49`_.


2.7.0 (2016-09-15)
------------------
Expand Down
25 changes: 14 additions & 11 deletions src/restview/restviewhttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,8 @@ class RestViewer(object):

favicon_path = os.path.join(DATA_PATH, 'favicon.ico')

report_level = None
halt_level = None
strict = False
pypi_strict = False

def __init__(self, root, command=None, watch=None):
Expand Down Expand Up @@ -471,12 +471,10 @@ def rest_to_html(self, rest_input, settings=None, mtime=None, filename=None):
settings_overrides.update(readme_rst.SETTINGS)
if self.halt_level is not None:
settings_overrides['halt_level'] = self.halt_level
elif self.strict:
settings_overrides['halt_level'] = 1
if self.report_level is not None:
settings_overrides['report_level'] = self.report_level

settings_overrides['report_level'] = 0

if settings:
if settings: # hook for unit tests
settings_overrides.update(settings)

try:
Expand Down Expand Up @@ -712,6 +710,12 @@ def main():
' multiple times [default: %s]'
% RestViewer.stylesheets,
action='append', dest='stylesheets', default=[])
parser.add_argument(
'--report-level',
help='''set the "report_level" option of docutils; restview
will report system messages at or above this level (1=info,
2=warnings, 3=errors, 4=severe)''',
type=int, default=2)
halt_level_group = parser.add_mutually_exclusive_group()
halt_level_group.add_argument(
'--halt-level',
Expand All @@ -722,12 +726,11 @@ def main():
type=int, default=None)
halt_level_group.add_argument(
'--strict',
help='halt at the slightest problem; equivalent to --halt-level=1',
action='store_true', default=False)
help='halt at the slightest problem; equivalent to --halt-level=2',
action='store_const', dest='halt_level', const=2)
parser.add_argument(
'--pypi-strict',
help='enable additional restrictions that PyPI performs;'
' implies --strict',
help='enable additional restrictions that PyPI performs',
action='store_true', default=False)
opts = parser.parse_args(sys.argv[1:])
args = opts.root
Expand All @@ -749,8 +752,8 @@ def main():
server = RestViewer(args, watch=opts.watch)
if opts.stylesheets:
server.stylesheets = ','.join(opts.stylesheets)
server.report_level = opts.report_level
server.halt_level = opts.halt_level
server.strict = opts.strict
server.pypi_strict = opts.pypi_strict

if opts.listen:
Expand Down
8 changes: 7 additions & 1 deletion src/restview/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ def doctest_RestViewer_rest_to_html_strict_and_error_handling():
>>> viewer = RestViewer('.')
>>> viewer.stylesheets = None
>>> viewer.strict = True
>>> viewer.halt_level = 2
>>> print(viewer.rest_to_html(b'''
... Some text with an `error
... ''', mtime=1364808683).strip())
Expand Down Expand Up @@ -800,6 +800,12 @@ def test_rest_to_html_halt_level(self):
html = viewer.rest_to_html(b'`Hello')
self.assertIn('<title>SystemMessage</title>', html)

def test_rest_to_html_report_level(self):
viewer = RestViewer('.')
viewer.report_level = 1
html = viewer.rest_to_html(b'.. _unused:\n\nEtc.')
self.assertIn('System Message: INFO/1', html)

def make_error(self, msg, source='file.rst', line=None,
level=docutils.utils.Reporter.ERROR_LEVEL):
sm = docutils.nodes.system_message(
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ deps =
coverage
commands =
coverage run --source=src/restview -m py.test
coverage report
coverage report -m --fail-under=100

0 comments on commit 704714c

Please sign in to comment.