Skip to content

Commit

Permalink
Test the two README.rst files, too, using pytest.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Howitz committed Sep 13, 2017
1 parent ea52341 commit 6d67d7d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ test = pytest
[tool:pytest]
addopts =
testpaths =
.
tests
src/RestrictedPython/tests

Expand Down
11 changes: 6 additions & 5 deletions src/RestrictedPython/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ controlled and restricted execution of code:
... def hello_world():
... return "Hello World!"
... '''
>>> from RestrictedPython.RCompile import compile_restricted
>>> from RestrictedPython import compile_restricted
>>> code = compile_restricted(src, '<string>', 'exec')

The resulting code can be executed using the ``exec`` built-in:
Expand Down Expand Up @@ -99,9 +99,10 @@ callable, from which the restricted machinery will create the object):

>>> from RestrictedPython.PrintCollector import PrintCollector
>>> _print_ = PrintCollector
>>> _getattr_ = getattr

>>> src = '''
... print "Hello World!"
... print("Hello World!")
... '''
>>> code = compile_restricted(src, '<string>', 'exec')
>>> exec(code)
Expand All @@ -111,7 +112,7 @@ collector collects it. We can have access to the text using the
``printed`` variable, though:

>>> src = '''
... print "Hello World!"
... print("Hello World!")
... result = printed
... '''
>>> code = compile_restricted(src, '<string>', 'exec')
Expand All @@ -133,7 +134,7 @@ unsafe operations, such as opening files:
... open('/etc/passwd')
... '''
>>> code = compile_restricted(src, '<string>', 'exec')
>>> exec(code) in restricted_globals
>>> exec(code, restricted_globals)
Traceback (most recent call last):
...
NameError: name 'open' is not defined
Expand All @@ -158,7 +159,7 @@ Normally accessing attriutes works as expected, because we're using
the standard ``getattr`` function for the ``_getattr_`` guard:

>>> src = '''
... print shed.colour
... print(shed.colour)
... result = printed
... '''
>>> code = compile_restricted(src, '<string>', 'exec')
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extras =
test

commands =
pytest --cov=src --cov-report=xml --html=reports/pytest/report-{envname}.html --self-contained-html {posargs}
pytest --cov=src --cov-report=xml --html=reports/pytest/report-{envname}.html --doctest-glob=*.rst --self-contained-html {posargs}
pytest --doctest-modules src/RestrictedPython/compile.py {posargs}

setenv =
Expand Down

0 comments on commit 6d67d7d

Please sign in to comment.