MCPcopy Index your code
hub / github.com/datacamp/pythonwhat / test_running_file

Function test_running_file

tests/test_check_files.py:98–132  ·  view source on GitHub ↗
(temp_py_file)

Source from the content-addressed store, hash-verified

96
97
98def test_running_file(temp_py_file):
99 content = cf.get_file_content(temp_py_file.name)
100 chain = setup_state("", "", pec="")
101
102 with tempfile.TemporaryDirectory() as d:
103 with ChDir(d):
104 chain.check_file(
105 temp_py_file.name, solution_code=content
106 ).run().has_equal_value(expr_code="a")
107
108 with tempfile.TemporaryDirectory() as d:
109 with ChDir(d):
110 chain.check_file(
111 temp_py_file.name, solution_code=content
112 ).run().check_object("a").has_equal_value()
113
114 with pytest.raises(TF):
115 with tempfile.TemporaryDirectory() as d:
116 with ChDir(d):
117 chain.check_file(
118 temp_py_file.name, solution_code=content.replace("1", "2")
119 ).run().has_equal_value(expr_code="a")
120
121 with tempfile.TemporaryDirectory() as d:
122 with ChDir(d):
123 chain.check_file(temp_py_file.name).run().has_equal_value(
124 expr_code="a", override=1
125 )
126
127 with pytest.raises(TF):
128 with tempfile.TemporaryDirectory() as d:
129 with ChDir(d):
130 chain.check_file(temp_py_file.name).run().has_equal_value(
131 expr_code="a", override=2
132 )
133
134
135def test_running_file_with_root_check(temp_py_file):

Callers

nothing calls this directly

Calls 3

setup_stateFunction · 0.90
ChDirClass · 0.90
runMethod · 0.80

Tested by

no test coverage detected