Skip to content

Commit

Permalink
use version detection support from _compat;
Browse files Browse the repository at this point in the history
get rid of `util`
  • Loading branch information
d-maurer committed May 9, 2020
1 parent 7ac0481 commit 6da63e4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 29 deletions.
22 changes: 19 additions & 3 deletions src/RestrictedPython/tests/test_NamedExpr.py
@@ -1,15 +1,17 @@
"""Assignment expression (``NamedExpr``) tests."""


from .util import check_version
from .util import compile_str
from ast import NodeTransformer
from ast import parse
from unittest import skipUnless
from unittest import TestCase

from RestrictedPython._compat import IS_PY38_OR_GREATER
from RestrictedPython import compile_restricted
from RestrictedPython import safe_globals

@skipUnless(check_version("3.8"), "Feature available for Python 3.8+")

@skipUnless(IS_PY38_OR_GREATER, "Feature available for Python 3.8+")
class TestNamedExpr(TestCase):
def test_works(self):
code, gs = compile_str("if x:= x + 1: True\n")
Expand Down Expand Up @@ -39,3 +41,17 @@ def visit_NamedExpr(self, node):
SyntaxError,
"Assignment expressions are only allowed for simple target"):
code, gs = compile_str(mod)


def compile_str(s, name="<unknown>"):
"""code and globals for *s*.
*s* must be acceptable for ``compile_restricted`` (this is (especially) the
case for an ``str`` or ``ast.Module``).
*name* is a ``str`` used in error messages.
"""
code = compile_restricted(s, name, 'exec')
gs = safe_globals.copy()
gs["__debug__"] = True # assert active
return code, gs
26 changes: 0 additions & 26 deletions src/RestrictedPython/tests/util.py

This file was deleted.

0 comments on commit 6da63e4

Please sign in to comment.