Skip to content

Commit e0befeb

Browse files
committed
Move local state setup function
1 parent 5d48d33 commit e0befeb

19 files changed

+40
-37
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ _, ctxt = prep_context()
3434
globals().update(ctxt)
3535

3636
# initialize state with student and solution submission
37-
from pythonwhat.local import setup_state
37+
from pythonwhat.test_exercise import setup_state
3838
setup_state(stu_code = "x = 5", sol_code = "x = 4")
3939

4040
Ex().check_object('x')
@@ -64,4 +64,4 @@ Bugs? Questions? Suggestions? [Create an issue](https://github.com/datacamp/pyth
6464

6565

6666
## License
67-
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fdatacamp%2Fpythonwhat.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fdatacamp%2Fpythonwhat?ref=badge_large)
67+
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fdatacamp%2Fpythonwhat.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fdatacamp%2Fpythonwhat?ref=badge_large)

pythonwhat/local.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import io
22
import random
33

4-
from pythonwhat.sct_syntax import Ex
5-
from pythonwhat.State import State
64
from pythonwhat.reporter import Reporter
75
from contextlib import redirect_stdout
86

@@ -26,23 +24,7 @@ def executeTask(self, task):
2624
return task(self.shell)
2725

2826

29-
def setup_state(stu_code="", sol_code="", pec="", pid=None):
30-
sol_process, stu_process, raw_stu_output, _ = run_exercise(
31-
pec, sol_code, stu_code, pid=pid
32-
)
3327

34-
state = State(
35-
student_code=stu_code,
36-
solution_code=sol_code,
37-
pre_exercise_code=pec,
38-
student_process=stu_process,
39-
solution_process=sol_process,
40-
raw_student_output=raw_stu_output,
41-
reporter=Reporter(),
42-
)
43-
44-
State.root_state = state
45-
return Ex(state)
4628

4729

4830
def run_exercise(pec, sol_code, stu_code, pid=None):

pythonwhat/test_exercise.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
from pythonwhat.State import State
2+
from pythonwhat.local import run_exercise
3+
from pythonwhat.sct_syntax import Ex
24
from pythonwhat.utils import check_str, check_process
35
from pythonwhat.reporter import Reporter
46
from protowhat.Test import TestFail
@@ -100,3 +102,22 @@ def prep_context():
100102

101103
cntxt.update(v2_check_functions)
102104
return tree, cntxt
105+
106+
107+
def setup_state(stu_code="", sol_code="", pec="", pid=None):
108+
sol_process, stu_process, raw_stu_output, _ = run_exercise(
109+
pec, sol_code, stu_code, pid=pid
110+
)
111+
112+
state = State(
113+
student_code=stu_code,
114+
solution_code=sol_code,
115+
pre_exercise_code=pec,
116+
student_process=stu_process,
117+
solution_process=sol_process,
118+
raw_student_output=raw_stu_output,
119+
reporter=Reporter(),
120+
)
121+
122+
State.root_state = state
123+
return Ex(state)

tests/test_author_warnings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import ast
33
import tests.helper as helper
44

5-
from pythonwhat.local import setup_state
5+
from pythonwhat.test_exercise import setup_state
66
from protowhat.Feedback import InstructorError
77
from inspect import signature, Signature, Parameter
88
from pythonwhat.checks.check_funcs import assert_ast

tests/test_check_class_def.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22
import tests.helper as helper
3-
from pythonwhat.local import setup_state
3+
from pythonwhat.test_exercise import setup_state
44
from pythonwhat.sct_syntax import v2_check_functions
55

66
globals().update(v2_check_functions)

tests/test_check_files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import tests.helper as helper
55
from protowhat.sct_syntax import F
66

7-
from pythonwhat.local import setup_state
7+
from pythonwhat.test_exercise import setup_state
88
from protowhat.checks import check_files as cf
99

1010

tests/test_check_function.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22
import tests.helper as helper
3-
from pythonwhat.local import setup_state
3+
from pythonwhat.test_exercise import setup_state
44
from protowhat.Test import TestFail as TF
55
from protowhat.Feedback import InstructorError
66
from pythonwhat.sct_syntax import v2_check_functions
@@ -80,7 +80,7 @@ def test_diff_function_types(fun, code, arg):
8080

8181

8282
def test_bind_args():
83-
from pythonwhat.local import setup_state
83+
from pythonwhat.test_exercise import setup_state
8484
from inspect import signature
8585
from pythonwhat.checks.check_function import bind_args
8686

tests/test_check_function_def.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22
import tests.helper as helper
33

4-
from pythonwhat.local import setup_state
4+
from pythonwhat.test_exercise import setup_state
55
from pythonwhat.sct_syntax import v2_check_functions
66

77
globals().update(v2_check_functions)

tests/test_check_list_comp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22
import tests.helper as helper
3-
from pythonwhat.local import setup_state
3+
from pythonwhat.test_exercise import setup_state
44
from pythonwhat.sct_syntax import v2_check_functions
55

66
globals().update(v2_check_functions)

tests/test_check_object.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22
import tests.helper as helper
3-
from pythonwhat.local import setup_state
3+
from pythonwhat.test_exercise import setup_state
44

55

66
@pytest.mark.parametrize(

tests/test_has_code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22
import tests.helper as helper
3-
from pythonwhat.local import setup_state
3+
from pythonwhat.test_exercise import setup_state
44

55

66
@pytest.mark.parametrize("stu, passes", [("", False), ("c", False), ("a == c", True)])

tests/test_has_expr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import pytest
2-
from pythonwhat.local import setup_state
2+
from pythonwhat.test_exercise import setup_state
33
from protowhat.Feedback import InstructorError
44
import tests.helper as helper
55

tests/test_has_import.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22
import tests.helper as helper
3-
from pythonwhat.local import setup_state
3+
from pythonwhat.test_exercise import setup_state
44

55

66
@pytest.mark.parametrize(

tests/test_has_output.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22
import tests.helper as helper
3-
from pythonwhat.local import setup_state
3+
from pythonwhat.test_exercise import setup_state
44

55

66
@pytest.mark.parametrize(

tests/test_has_printout.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import pytest
2-
from pythonwhat.local import setup_state
2+
from pythonwhat.test_exercise import setup_state
33
from protowhat.Test import TestFail as TF
44
import tests.helper as helper
55

tests/test_highlighting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22
import tests.helper as helper
3-
from pythonwhat.local import setup_state
3+
from pythonwhat.test_exercise import setup_state
44

55

66
def test_disable_highlighting():

tests/test_set_env.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22
import tests.helper as helper
3-
from pythonwhat.local import setup_state
3+
from pythonwhat.test_exercise import setup_state
44
from pythonwhat.sct_syntax import v2_check_functions
55

66
set_env = v2_check_functions["set_env"]

tests/test_signatures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pythonwhat.local import setup_state
1+
from pythonwhat.test_exercise import setup_state
22
import pytest
33

44
# https://docs.python.org/3.x/library/functions.html

tests/test_test_compound_statement.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22
import tests.helper as helper
3-
from pythonwhat.local import setup_state
3+
from pythonwhat.test_exercise import setup_state
44
from pythonwhat.sct_syntax import v2_check_functions
55

66
globals().update(v2_check_functions)

0 commit comments

Comments
 (0)