Skip to content

Commit 8c54875

Browse files
committed
execute scripts
1 parent 8c5dbf3 commit 8c54875

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

code/tests/test_code_in_scripts.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ def run_py(path):
1111
orig_dir = os.getcwd()
1212
os.chdir(py_dir)
1313

14+
with open(path, 'r') as f:
15+
content = f.read()
16+
17+
with open(path, 'w') as f:
18+
set_backend = "import matplotlib\nmatplotlib.use('Agg')\n"
19+
content = set_backend + content
20+
f.write(content)
21+
1422
args = ["python", py_path]
1523
subprocess.check_output(args)
1624

@@ -19,11 +27,6 @@ def run_py(path):
1927

2028
class TestOptionalScripts(unittest.TestCase):
2129

22-
def test_ch01(self):
23-
this_dir = os.path.dirname(os.path.abspath(__file__))
24-
run_py(os.path.join(this_dir,
25-
'../ch01/ch01.py'))
26-
2730
def test_ch02(self):
2831
this_dir = os.path.dirname(os.path.abspath(__file__))
2932
run_py(os.path.join(this_dir,
@@ -62,15 +65,6 @@ def test_ch08(self):
6265
run_py(os.path.join(this_dir,
6366
'../ch08/ch08.py'))
6467

65-
def test_ch09(self):
66-
this_dir = os.path.dirname(os.path.abspath(__file__))
67-
68-
# run only on Py3, because of the Py3 specific pickle files
69-
if (sys.version_info >= (3, 0)):
70-
run_py(os.path.join(this_dir, '../ch09/ch09.py'))
71-
else:
72-
pass
73-
7468
def test_ch10(self):
7569
this_dir = os.path.dirname(os.path.abspath(__file__))
7670
run_py(os.path.join(this_dir,

0 commit comments

Comments
 (0)