Skip to content

Commit

Permalink
autotest vsicrypt.py: move setup to fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaston committed Jul 15, 2023
1 parent 7dc0e78 commit 447f387
Showing 1 changed file with 9 additions and 27 deletions.
36 changes: 9 additions & 27 deletions autotest/gcore/vsicrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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")


###############################################################################
Expand All @@ -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+")
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"
)
Expand Down Expand Up @@ -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+")
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 447f387

Please sign in to comment.