Skip to content

Commit 53662e9

Browse files
committed
TEST: copy files in TestWorkbook.test_links before modifying them
To avoid git considering them "modified" each time the test is run
1 parent 05fdb4c commit 53662e9

File tree

1 file changed

+30
-24
lines changed

1 file changed

+30
-24
lines changed

larray/tests/test_excel.py

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import re
22
import faulthandler
3+
import shutil
4+
import tempfile
35
from pathlib import Path
46

57
import pytest
@@ -56,30 +58,34 @@ def test_open_excel(self):
5658
wb['test'] = 'content'
5759

5860
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
8389

8490
def test_repr(self):
8591
with open_excel(visible=False) as wb:

0 commit comments

Comments
 (0)