def test_vsiadls_fake_sync_copyobject(): if gdaltest.webserver_port == 0: pytest.skip() gdal.VSICurlClearCache() handler = webserver.SequentialHandler() handler.add('HEAD', '/azure/blob/myaccount/test_bucket/src.txt', 200, {'Content-Length': '3', 'x-ms-permissions': 'rwxrwxrwx', 'x-ms-resource-type': 'file'}) handler.add('HEAD', '/azure/blob/myaccount/test_bucket/dst.txt', 404) handler.add('PUT', '/azure/blob/myaccount/test_bucket/dst.txt', 202, expected_headers={'x-ms-copy-source': 'http://127.0.0.1:%d/azure/blob/myaccount/test_bucket/src.txt' % gdaltest.webserver_port}) with webserver.install_http_handler(handler): assert gdal.Sync('/vsiadls/test_bucket/src.txt', '/vsiadls/test_bucket/dst.txt') gdal.VSICurlClearCache() # Error case handler = webserver.SequentialHandler() handler.add('HEAD', '/azure/blob/myaccount/test_bucket/src.txt', 200, {'Content-Length': '3', 'x-ms-permissions': 'rwxrwxrwx', 'x-ms-resource-type': 'file'}) handler.add('HEAD', '/azure/blob/myaccount/test_bucket/dst.txt', 404) handler.add('PUT', '/azure/blob/myaccount/test_bucket/dst.txt', 400) with webserver.install_http_handler(handler): with gdaltest.error_handler(): assert not gdal.Sync('/vsiadls/test_bucket/src.txt', '/vsiadls/test_bucket/dst.txt')
def test_vsiadls_fake_sync_multithreaded_upload_single_file(): if gdaltest.webserver_port == 0: pytest.skip() gdal.VSICurlClearCache() gdal.Mkdir('/vsimem/test', 0) gdal.FileFromMemBuffer('/vsimem/test/foo', 'foo\n') handler = webserver.SequentialHandler() handler.add('HEAD', '/azure/blob/myaccount/test_bucket?resource=filesystem', 200) handler.add('HEAD', '/azure/blob/myaccount/test_bucket/foo', 404) handler.add('PUT', '/azure/blob/myaccount/test_bucket/foo?resource=file', 201) handler.add('PATCH', '/azure/blob/myaccount/test_bucket/foo?action=append&position=0', 202, expected_body = b'foo') handler.add('PATCH', '/azure/blob/myaccount/test_bucket/foo?action=append&position=3', 202, expected_body = b'\n') handler.add('PATCH', '/azure/blob/myaccount/test_bucket/foo?action=flush&close=true&position=4', 200) with gdaltest.config_option('VSIS3_SIMULATE_THREADING', 'YES'): with webserver.install_http_handler(handler): assert gdal.Sync('/vsimem/test/foo', '/vsiadls/test_bucket', options=['NUM_THREADS=1', 'CHUNK_SIZE=3']) gdal.RmdirRecursive('/vsimem/test')
def test_vsisync(): with gdaltest.error_handler(): assert not gdal.Sync('/i_do/not/exist', '/vsimem/') with gdaltest.error_handler(): assert not gdal.Sync('vsifile.py', '/i_do/not/exist') # Test copying a file for i in range(2): assert gdal.Sync('vsifile.py', '/vsimem/') assert gdal.VSIStatL('/vsimem/vsifile.py').size == gdal.VSIStatL( 'vsifile.py').size gdal.Unlink('/vsimem/vsifile.py') # Test copying the content of a directory gdal.Mkdir('/vsimem/test_sync', 0) gdal.FileFromMemBuffer('/vsimem/test_sync/foo.txt', 'bar') gdal.Mkdir('/vsimem/test_sync/subdir', 0) gdal.FileFromMemBuffer('/vsimem/test_sync/subdir/bar.txt', 'baz') if sys.platform != 'win32': with gdaltest.error_handler(): # even root cannot write into /proc assert not gdal.Sync('/vsimem/test_sync/', '/proc/i_do_not/exist') assert gdal.Sync('/vsimem/test_sync/', '/vsimem/out') assert gdal.ReadDir('/vsimem/out') == ['foo.txt', 'subdir'] assert gdal.ReadDir('/vsimem/out/subdir') == ['bar.txt'] # Again assert gdal.Sync('/vsimem/test_sync/', '/vsimem/out') gdal.RmdirRecursive('/vsimem/out') # Test copying a directory pct_values = [] def my_progress(pct, message, user_data): pct_values.append(pct) assert gdal.Sync('/vsimem/test_sync', '/vsimem/out', callback=my_progress) assert pct_values == [0.5, 1.0] assert gdal.ReadDir('/vsimem/out') == ['test_sync'] assert gdal.ReadDir('/vsimem/out/test_sync') == ['foo.txt', 'subdir'] gdal.RmdirRecursive('/vsimem/test_sync') gdal.RmdirRecursive('/vsimem/out')
def vsisync(): with gdaltest.error_handler(): if gdal.Sync('/i_do/not/exist', '/vsimem/'): gdaltest.post_reason('fail') return 'fail' with gdaltest.error_handler(): if gdal.Sync('vsifile.py', '/i_do/not/exist'): gdaltest.post_reason('fail') return 'fail' # Test copying a file for i in range(2): if not gdal.Sync('vsifile.py', '/vsimem/'): gdaltest.post_reason('fail') return 'fail' if gdal.VSIStatL('/vsimem/vsifile.py').size != gdal.VSIStatL( 'vsifile.py').size: gdaltest.post_reason('fail') return 'fail' gdal.Unlink('/vsimem/vsifile.py') # Test copying the content of a directory gdal.Mkdir('/vsimem/test_sync', 0) gdal.FileFromMemBuffer('/vsimem/test_sync/foo.txt', 'bar') gdal.Mkdir('/vsimem/test_sync/subdir', 0) gdal.FileFromMemBuffer('/vsimem/test_sync/subdir/bar.txt', 'baz') if sys.platform != 'win32': with gdaltest.error_handler(): if gdal.Sync('/vsimem/test_sync/', '/i_do_not/exist'): gdaltest.post_reason('fail') return 'fail' if not gdal.Sync('/vsimem/test_sync/', '/vsimem/out'): gdaltest.post_reason('fail') return 'fail' if gdal.ReadDir('/vsimem/out') != ['foo.txt', 'subdir']: gdaltest.post_reason('fail') print(gdal.ReadDir('/vsimem/out')) return 'fail' if gdal.ReadDir('/vsimem/out/subdir') != ['bar.txt']: gdaltest.post_reason('fail') print(gdal.ReadDir('/vsimem/out/subdir')) return 'fail' # Again if not gdal.Sync('/vsimem/test_sync/', '/vsimem/out'): gdaltest.post_reason('fail') return 'fail' gdal.RmdirRecursive('/vsimem/out') # Test copying a directory pct_values = [] def my_progress(pct, message, user_data): pct_values.append(pct) if not gdal.Sync('/vsimem/test_sync', '/vsimem/out', callback=my_progress): gdaltest.post_reason('fail') return 'fail' if pct_values != [0.5, 1.0]: gdaltest.post_reason('fail') print(pct_values) return 'fail' if gdal.ReadDir('/vsimem/out') != ['test_sync']: gdaltest.post_reason('fail') print(gdal.ReadDir('/vsimem/out')) return 'fail' if gdal.ReadDir('/vsimem/out/test_sync') != ['foo.txt', 'subdir']: gdaltest.post_reason('fail') print(gdal.ReadDir('/vsimem/out/test_sync')) return 'fail' gdal.RmdirRecursive('/vsimem/test_sync') gdal.RmdirRecursive('/vsimem/out') return 'success'