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