|
9 | 9 | from matplotlib import pyplot as plt
|
10 | 10 |
|
11 | 11 |
|
12 |
| -def test_pyplot_up_to_date(): |
| 12 | +def test_pyplot_up_to_date(tmpdir): |
13 | 13 | gen_script = Path(mpl.__file__).parents[2] / "tools/boilerplate.py"
|
14 | 14 | if not gen_script.exists():
|
15 | 15 | pytest.skip("boilerplate.py not found")
|
16 | 16 | orig_contents = Path(plt.__file__).read_text()
|
17 |
| - try: |
18 |
| - subprocess.run([sys.executable, str(gen_script)], check=True) |
19 |
| - new_contents = Path(plt.__file__).read_text() |
20 |
| - |
21 |
| - if orig_contents != new_contents: |
22 |
| - diff_msg = '\n'.join( |
23 |
| - difflib.unified_diff( |
24 |
| - orig_contents.split('\n'), new_contents.split('\n'), |
25 |
| - fromfile='found pyplot.py', |
26 |
| - tofile='expected pyplot.py', |
27 |
| - n=0, lineterm='')) |
28 |
| - pytest.fail( |
29 |
| - "pyplot.py is not up-to-date. Please run " |
30 |
| - "'python tools/boilerplate.py' to update pyplot.py. " |
31 |
| - "This needs to be done from an environment where your " |
32 |
| - "current working copy is installed (e.g. 'pip install -e'd). " |
33 |
| - "Here is a diff of unex
8000
pected differences:\n%s" % diff_msg |
34 |
| - ) |
35 |
| - finally: |
36 |
| - Path(plt.__file__).write_text(orig_contents) |
| 17 | + plt_file = tmpdir.join('pyplot.py') |
| 18 | + plt_file.write_text(orig_contents, 'utf-8') |
| 19 | + |
| 20 | + subprocess.run([sys.executable, str(gen_script), str(plt_file)], |
| 21 | + check=True) |
| 22 | + new_contents = plt_file.read_text('utf-8') |
| 23 | + |
| 24 | + if orig_contents != new_contents: |
| 25 | + diff_msg = '\n'.join( |
| 26 | + difflib.unified_diff( |
| 27 | + orig_contents.split('\n'), new_contents.split('\n'), |
| 28 | + fromfile='found pyplot.py', |
| 29 | + tofile='expected pyplot.py', |
| 30 | + n=0, lineterm='')) |
| 31 | + pytest.fail( |
| 32 | + "pyplot.py is not up-to-date. Please run " |
| 33 | + "'python tools/boilerplate.py' to update pyplot.py. " |
| 34 | + "This needs to be done from an environment where your " |
| 35 | + "current working copy is installed (e.g. 'pip install -e'd). " |
| 36 | + "Here is a diff of unexpected differences:\n%s" % diff_msg |
| 37 | + ) |
37 | 38 |
|
38 | 39 |
|
39 | 40 | def test_pyplot_box():
|
|
0 commit comments