Skip to content

Commit

Permalink
improved tests
Browse files Browse the repository at this point in the history
  • Loading branch information
johntruckenbrodt committed May 17, 2024
1 parent 39894c5 commit d432092
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
14 changes: 13 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import pytest
import platform


@pytest.fixture
Expand All @@ -21,7 +22,8 @@ def testdir():
def testdata(testdir):
out = {
# ASAR_IMS__A_20040703T205338, product: SLC, driver: ESA
'asar': os.path.join(testdir, 'ASA_IMS_1PNESA20040703_205338_000000182028_00172_12250_00001672562030318361237.N1'),
'asar': os.path.join(testdir,
'ASA_IMS_1PNESA20040703_205338_000000182028_00172_12250_00001672562030318361237.N1'),
# ERS1_IMP__A_19960808T205906, product: PRI, driver: ESA
'ers1_esa': os.path.join(testdir, 'SAR_IMP_1PXESA19960808_205906_00000017G158_00458_26498_2615.E1'),
# ERS1_IMS__D_19951220T024320, product: SLC, driver: CEOS_ERS
Expand Down Expand Up @@ -54,3 +56,13 @@ def auxdata_dem_cases():
('SRTM 3Sec', ['srtm_39_02.zip']),
('TDX90m', ['DEM/N51/E010/TDM1_DEM__30_N51E011.zip'])]
return cases


@pytest.fixture
def tmp_home(monkeypatch, tmp_path):
home = tmp_path / 'tmp_home'
home.mkdir()
var = 'USERPROFILE' if platform.system() == 'Windows' else 'HOME'
monkeypatch.setenv(var, str(home))
assert os.path.expanduser('~') == str(home)
yield home
17 changes: 11 additions & 6 deletions tests/test_examine.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
from pyroSAR.examine import ExamineSnap, SnapProperties


def test_snap_config(tmpdir):
def test_snap_config(tmpdir, tmp_home):
conf_snap = ExamineSnap()
conf = SnapProperties(path=os.path.dirname(conf_snap.etc))
tmp_userpath = conf.userpath
tmp_tilecache = conf['snap.jai.tileCacheSize']
path = os.path.join(os.path.expanduser('~'), '.snap', 'etc', 'snap.properties')
assert conf.userpath_properties == path
conf.userpath = tmpdir
assert conf.userpath == tmpdir
with pytest.raises(KeyError):
conf['foobar'] = tmpdir

###########################################################################
# check that the type is preserved when setting values
conf['snap.jai.tileCacheSize'] = 2048
assert conf['snap.jai.tileCacheSize'] == 2048
assert isinstance(conf['snap.jai.tileCacheSize'], int)
Expand All @@ -39,6 +40,10 @@ def test_snap_config(tmpdir):

conf = SnapProperties(path=os.path.dirname(conf_snap.etc))
assert conf['snap.jai.tileCacheSize'] is True
###########################################################################
# check that a path can correctly be written and read
conf = SnapProperties(path=os.path.dirname(conf_snap.etc))
conf['snap.userdir'] = str(tmpdir / '.snap')

conf.userpath = tmp_userpath
conf['snap.jai.tileCacheSize'] = tmp_tilecache
conf = SnapProperties(path=os.path.dirname(conf_snap.etc))
assert conf['snap.userdir'] == str(tmpdir / '.snap')

0 comments on commit d432092

Please sign in to comment.