From 447f3877fc57d4c5ff6d481568a81ff89902fb18 Mon Sep 17 00:00:00 2001 From: Daniel Baston Date: Thu, 13 Jul 2023 20:39:00 -0400 Subject: [PATCH] autotest vsicrypt.py: move setup to fixture --- autotest/gcore/vsicrypt.py | 36 +++++++++--------------------------- 1 file changed, 9 insertions(+), 27 deletions(-) diff --git a/autotest/gcore/vsicrypt.py b/autotest/gcore/vsicrypt.py index db45125fe656..f3667db88279 100755 --- a/autotest/gcore/vsicrypt.py +++ b/autotest/gcore/vsicrypt.py @@ -44,7 +44,14 @@ ############################################################################### @pytest.fixture(autouse=True, scope="module") -def module_disable_exceptions(): +def setup_and_cleanup(): + + fp = gdal.VSIFOpenL("/vsicrypt/key=DONT_USE_IN_PROD,file=/vsimem/file.bin", "wb+") + if fp is None: + pytest.skip("/vsicrypt is not available") + gdal.VSIFCloseL(fp) + gdal.Unlink("/vsicrypt/key=DONT_USE_IN_PROD,file=/vsimem/file.bin") + with gdaltest.disable_exceptions(): yield @@ -55,19 +62,9 @@ def module_disable_exceptions(): def test_vsicrypt_1(): - gdaltest.has_vsicrypt = False - fp = gdal.VSIFOpenL("/vsicrypt/key=DONT_USE_IN_PROD,file=/vsimem/file.bin", "wb+") - if fp is None: - pytest.skip() - gdal.VSIFCloseL(fp) - gdal.Unlink("/vsicrypt/key=DONT_USE_IN_PROD,file=/vsimem/file.bin") - gdaltest.has_vsicrypt = True - import vsifile - return vsifile.vsifile_generic( - "/vsicrypt/key=DONT_USE_IN_PROD,file=/vsimem/file.bin" - ) + vsifile.vsifile_generic("/vsicrypt/key=DONT_USE_IN_PROD,file=/vsimem/file.bin") ############################################################################### @@ -76,9 +73,6 @@ def test_vsicrypt_1(): def test_vsicrypt_2(): - if not gdaltest.has_vsicrypt: - pytest.skip() - # Missing key with gdaltest.error_handler(): fp = gdal.VSIFOpenL("/vsicrypt//vsimem/file.bin", "wb+") @@ -356,9 +350,6 @@ def test_vsicrypt_2(): ) def test_vsicrypt_3(): - if not gdaltest.has_vsicrypt: - pytest.skip() - for options in [ "sector_size=16", "alg=AES", @@ -492,9 +483,6 @@ def test_vsicrypt_3(): def test_vsicrypt_4(): - if not gdaltest.has_vsicrypt: - pytest.skip() - test_file = ( "/vsicrypt/key=DONT_USE_IN_PROD,sector_size=32,file=/vsimem/file_enc.bin" ) @@ -562,9 +550,6 @@ def test_vsicrypt_4(): def test_vsicrypt_5(): - if not gdaltest.has_vsicrypt: - pytest.skip() - test_file = "/vsicrypt/key=DONT_USE_IN_PROD,file=/vsimem/file_enc.bin" f = gdal.VSIFOpenL(test_file, "wb+") @@ -623,9 +608,6 @@ def test_vsicrypt_6(testnonboundtoswig_setup): # noqa # Set a valid key testnonboundtoswig_setup.VSISetCryptKey("DONT_USE_IN_PROD".encode("ASCII"), 16) - if not gdaltest.has_vsicrypt: - pytest.skip() - fp = gdal.VSIFOpenL("/vsicrypt/add_key_check=yes,file=/vsimem/file.bin", "wb+") assert fp is not None gdal.VSIFWriteL("hello", 1, 5, fp)