Skip to content

Commit

Permalink
Merge pull request #39 from zopefoundation/compile_tests
Browse files Browse the repository at this point in the history
Compile tests of invalid options
  • Loading branch information
loechel committed Mar 3, 2017
2 parents 0bfa2e2 + 0ba212f commit 70eca19
Show file tree
Hide file tree
Showing 15 changed files with 132 additions and 191 deletions.
5 changes: 5 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
[run]
branch = True
source = RestrictedPython
omit =
src/RestrictedPython/tests
src/RestrictedPython/tests/*.py
tests/*.py
bootstrap.py

[report]
precision = 3
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pip-selfcheck.json
pyvenv.cfg
/.python-version
/*.egg-info
/.eggs/
/.Python
/.cache
/.installed.cfg
Expand All @@ -20,6 +21,7 @@ pyvenv.cfg
/eggs
/fake-eggs
/htmlcov
/report-*.html
/include
/lib
/share
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

# General information about the project.
project = u'RestrictedPython'
copyright = u'2016, Zope Foundation'
copyright = u'2017, Zope Foundation and Contributors'
author = u'Alexander Loechel'

# The version info for the project you're documenting, acts as replacement for
Expand Down
7 changes: 0 additions & 7 deletions pytest.ini

This file was deleted.

16 changes: 16 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,31 @@ upload-dir = docs/html
ignore =
.travis.yml
bootstrap-buildout.py
bootstrap.py
buildout.cfg
jenkins.cfg
travis.cfg

[aliases]
test = pytest

[tool:pytest]
addopts =
testpaths =
tests
src/RestrictedPython/tests
norecursedirs = fixures

isort_ignore =
bootstrap.py


[isort]
force_alphabetical_sort = True
force_single_line = True
lines_after_imports = 2
line_length = 200
skip = bootstrap.py
not_skip = __init__.py

[flake8]
Expand Down
10 changes: 7 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ def read(*rnames):
package_dir={'': 'src'},
install_requires=[
'setuptools',

],
setup_requires=[
'pytest-runner',
],
test_requires=[
'pytest',
],
extras_require={
'docs': [
Expand All @@ -57,9 +64,6 @@ def read(*rnames):
'release': [
'zest.releaser',
],
'test': [
'pytest',
],
'develop': [
'pdbpp',
'isort',
Expand Down
19 changes: 6 additions & 13 deletions src/RestrictedPython/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,11 @@ def compile_restricted_single(


def compile_restricted_function(
source,
p,
body,
name,
filename='<string>',
flags=0,
dont_inherit=0,
globalize=None,
policy=RestrictingNodeTransformer):
"""Compile a restricted code object for a function.
Expand All @@ -121,17 +122,9 @@ def compile_restricted_function(
The globalize argument, if specified, is a list of variable names to be
treated as globals (code is generated as if each name in the list
appeared in a global statement at the top of the function).
TODO: Special function not comparable with the other restricted_compile_*
functions.
"""
return _compile_restricted_mode(
source,
filename=filename,
mode='function',
flags=flags,
dont_inherit=dont_inherit,
policy=policy)
# TODO: Special function not comparable with the other restricted_compile_* functions. # NOQA
return None


def compile_restricted(
Expand Down
153 changes: 0 additions & 153 deletions src/RestrictedPython/tests/testUtiliities.py

This file was deleted.

11 changes: 7 additions & 4 deletions src/RestrictedPython/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,9 +627,12 @@ def visit_Expr(self, node):

def visit_UnaryOp(self, node):
"""
UnaryOp (Unary Operations) is the overall element for:
* Not --> which should be allowed
* UAdd
* USub
"""
self.not_allowed(node)
return self.node_contents_visit(node)

def visit_UAdd(self, node):
"""
Expand All @@ -645,9 +648,9 @@ def visit_USub(self, node):

def visit_Not(self, node):
"""
The Not Operator should be allowed.
"""
self.not_allowed(node)
return self.node_contents_visit(node)

def visit_Invert(self, node):
"""
Expand Down
72 changes: 72 additions & 0 deletions tests/builtins/test_limits.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
from RestrictedPython.Limits import _limited_list
from RestrictedPython.Limits import _limited_range
from RestrictedPython.Limits import _limited_tuple

import pytest


def test__limited_range_length_1():
result = _limited_range(1)
assert result == range(0, 1)


def test__limited_range_length_10():
result = _limited_range(10)
assert result == range(0, 10)


def test__limited_range_5_10():
result = _limited_range(5, 10)
assert result == range(5, 10)


def test__limited_range_5_10_sm1():
result = _limited_range(5, 10, -1)
assert result == range(5, 10, -1)


def test__limited_range_15_10_s2():
result = _limited_range(15, 10, 2)
assert result == range(15, 10, 2)


def test__limited_range_no_input():
with pytest.raises(TypeError):
_limited_range()


def test__limited_range_more_steps():
with pytest.raises(AttributeError):
_limited_range(0, 0, 0, 0)


def test__limited_range_zero_step():
with pytest.raises(ValueError):
_limited_range(0, 10, 0)


def test__limited_range_range_overflow():
with pytest.raises(ValueError):
_limited_range(0, 5000, 1)


def test__limited_list_valid_list_input():
input = [1, 2, 3]
result = _limited_list(input)
assert result == input


def test__limited_list_invalid_string_input():
with pytest.raises(TypeError):
_limited_list('input')


def test__limited_tuple_valid_list_input():
input = [1, 2, 3]
result = _limited_tuple(input)
assert result == tuple(input)


def test__limited_tuple_invalid_string_input():
with pytest.raises(TypeError):
_limited_tuple('input')
File renamed without changes.
Loading

0 comments on commit 70eca19

Please sign in to comment.