def test_overwrite(self, tmpdir): config = os.path.join(str(tmpdir), 'unit_test_config.ini') conf = ConfigHandler(config_fname=config) conf.add_section('SNAP') conf.set('SNAP', 'etc', 'temp/dir') with pytest.raises(RuntimeError): conf.set('SNAP', 'etc', 'temp/dir2') conf.set('SNAP', 'etc', 'temp/dir2', True) assert conf['SNAP']['etc'] == 'temp/dir2'
def test_remove(self, tmpdir): conf = ConfigHandler() with pytest.raises(AttributeError): conf.remove_option('SNAP', 'kex') with pytest.raises(AttributeError): conf.remove_option('SNApP', 'etc') conf.remove_option('FOO', 'bar') assert list(conf['FOO'].keys()) == [] conf.remove_section('FOO')
def test_make_dir_and_config(self, tmpdir): conf = ConfigHandler() path_pyrosar = os.path.exists(conf._ConfigHandler__GLOBAL['path']) path_config = os.path.isfile(conf._ConfigHandler__GLOBAL['config']) assert path_pyrosar is True assert path_config is True
def test_make_dir_and_config(self, tmpdir): config = os.path.join(str(tmpdir), 'unit_test_config.ini') conf = ConfigHandler(config_fname=config) path_pyrosar = os.path.exists(conf._ConfigHandler__GLOBAL['path']) path_config = os.path.isfile(conf._ConfigHandler__GLOBAL['config']) assert path_pyrosar is True assert path_config is True
def test_options(self, tmpdir): config = os.path.join(str(tmpdir), 'unit_test_config.ini') conf = ConfigHandler(config_fname=config) conf.add_section('SNAP') conf.set('SNAP', 'etc', 'temp/dir') with pytest.raises(AttributeError): conf.set('SNAPp', 'etc', 'temp/dir') assert conf['SNAP']['etc'] == 'temp/dir' assert conf['SNAP'] == {'etc': 'temp/dir'} assert conf.sections == ['SNAP']
def test_overwrite(self, tmpdir): conf = ConfigHandler() with pytest.raises(RuntimeError): conf.set('FOO', 'bar', 'loremipsum') conf.set('FOO', 'bar', 'loremipsum', overwrite=True) assert conf['FOO']['bar'] == 'loremipsum'
def test_options(self, tmpdir): conf = ConfigHandler() conf.set('FOO', 'bar', 'foobar') # cannot set attribute for section that does not exist with pytest.raises(AttributeError): conf.set('SNAPp', 'etc', 'temp/dir') assert conf['FOO']['bar'] == 'foobar' assert conf['FOO'] == {'bar': 'foobar'}
import ast import json import os import shutil import re import warnings import pkg_resources from pyroSAR._dev_config import ConfigHandler from spatialist.ancillary import finder config = ConfigHandler() class ExamineSnap(object): """ Class to check if ESA SNAP is installed. Upon initialization, this class searches for relevant binaries and the accompanying relative directory structure, which uniquely identify an ESA SNAP installation on a system. First, all relevant file and folder names are read from the pyroSAR config file if it exists and their existence is verified. If this fails, a system check is performed to find relevant binaries in the system PATH variable and additional files and folders relative to them. Furthermore, a snap.auxdata.properties file is scanned for auxiliary data URLs and local storage location. This is used by SNAP to manage data from e.g. the SRTM mission. In case SNAP is not installed, the respective information is read from a default file delivered with pyroSAR. This has the advantage of using the SNAP download URLs and local directory structure without having SNAP installed such that it can be adapted by other SAR software. """ def __init__(self):
def test_add_section(self): conf = ConfigHandler() conf.add_section('FOO') assert 'FOO' in conf.sections
def test_remove(self, tmpdir): config = os.path.join(str(tmpdir), 'unit_test_config.ini') conf = ConfigHandler(config_fname=config) conf.add_section('SNAP') conf.set('SNAP', 'etc', 'temp/dir') with pytest.raises(AttributeError): conf.remove_option('SNAP', 'kex') with pytest.raises(AttributeError): conf.remove_option('SNApP', 'etc') conf.remove_option('SNAP', 'etc') assert list(conf['SNAP'].keys()) == []
def test_add_section(self, tmpdir): config = os.path.join(str(tmpdir), 'unit_test_config.ini') conf = ConfigHandler(config_fname=config) conf.add_section('SNAP') assert conf.sections[0] == 'SNAP'
def test_delete_unit_data(self, tmpdir): config = os.path.join(str(tmpdir), 'unit_test_config.ini') conf = ConfigHandler(config_fname=config) os.remove(conf._ConfigHandler__GLOBAL['config'])