Skip to content

Commit

Permalink
start testing for Python 3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
loechel committed Oct 26, 2018
1 parent c055c52 commit c7323b1
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/RestrictedPython/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,18 +568,26 @@ def visit_Dict(self, node):
return self.node_contents_visit(node)

def visit_Ellipsis(self, node):
"""Deny using `...`.
"""Allow using `...`.
Ellipsis is exists only in Python 3.
"""
self.not_allowed(node)
return self.node_contents_visit(node)

def visit_NameConstant(self, node):
"""
"""
return self.node_contents_visit(node)

def visit_Constant(self, node):
"""
Constant replaces Num, Str, Byte, NameConstant and Ellipsis
:see: https://docs.python.org/dev/whatsnew/3.8.html#deprecated
"""
return self.node_contents_visit(node)

# ast for Variables

def visit_Name(self, node):
Expand Down
4 changes: 3 additions & 1 deletion tests/transformer/test_base_types.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from RestrictedPython import compile_restricted_eval
from RestrictedPython._compat import IS_PY2
from tests import c_exec
from tests import e_eval
Expand Down Expand Up @@ -29,4 +30,5 @@ def test_Set(e_eval):
def test_Ellipsis(c_exec):
"""It prevents using the `ellipsis` statement."""
result = c_exec('...')
assert result.errors == ('Line 1: Ellipsis statements are not allowed.',)
assert result.errors == ()
assert eval(compile_restricted_eval('...').code, {})
37 changes: 37 additions & 0 deletions tests/transformer/test_slice.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from operator import getitem
from RestrictedPython import compile_restricted_eval
from RestrictedPython import compile_restricted_exec
from RestrictedPython._compat import IS_PY2
from tests import e_eval

import pytest
Expand All @@ -21,3 +24,37 @@ def test_slice(e_eval):
assert e_eval('[1, 2, 3, 4, 5][%d::%d]' % (low, stride), rglb) == [2, 5]
assert e_eval('[1, 2, 3, 4, 5][:%d:%d]' % (high, stride), rglb) == [1, 4]
assert e_eval('[1, 2, 3, 4, 5][%d:%d:%d]' % (low, high, stride), rglb) == [2] # NOQA: E501


@pytest.mark.xfail
@pytest.mark.skipif(
IS_PY2,
reason="Ellipsis is Python 3 only."
)
def test_ellipsis_slice_01():
rglb = {'_getitem_': getitem} # restricted globals

assert eval(
compile_restricted_eval(
'[1, 2, 3, 4, 5, 6, 7] == [1, 2, 3, ... , 7]'
).code,
rglb
) is True


ELLIPSIS_EXAMPLE = """
def first_last(input_list):
first , ..., last = input_list
return (first, last)
"""


@pytest.mark.skipif(
IS_PY2,
reason="Ellipsis is Python 3 only."
)
def test_ellipsis_slice_02():
result = compile_restricted_exec(ELLIPSIS_EXAMPLE)
assert result.errors == ()
assert result.warnings == []
assert result.code is not None
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ envlist =
py36,
py36-datetime,
py37,
py38,
# pypy,
# pypy3,
docs,
Expand Down

0 comments on commit c7323b1

Please sign in to comment.