From f4e5265348832716e65b36b417ddd4adbb47a0d0 Mon Sep 17 00:00:00 2001 From: alzhang Date: Wed, 16 Jan 2019 16:22:26 +0800 Subject: [PATCH 1/3] alter .gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d7b5516c..0e679ce0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,9 @@ *.pyc +.vscode .idea .project .pydevproject .settings .coverage build -dist \ No newline at end of file +dist From da698b5d5b73db3a5e19e0fa4a68f0c3ae44d192 Mon Sep 17 00:00:00 2001 From: alzhang Date: Thu, 18 Apr 2019 17:10:14 +0800 Subject: [PATCH 2/3] Delete files remaining during the test --- tests/test_multipart.py | 1 + tests/test_object.py | 1 + tests/test_select_csv_object.py | 23 ++++++++++++++++++++++- tests/test_upload.py | 4 ++++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/tests/test_multipart.py b/tests/test_multipart.py index 3bf840d0..c6cbb8c8 100644 --- a/tests/test_multipart.py +++ b/tests/test_multipart.py @@ -50,6 +50,7 @@ def test_upload_part_content_md5_bad(self): headers = {'Content-Md5': oss2.utils.content_md5(content + content)} self.assertRaises(oss2.exceptions.InvalidDigest, self.bucket.upload_part, key, upload_id, 1, content, headers=headers) + self.bucket.abort_multipart_upload(key, upload_id) def test_progress(self): stats = {'previous': -1} diff --git a/tests/test_object.py b/tests/test_object.py index 31d22417..e0074f41 100644 --- a/tests/test_object.py +++ b/tests/test_object.py @@ -557,6 +557,7 @@ def test_copy_object_source_with_escape(self): result = self.bucket.get_object(target_key) self.assertEqual(content, result.read()) + self.bucket.delete_object(source_key) def test_update_object_meta(self): key = self.random_key('.txt') diff --git a/tests/test_select_csv_object.py b/tests/test_select_csv_object.py index e35e26d8..0350d7f9 100644 --- a/tests/test_select_csv_object.py +++ b/tests/test_select_csv_object.py @@ -42,6 +42,7 @@ def test_select_csv_object(self, testCase, sql, line_range = None): if line_range is None: testCase.assertEqual(self.scannedSize, file_size) + self.bucket.delete_object(key) return content 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 testCase.assertEqual(result.status, 400) except oss2.exceptions.ServerError as e: testCase.assertEqual(e.status, 400) + + self.bucket.delete_object(key) class TestSelectCsvObject(OssTestCase): def test_select_csv_object_not_empty_city(self): @@ -244,6 +247,7 @@ def test_select_csv_object_with_invalid_data(self): self.assertFalse(True, "expect to raise exception") except SelectOperationFailed: print("Got the exception. Ok.") + self.bucket.delete_object(key) def test_select_csv_object_into_file(self): key = "city_sample_data.csv" @@ -276,6 +280,7 @@ def test_select_csv_object_into_file(self): os.remove(output_file) self.assertEqual(content1, content2) + self.bucket.delete_object(key) def test_select_gzip_csv_object_into_file(self): key = "city_sample_data.csv.gz" @@ -300,6 +305,7 @@ def test_select_gzip_csv_object_into_file(self): os.remove(output_file) self.assertEqual(content1, content2) + self.bucket.delete_object(key) def test_select_csv_object_none_range(self): key = "city_sample_data.csv" @@ -319,7 +325,10 @@ def test_select_csv_object_none_range(self): for chunk in result: content += chunk + if len(content) <= 0 : + self.bucket.delete_object(key) self.assertTrue(len(content) > 0) + self.bucket.delete_object(key) def test_select_csv_object_with_output_delimiters(self): key = "test_select_csv_object_with_output_delimiters" @@ -332,6 +341,7 @@ def test_select_csv_object_with_output_delimiters(self): content += chunk self.assertEqual(content, 'abc|def\r\n'.encode('utf-8')) + self.bucket.delete_object(key) def test_select_csv_object_with_crc(self): key = "test_select_csv_object_with_crc" @@ -344,6 +354,7 @@ def test_select_csv_object_with_crc(self): content += chunk self.assertEqual(content, 'abc,def\n'.encode('utf-8')) + self.bucket.delete_object(key) def test_select_csv_object_with_skip_partial_data(self): key = "test_select_csv_object_with_skip_partial_data" @@ -359,6 +370,7 @@ def test_select_csv_object_with_skip_partial_data(self): print("expected error occurs") self.assertEqual(content, 'abc,def\n'.encode('utf-8')) + self.bucket.delete_object(key) def test_select_csv_object_with_output_raw(self): key = "test_select_csv_object_with_output_raw" @@ -371,6 +383,7 @@ def test_select_csv_object_with_output_raw(self): content += chunk self.assertEqual(content, 'abc\n'.encode('utf-8')) + self.bucket.delete_object(key) def test_select_csv_object_with_keep_columns(self): key = "test_select_csv_object_with_keep_columns" @@ -383,6 +396,7 @@ def test_select_csv_object_with_keep_columns(self): content += chunk self.assertEqual(content, 'abc,\n'.encode('utf-8')) + self.bucket.delete_object(key) def test_select_csv_object_with_output_header(self): key = "test_select_csv_object_with_output_header" @@ -395,6 +409,7 @@ def test_select_csv_object_with_output_header(self): content += chunk self.assertEqual(content, 'name\nabc\n'.encode('utf-8')) + self.bucket.delete_object(key) def test_select_csv_object_with_invalid_parameters(self): key = "test_select_csv_object_with_invalid_parameters" @@ -403,8 +418,14 @@ def test_select_csv_object_with_invalid_parameters(self): select_params = {'OutputHeader123':'true', 'CsvHeaderInfo':'Use'} try: result = self.bucket.select_object(key, "select name from ossobject", None, select_params) - self.assertFalse() + content = b'' + for chunk in result: + content += chunk + + self.bucket.delete_object(key) + self.assertEqual(content, 'abc\n'.encode('utf-8')) except SelectOperationClientError: + self.bucket.delete_object(key) print("expected error") if __name__ == '__main__': diff --git a/tests/test_upload.py b/tests/test_upload.py index 6a851234..fd89f8e9 100644 --- a/tests/test_upload.py +++ b/tests/test_upload.py @@ -178,6 +178,10 @@ def upload_part(self, key, upload_id, part_number, data): oss2.resumable_upload(self.bucket, key, pathname, multipart_threshold=0, part_size=100 * 1024) self.assertEqual(len(list(oss2.ObjectUploadIterator(self.bucket, key))), expected_unfinished) + upload = self.bucket.list_multipart_uploads() + for upload_id in upload.upload_list : + self.bucket.abort_multipart_upload(key, upload_id.upload_id) + self.bucket.delete_object(key) def test_interrupt_empty(self): self.__test_interrupt(310 * 1024, 1) From f9b05dc531bb72d9d90ff65dbb4c7b677c6ea2ff Mon Sep 17 00:00:00 2001 From: alzhang Date: Fri, 19 Apr 2019 11:17:15 +0800 Subject: [PATCH 3/3] Delete files remaining during the test --- tests/test_select_json_object.py | 5 ++++- tests/test_upload.py | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/test_select_json_object.py b/tests/test_select_json_object.py index bd9fb6ee..ec2e879e 100644 --- a/tests/test_select_json_object.py +++ b/tests/test_select_json_object.py @@ -52,7 +52,7 @@ def test_select_json_object(self, testCase, sql, input_format): if 'SplitRange' not in input_format and 'LineRange' not in input_format: testCase.assertEqual(self.scannedSize, file_size) - + self.bucket.delete_object(key) return content def test_select_json_object_invalid_request(self, testCase, sql, input_format): @@ -235,6 +235,7 @@ def test_select_json_object_with_invalid_data(self): self.assertFalse(True, "expect to raise exception") except oss2.exceptions.ServerError: print("Got the exception. Ok.") + self.bucket.delete_object(key) def test_select_json_object_none_range(self): print("test_select_json_object_none_range") @@ -258,6 +259,7 @@ def test_select_json_object_none_range(self): content += chunk self.assertTrue(len(content) > 0) + self.bucket.delete_object(key) def test_select_json_object_parse_num_as_string(self): key = "test_select_json_object_parse_num_as_string" @@ -267,6 +269,7 @@ def test_select_json_object_parse_num_as_string(self): for chunk in result: content += chunk self.assertEqual(content, b"{\"a\":123456789.123456789}\n") + self.bucket.delete_object(key) if __name__ == '__main__': unittest.main() diff --git a/tests/test_upload.py b/tests/test_upload.py index fd89f8e9..048c7591 100644 --- a/tests/test_upload.py +++ b/tests/test_upload.py @@ -76,6 +76,7 @@ def test_concurrency(self): result = self.bucket.get_object(key) self.assertEqual(content, result.read()) self.assertEqual(result.headers['x-oss-object-type'], 'Multipart') + self.bucket.delete_object(key) def test_progress(self): stats = {'previous': -1, 'ncalled': 0} @@ -180,7 +181,8 @@ def upload_part(self, key, upload_id, part_number, data): self.assertEqual(len(list(oss2.ObjectUploadIterator(self.bucket, key))), expected_unfinished) upload = self.bucket.list_multipart_uploads() for upload_id in upload.upload_list : - self.bucket.abort_multipart_upload(key, upload_id.upload_id) + if key == upload_id.key: + self.bucket.abort_multipart_upload(key, upload_id.upload_id) self.bucket.delete_object(key) def test_interrupt_empty(self):