File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 1
1
from RestrictedPython import compile_restricted_exec
2
2
from RestrictedPython ._compat import IS_PY36_OR_GREATER
3
+ from RestrictedPython ._compat import IS_PY38_OR_GREATER
4
+ from RestrictedPython .PrintCollector import PrintCollector
3
5
4
6
import pytest
5
7
@@ -33,3 +35,28 @@ def test_visit_invalid_variable_name():
33
35
assert result .errors == (
34
36
'Line 1: "__init__" is an invalid variable name because it starts with "_"' , # NOQA: E501
35
37
)
38
+
39
+
40
+ f_string_self_documenting_expressions_example = """
41
+ from datetime import date
42
+
43
+ user = 'eric_idle'
44
+ member_since = date(1975, 7, 31)
45
+ print(f'{user=} {member_since=}')
46
+ """
47
+
48
+
49
+ @pytest .mark .skipif (
50
+ not IS_PY38_OR_GREATER ,
51
+ reason = "f-string self-documenting expressions added in Python 3.8." ,
52
+ )
53
+ def test_f_string_self_documenting_expressions ():
54
+ """Checks if f-string self-documenting expressions is checked."""
55
+ result = compile_restricted_exec (
56
+ f_string_self_documenting_expressions_example ,
57
+ )
58
+ assert result .errors == ()
59
+
60
+ glb = {'_print_' : PrintCollector , '_getattr_' : None }
61
+ exec (result .code , glb )
62
+ assert glb ['_print' ]() == "user='eric_idle' member_since=datetime.date(1975, 7, 31)\n " # NOQA: E501
You can’t perform that action at this time.
0 commit comments