|
1 | 1 | import re
|
2 | 2 | import faulthandler
|
| 3 | +import shutil |
| 4 | +import tempfile |
3 | 5 | from pathlib import Path
|
4 | 6 |
|
5 | 7 | import pytest
|
@@ -56,30 +58,34 @@ def test_open_excel(self):
|
56 | 58 | wb['test'] = 'content'
|
57 | 59 |
|
58 | 60 | def test_links(self):
|
59 |
| - data_dir = TEST_DATA_PATH / 'excel_with_links' |
60 |
| - fpath1 = data_dir / 'BookA.xlsx' |
61 |
| - fpath2 = data_dir / 'BookB.xlsx' |
62 |
| - fpath3 = data_dir / 'BookC.xlsx' |
63 |
| - assert read_excel(fpath1)['link to cell with link to other workbook', 'value from link'] == 4 |
64 |
| - assert read_excel(fpath2)['cell with link to other workbook', 'formula value'] == 4 |
65 |
| - assert read_excel(fpath3).i[0, 0] == 3 |
66 |
| - |
67 |
| - with open_excel(fpath1) as a, open_excel(fpath2) as b, open_excel(fpath3) as c: |
68 |
| - c[0]['B2'] = 41 |
69 |
| - a.save() |
70 |
| - b.save() |
71 |
| - c.save() |
72 |
| - assert read_excel(fpath1)['link to cell with link to other workbook', 'value from link'] == 42 |
73 |
| - assert read_excel(fpath2)['cell with link to other workbook', 'formula value'] == 42 |
74 |
| - assert read_excel(fpath3).i[0, 0] == 41 |
75 |
| - with open_excel(fpath1) as a, open_excel(fpath2) as b, open_excel(fpath3) as c: |
76 |
| - c[0]['B2'] = 3 |
77 |
| - a.save() |
78 |
| - b.save() |
79 |
| - c.save() |
80 |
| - assert read_excel(fpath1)['link to cell with link to other workbook', 'value from link'] == 4 |
81 |
| - assert read_excel(fpath2)['cell with link to other workbook', 'formula value'] == 4 |
82 |
| - assert read_excel(fpath3).i[0, 0] == 3 |
| 61 | + test_data_dir = TEST_DATA_PATH / 'excel_with_links' |
| 62 | + with tempfile.TemporaryDirectory() as tmp_dir_name: |
| 63 | + tmp_dir = Path(tmp_dir_name) |
| 64 | + for book in ('BookA.xlsx', 'BookB.xlsx', 'BookC.xlsx'): |
| 65 | + shutil.copy2(test_data_dir / book, tmp_dir) |
| 66 | + fpath1 = tmp_dir / 'BookA.xlsx' |
| 67 | + fpath2 = tmp_dir / 'BookB.xlsx' |
| 68 | + fpath3 = tmp_dir / 'BookC.xlsx' |
| 69 | + assert read_excel(fpath1)['link to cell with link to other workbook', 'value from link'] == 4 |
| 70 | + assert read_excel(fpath2)['cell with link to other workbook', 'formula value'] == 4 |
| 71 | + assert read_excel(fpath3).i[0, 0] == 3 |
| 72 | + |
| 73 | + with open_excel(fpath1) as a, open_excel(fpath2) as b, open_excel(fpath3) as c: |
| 74 | + c[0]['B2'] = 41 |
| 75 | + a.save() |
| 76 | + b.save() |
| 77 | + c.save() |
| 78 | + assert read_excel(fpath1)['link to cell with link to other workbook', 'value from link'] == 42 |
| 79 | + assert read_excel(fpath2)['cell with link to other workbook', 'formula value'] == 42 |
| 80 | + assert read_excel(fpath3).i[0, 0] == 41 |
| 81 | + with open_excel(fpath1) as a, open_excel(fpath2) as b, open_excel(fpath3) as c: |
| 82 | + c[0]['B2'] = 3 |
| 83 | + a.save() |
| 84 | + b.save() |
| 85 | + c.save() |
| 86 | + assert read_excel(fpath1)['link to cell with link to other workbook', 'value from link'] == 4 |
| 87 | + assert read_excel(fpath2)['cell with link to other workbook', 'formula value'] == 4 |
| 88 | + assert read_excel(fpath3).i[0, 0] == 3 |
83 | 89 |
|
84 | 90 | def test_repr(self):
|
85 | 91 | with open_excel(visible=False) as wb:
|
|
0 commit comments