Skip to content

Commit 84a5015

Browse files
authored
include tests in installed package (#232)
This moves the tests to a sub-directory of RestrictedPython, so that they are installed along with the package. This also required adjusting the imports from within the tests (making them relative imports after adding necessary __init__.py ) and making the tests pass the linter (they were not linted before, because they were not part of src I guess). Some configuration that became unnecessary was also removed ( no need to include from tests in MANIFEST and no need to collect coverage from tests )
1 parent e445d19 commit 84a5015

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+80
-64
lines changed

.meta.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ testenv-setenv = [
2929
testenv-commands = [
3030
"python -V",
3131
"pip list",
32-
"pytest --cov=src --cov=tests --cov-report= {posargs}",
32+
"pytest --cov=src --cov-report= {posargs}",
3333
]
3434
testenv-additional = [
3535
"",
@@ -51,7 +51,7 @@ testenv-additional = [
5151
"depends = py36,py37,py38,py39,py39-datetime,py310,py311,coverage",
5252
]
5353
coverage-basepython = "python3.8"
54-
coverage-command = "pytest --cov=src --cov=tests --cov-report= {posargs}"
54+
coverage-command = "pytest --cov=src --cov-report= {posargs}"
5555
coverage-setenv = [
5656
"COVERAGE_FILE=.coverage",
5757
]
@@ -64,7 +64,6 @@ additional-rules = [
6464
"recursive-include docs *.ast",
6565
"recursive-include docs *.bat",
6666
"recursive-include docs *.jpg",
67-
"recursive-include tests *.py",
6867
]
6968

7069
[check-manifest]

MANIFEST.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,3 @@ recursive-include src *.py
1515
recursive-include docs *.ast
1616
recursive-include docs *.bat
1717
recursive-include docs *.jpg
18-
recursive-include tests *.py
File renamed without changes.

tests/builtins/test_limits.py renamed to src/RestrictedPython/tests/builtins/test_limits.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import pytest
2+
13
from RestrictedPython.Limits import limited_list
24
from RestrictedPython.Limits import limited_range
35
from RestrictedPython.Limits import limited_tuple
46

5-
import pytest
6-
77

88
def test_limited_range_length_1():
99
result = limited_range(1)

tests/helper.py renamed to src/RestrictedPython/tests/helper.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
import RestrictedPython.Guards
12
from RestrictedPython import compile_restricted_eval
23
from RestrictedPython import compile_restricted_exec
34

4-
import RestrictedPython.Guards
5-
65

76
def _compile(compile_func, source):
87
"""Compile some source with a compile func."""

tests/test_Guards.py renamed to src/RestrictedPython/tests/test_Guards.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
import pytest
2+
13
from RestrictedPython import compile_restricted_exec
24
from RestrictedPython.Guards import guarded_unpack_sequence
35
from RestrictedPython.Guards import safe_builtins
46
from RestrictedPython.Guards import safe_globals
57
from RestrictedPython.Guards import safer_getattr
6-
from tests.helper import restricted_eval
7-
from tests.helper import restricted_exec
88

9-
import pytest
9+
from .helper import restricted_eval
10+
from .helper import restricted_exec
1011

1112

1213
def _write_(x):

tests/test_NamedExpr.py renamed to src/RestrictedPython/tests/test_NamedExpr.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33

44
from ast import NodeTransformer
55
from ast import parse
6+
from unittest import TestCase
7+
from unittest import skipUnless
8+
69
from RestrictedPython import compile_restricted
710
from RestrictedPython import safe_globals
811
from RestrictedPython._compat import IS_PY38_OR_GREATER
9-
from unittest import skipUnless
10-
from unittest import TestCase
1112

1213

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

tests/test_compile.py renamed to src/RestrictedPython/tests/test_compile.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1+
import platform
2+
import types
3+
4+
import pytest
5+
6+
from RestrictedPython import CompileResult
17
from RestrictedPython import compile_restricted
28
from RestrictedPython import compile_restricted_eval
39
from RestrictedPython import compile_restricted_exec
410
from RestrictedPython import compile_restricted_single
5-
from RestrictedPython import CompileResult
611
from RestrictedPython._compat import IS_PY38_OR_GREATER
712
from RestrictedPython._compat import IS_PY310_OR_GREATER
8-
from tests.helper import restricted_eval
913

10-
import platform
11-
import pytest
12-
import types
14+
from .helper import restricted_eval
1315

1416

1517
def test_compile__compile_restricted_invalid_code_input():

0 commit comments

Comments
 (0)