Skip to content

Commit da698b5

Browse files
alzhangalzhang
authored andcommitted
Delete files remaining during the test
1 parent a5ad8d0 commit da698b5

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

tests/test_multipart.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def test_upload_part_content_md5_bad(self):
5050
headers = {'Content-Md5': oss2.utils.content_md5(content + content)}
5151

5252
self.assertRaises(oss2.exceptions.InvalidDigest, self.bucket.upload_part, key, upload_id, 1, content, headers=headers)
53+
self.bucket.abort_multipart_upload(key, upload_id)
5354

5455
def test_progress(self):
5556
stats = {'previous': -1}

tests/test_object.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ def test_copy_object_source_with_escape(self):
557557

558558
result = self.bucket.get_object(target_key)
559559
self.assertEqual(content, result.read())
560+
self.bucket.delete_object(source_key)
560561

561562
def test_update_object_meta(self):
562563
key = self.random_key('.txt')

tests/test_select_csv_object.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def test_select_csv_object(self, testCase, sql, line_range = None):
4242
if line_range is None:
4343
testCase.assertEqual(self.scannedSize, file_size)
4444

45+
self.bucket.delete_object(key)
4546
return content
4647

4748
def test_select_csv_object_invalid_request(self, testCase, sql, line_range = None):
@@ -60,6 +61,8 @@ def test_select_csv_object_invalid_request(self, testCase, sql, line_range = Non
6061
testCase.assertEqual(result.status, 400)
6162
except oss2.exceptions.ServerError as e:
6263
testCase.assertEqual(e.status, 400)
64+
65+
self.bucket.delete_object(key)
6366

6467
class TestSelectCsvObject(OssTestCase):
6568
def test_select_csv_object_not_empty_city(self):
@@ -244,6 +247,7 @@ def test_select_csv_object_with_invalid_data(self):
244247
self.assertFalse(True, "expect to raise exception")
245248
except SelectOperationFailed:
246249
print("Got the exception. Ok.")
250+
self.bucket.delete_object(key)
247251

248252
def test_select_csv_object_into_file(self):
249253
key = "city_sample_data.csv"
@@ -276,6 +280,7 @@ def test_select_csv_object_into_file(self):
276280

277281
os.remove(output_file)
278282
self.assertEqual(content1, content2)
283+
self.bucket.delete_object(key)
279284

280285
def test_select_gzip_csv_object_into_file(self):
281286
key = "city_sample_data.csv.gz"
@@ -300,6 +305,7 @@ def test_select_gzip_csv_object_into_file(self):
300305

301306
os.remove(output_file)
302307
self.assertEqual(content1, content2)
308+
self.bucket.delete_object(key)
303309

304310
def test_select_csv_object_none_range(self):
305311
key = "city_sample_data.csv"
@@ -319,7 +325,10 @@ def test_select_csv_object_none_range(self):
319325
for chunk in result:
320326
content += chunk
321327

328+
if len(content) <= 0 :
329+
self.bucket.delete_object(key)
322330
self.assertTrue(len(content) > 0)
331+
self.bucket.delete_object(key)
323332

324333
def test_select_csv_object_with_output_delimiters(self):
325334
key = "test_select_csv_object_with_output_delimiters"
@@ -332,6 +341,7 @@ def test_select_csv_object_with_output_delimiters(self):
332341
content += chunk
333342

334343
self.assertEqual(content, 'abc|def\r\n'.encode('utf-8'))
344+
self.bucket.delete_object(key)
335345

336346
def test_select_csv_object_with_crc(self):
337347
key = "test_select_csv_object_with_crc"
@@ -344,6 +354,7 @@ def test_select_csv_object_with_crc(self):
344354
content += chunk
345355

346356
self.assertEqual(content, 'abc,def\n'.encode('utf-8'))
357+
self.bucket.delete_object(key)
347358

348359
def test_select_csv_object_with_skip_partial_data(self):
349360
key = "test_select_csv_object_with_skip_partial_data"
@@ -359,6 +370,7 @@ def test_select_csv_object_with_skip_partial_data(self):
359370
print("expected error occurs")
360371

361372
self.assertEqual(content, 'abc,def\n'.encode('utf-8'))
373+
self.bucket.delete_object(key)
362374

363375
def test_select_csv_object_with_output_raw(self):
364376
key = "test_select_csv_object_with_output_raw"
@@ -371,6 +383,7 @@ def test_select_csv_object_with_output_raw(self):
371383
content += chunk
372384

373385
self.assertEqual(content, 'abc\n'.encode('utf-8'))
386+
self.bucket.delete_object(key)
374387

375388
def test_select_csv_object_with_keep_columns(self):
376389
key = "test_select_csv_object_with_keep_columns"
@@ -383,6 +396,7 @@ def test_select_csv_object_with_keep_columns(self):
383396
content += chunk
384397

385398
self.assertEqual(content, 'abc,\n'.encode('utf-8'))
399+
self.bucket.delete_object(key)
386400

387401
def test_select_csv_object_with_output_header(self):
388402
key = "test_select_csv_object_with_output_header"
@@ -395,6 +409,7 @@ def test_select_csv_object_with_output_header(self):
395409
content += chunk
396410

397411
self.assertEqual(content, 'name\nabc\n'.encode('utf-8'))
412+
self.bucket.delete_object(key)
398413

399414
def test_select_csv_object_with_invalid_parameters(self):
400415
key = "test_select_csv_object_with_invalid_parameters"
@@ -403,8 +418,14 @@ def test_select_csv_object_with_invalid_parameters(self):
403418
select_params = {'OutputHeader123':'true', 'CsvHeaderInfo':'Use'}
404419
try:
405420
result = self.bucket.select_object(key, "select name from ossobject", None, select_params)
406-
self.assertFalse()
421+
content = b''
422+
for chunk in result:
423+
content += chunk
424+
425+
self.bucket.delete_object(key)
426+
self.assertEqual(content, 'abc\n'.encode('utf-8'))
407427
except SelectOperationClientError:
428+
self.bucket.delete_object(key)
408429
print("expected error")
409430

410431
if __name__ == '__main__':

tests/test_upload.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ def upload_part(self, key, upload_id, part_number, data):
178178
oss2.resumable_upload(self.bucket, key, pathname, multipart_threshold=0, part_size=100 * 1024)
179179

180180
self.assertEqual(len(list(oss2.ObjectUploadIterator(self.bucket, key))), expected_unfinished)
181+
upload = self.bucket.list_multipart_uploads()
182+
for upload_id in upload.upload_list :
183+
self.bucket.abort_multipart_upload(key, upload_id.upload_id)
184+
self.bucket.delete_object(key)
181185

182186
def test_interrupt_empty(self):
183187
self.__test_interrupt(310 * 1024, 1)

0 commit comments

Comments
 (0)