Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
yreynaud committed May 4, 2023
1 parent 0caf1ca commit c6fcb0a
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
10 changes: 9 additions & 1 deletion docs/installing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,12 @@ Developement installation
# this is needed to register git filters
git config --local include.path ../.gitconfig
pip install -e .
pip install -r requirements.txt
pip install -r requirements.txt
Pytest configuration
....................

Pytest uses a default configuration file (`config.yml`) in which we can found products paths to test.
This configuration can be superseded by adding a local config file on the home directory :
(`~/xarray-safe-s1/localconfig.yml`).
In this file, testing files can be listed in the var `product_paths`.
3 changes: 3 additions & 0 deletions safe_s1/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# default data paths for tests
product_paths:
- 'S1A_IW_GRDH_1SDV_20170907T103020_20170907T103045_018268_01EB76_Z010.SAFE'
48 changes: 48 additions & 0 deletions test/test_s1reader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import safe_s1
from safe_s1 import sentinel1_xml_mappings, Sentinel1Reader
import os
import logging
from pathlib import Path
import yaml

logging.basicConfig()
logging.captureWarnings(True)

logger = logging.getLogger('s1_reader_test')
logger.setLevel(logging.DEBUG)


# determine the config file we will use (config.yml by default, and a local config if one is present) and retrieve
# the products names
local_config_pontential_path = Path(os.path.join('~', 'xarray-safe-s1', 'localconfig.yml')).expanduser()
if local_config_pontential_path.exists():
config_path = local_config_pontential_path
with open(config_path) as config_content:
products = yaml.load(config_content, Loader=yaml.SafeLoader)['product_paths']
else:
config_path = Path(os.path.join(os.path.dirname(safe_s1.__file__), 'config.yml'))
with open(config_path) as config_content:
raw_products = yaml.load(config_content, Loader=yaml.SafeLoader)['product_paths']
products = [sentinel1_xml_mappings.get_test_file(filename) for filename in raw_products]


# Try to apply the reader on different products
def test_reader():
try:
for product in products:
reader = Sentinel1Reader(product)
# When a product is a multidataset, datatree is none, so we want to be sure that the datatree isn't empty
# (selecting a dataset)
sub_reader = Sentinel1Reader(reader.datasets_names[0])
dt = sub_reader.datatree
for ds in dt:
dt[ds].to_dataset().compute()
assert True
except:
assert False






0 comments on commit c6fcb0a

Please sign in to comment.