Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oss zh check tests #172

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
*.pyc
.vscode
.idea
.project
.pydevproject
.settings
.coverage
build
dist
dist
1 change: 1 addition & 0 deletions tests/test_multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
1 change: 1 addition & 0 deletions tests/test_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
23 changes: 22 additions & 1 deletion tests/test_select_csv_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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__':
Expand Down
5 changes: 4 additions & 1 deletion tests/test_select_json_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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")
Expand All @@ -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"
Expand All @@ -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()
6 changes: 6 additions & 0 deletions tests/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -178,6 +179,11 @@ 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 :
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):
self.__test_interrupt(310 * 1024, 1)
Expand Down