Skip to content

Commit ad867ed

Browse files
committed
Make test filenames unique
1 parent e81f39e commit ad867ed

1 file changed

Lines changed: 45 additions & 31 deletions

File tree

singlestoredb/tests/test_management.py

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -450,55 +450,59 @@ def test_upload_file(self):
450450
def test_open(self):
451451
st = self.wg.stage
452452

453+
open_test_sql = f'open_test_{id(self)}.sql'
454+
453455
# See if error is raised for non-existent file
454456
with self.assertRaises(s2.ManagementError):
455-
st.open('open_test.sql', 'r')
457+
st.open(open_test_sql, 'r')
456458

457459
# Load test file
458-
st.upload_file(TEST_DIR / 'test.sql', 'open_test.sql')
460+
st.upload_file(TEST_DIR / 'test.sql', open_test_sql)
459461

460462
# Read file using `open`
461-
with st.open('open_test.sql', 'r') as rfile:
463+
with st.open(open_test_sql, 'r') as rfile:
462464
assert rfile.read() == open(TEST_DIR / 'test.sql').read()
463465

464466
# Read file using `open` with 'rt' mode
465-
with st.open('open_test.sql', 'rt') as rfile:
467+
with st.open(open_test_sql, 'rt') as rfile:
466468
assert rfile.read() == open(TEST_DIR / 'test.sql').read()
467469

468470
# Read file using `open` with 'rb' mode
469-
with st.open('open_test.sql', 'rb') as rfile:
471+
with st.open(open_test_sql, 'rb') as rfile:
470472
assert rfile.read() == open(TEST_DIR / 'test.sql', 'rb').read()
471473

472474
# Read file using `open` with 'rb' mode
473475
with self.assertRaises(ValueError):
474-
with st.open('open_test.sql', 'b') as rfile:
476+
with st.open(open_test_sql, 'b') as rfile:
475477
pass
476478

477479
# Attempt overwrite file using `open` with mode 'x'
478480
with self.assertRaises(OSError):
479-
with st.open('open_test.sql', 'x') as wfile:
481+
with st.open(open_test_sql, 'x') as wfile:
480482
pass
481483

482484
# Attempt overwrite file using `open` with mode 'w'
483-
with st.open('open_test.sql', 'w') as wfile:
485+
with st.open(open_test_sql, 'w') as wfile:
484486
wfile.write(open(TEST_DIR / 'test2.sql').read())
485487

486-
txt = st.download_file('open_test.sql', encoding='utf-8')
488+
txt = st.download_file(open_test_sql, encoding='utf-8')
487489

488490
assert txt == open(TEST_DIR / 'test2.sql').read()
489491

492+
open_raw_test_sql = f'open_raw_test_{id(self)}.sql'
493+
490494
# Test writer without context manager
491-
wfile = st.open('open_raw_test.sql', 'w')
495+
wfile = st.open(open_raw_test_sql, 'w')
492496
for line in open(TEST_DIR / 'test.sql'):
493497
wfile.write(line)
494498
wfile.close()
495499

496-
txt = st.download_file('open_raw_test.sql', encoding='utf-8')
500+
txt = st.download_file(open_raw_test_sql, encoding='utf-8')
497501

498502
assert txt == open(TEST_DIR / 'test.sql').read()
499503

500504
# Test reader without context manager
501-
rfile = st.open('open_raw_test.sql', 'r')
505+
rfile = st.open(open_raw_test_sql, 'r')
502506
txt = ''
503507
for line in rfile:
504508
txt += line
@@ -509,15 +513,18 @@ def test_open(self):
509513
def test_obj_open(self):
510514
st = self.wg.stage
511515

516+
obj_open_test_sql = f'obj_open_test_{id(self)}.sql'
517+
obj_open_dir = f'obj_open_dir_{id(self)}'
518+
512519
# Load test file
513-
f = st.upload_file(TEST_DIR / 'test.sql', 'obj_open_test.sql')
520+
f = st.upload_file(TEST_DIR / 'test.sql', obj_open_test_sql)
514521

515522
# Read file using `open`
516523
with f.open() as rfile:
517524
assert rfile.read() == open(TEST_DIR / 'test.sql').read()
518525

519526
# Make sure directories error out
520-
d = st.mkdir('obj_open_dir')
527+
d = st.mkdir(obj_open_dir)
521528
with self.assertRaises(IsADirectoryError):
522529
d.open()
523530

@@ -1143,58 +1150,62 @@ def test_upload_file_io(self):
11431150

11441151
def test_open(self):
11451152
for space in [self.personal_space, self.shared_space]:
1153+
open_test_ipynb = f'open_test_ipynb_{id(self)}.ipynb'
1154+
11461155
# See if error is raised for non-existent file
11471156
with self.assertRaises(s2.ManagementError):
1148-
space.open('open_test.ipynb', 'r')
1157+
space.open(open_test_ipynb, 'r')
11491158

11501159
# Load test file
1151-
space.upload_file(TEST_DIR / 'test.ipynb', 'open_test.ipynb')
1160+
space.upload_file(TEST_DIR / 'test.ipynb', open_test_ipynb)
11521161

11531162
# Read file using `open`
1154-
with space.open('open_test.ipynb', 'r') as rfile:
1163+
with space.open(open_test_ipynb, 'r') as rfile:
11551164
assert rfile.read() == open(TEST_DIR / 'test.ipynb').read()
11561165

11571166
# Read file using `open` with 'rt' mode
1158-
with space.open('open_test.ipynb', 'rt') as rfile:
1167+
with space.open(open_test_ipynb, 'rt') as rfile:
11591168
assert rfile.read() == open(TEST_DIR / 'test.ipynb').read()
11601169

11611170
# Read file using `open` with 'rb' mode
1162-
with space.open('open_test.ipynb', 'rb') as rfile:
1171+
with space.open(open_test_ipynb, 'rb') as rfile:
11631172
assert rfile.read() == open(TEST_DIR / 'test.ipynb', 'rb').read()
11641173

11651174
# Read file using `open` with 'rb' mode
11661175
with self.assertRaises(ValueError):
1167-
with space.open('open_test.ipynb', 'b') as rfile:
1176+
with space.open(open_test_ipynb, 'b') as rfile:
11681177
pass
11691178

11701179
# Attempt overwrite file using `open` with mode 'x'
11711180
with self.assertRaises(OSError):
1172-
with space.open('open_test.ipynb', 'x') as wfile:
1181+
with space.open(open_test_ipynb, 'x') as wfile:
11731182
pass
11741183

11751184
# Attempt overwrite file using `open` with mode 'w'
1176-
with space.open('open_test.ipynb', 'w') as wfile:
1185+
with space.open(open_test_ipynb, 'w') as wfile:
11771186
wfile.write(open(TEST_DIR / 'test2.ipynb').read())
11781187

1179-
txt = space.download_file('open_test.ipynb', encoding='utf-8')
1188+
txt = space.download_file(open_test_ipynb, encoding='utf-8')
11801189

11811190
assert txt == open(TEST_DIR / 'test2.ipynb').read()
11821191

1192+
open_raw_test_ipynb = f'open_raw_test_{id(self)}.ipynb'
1193+
11831194
# Test writer without context manager
1184-
wfile = space.open('open_raw_test.ipynb', 'w')
1195+
wfile = space.open(open_raw_test_ipynb, 'w')
11851196
for line in open(TEST_DIR / 'test.ipynb'):
11861197
wfile.write(line)
11871198
wfile.close()
11881199

11891200
txt = space.download_file(
1190-
'open_raw_test.ipynb',
1201+
open_raw_test_ipynb,
11911202
encoding='utf-8',
11921203
)
11931204

11941205
assert txt == open(TEST_DIR / 'test.ipynb').read()
11951206

11961207
# Test reader without context manager
1197-
rfile = space.open('open_raw_test.ipynb', 'r')
1208+
rfile = space.open(open_raw_test_ipynb, 'r')
11981209
txt = ''
11991210
for line in rfile:
12001211
txt += line
@@ -1203,15 +1214,18 @@ def test_open(self):
12031214
assert txt == open(TEST_DIR / 'test.ipynb').read()
12041215

12051216
# Cleanup
1206-
space.remove('open_test.ipynb')
1207-
space.remove('open_raw_test.ipynb')
1217+
space.remove(open_test_ipynb)
1218+
space.remove(open_raw_test_ipynb)
12081219

12091220
def test_obj_open(self):
12101221
for space in [self.personal_space, self.shared_space]:
1222+
obj_open_test_ipynb = f'obj_open_test_{id(self)}.ipynb'
1223+
obj_open_dir = f'obj_open_dir_{id(self)}'
1224+
12111225
# Load test file
12121226
f = space.upload_file(
12131227
TEST_DIR / 'test.ipynb',
1214-
'obj_open_test.ipynb',
1228+
obj_open_test_ipynb,
12151229
)
12161230

12171231
# Read file using `open`
@@ -1220,7 +1234,7 @@ def test_obj_open(self):
12201234

12211235
# Make sure directories error out
12221236
with self.assertRaises(s2.ManagementError):
1223-
space.mkdir('obj_open_dir')
1237+
space.mkdir(obj_open_dir)
12241238

12251239
# Write file using `open`
12261240
with f.open('w', encoding='utf-8') as wfile:
@@ -1248,7 +1262,7 @@ def test_obj_open(self):
12481262
assert txt == open(TEST_DIR / 'test.ipynb').read()
12491263

12501264
# Cleanup
1251-
space.remove('obj_open_test.ipynb')
1265+
space.remove(obj_open_test_ipynb)
12521266

12531267
def test_os_directories(self):
12541268
for space in [self.personal_space, self.shared_space]:

0 commit comments

Comments
 (0)