Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.5.2 #670

Merged
merged 110 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
110 commits
Select commit Hold shift + click to select a range
b407817
Formatting
garlic-os Jun 4, 2024
2aba84b
Use sep instead of delim_whitespace
garlic-os Jun 8, 2024
4f9abd9
Formatting, type annotations
garlic-os Jun 10, 2024
124a007
autopep8
garlic-os Jun 10, 2024
7ec6592
Refactor
garlic-os Jun 10, 2024
7c3d209
Add entry for #652
garlic-os Jun 10, 2024
6abd5a7
Add entry for #651
garlic-os Jun 10, 2024
a259c7a
Add link to #652
garlic-os Jun 10, 2024
05beba5
Update .netrc instead of overwriting
garlic-os Jun 12, 2024
8611224
Add to-do list for new tests
garlic-os Jun 12, 2024
f9470c9
Bump ASFHyP3/actions from 0.11.0 to 0.11.1
dependabot[bot] Jun 17, 2024
f350997
Use raw string for RegEx
garlic-os Jun 19, 2024
f185470
Add tests for credentials.py
garlic-os Jun 19, 2024
e2191c2
Fix bugs identified by tests
garlic-os Jun 19, 2024
2bddba0
Merge pull request #651 from garlic-os/issue-643-remove-delim_whitespace
jlmaurer Jun 21, 2024
5e9f78f
add catch for when calling tropo_delay as a fcn
jlmaurer Jan 17, 2024
94cbf1a
add a unit test
jlmaurer Jan 18, 2024
e0198fd
add another unit test
jlmaurer Jan 18, 2024
541600a
update CHANGELOG
jlmaurer Jan 18, 2024
16c9b23
temp fix for merra2
jlmaurer Feb 13, 2024
e413c88
merra2 seems to work so use that
jlmaurer Feb 21, 2024
91b7b83
allow both scenario_4 tests
jlmaurer Feb 21, 2024
9c0d9fb
saving for now
jlmaurer Apr 9, 2024
7b57c33
Merge pull request #654 from dbekaert/dependabot/github_actions/ASFHy…
jlmaurer Jun 24, 2024
7b28344
Use more apt name "run config" instead of "template"
garlic-os Jun 24, 2024
c4c6502
Add type hints as I go
garlic-os Jun 24, 2024
2d5f7dc
Fix formatting as I go
garlic-os Jun 24, 2024
8f6fbdb
Update program name from "raiderDelay.py" to "raider.py"
garlic-os Jun 24, 2024
cca39fc
Core count: default to all instead of arbitrary 8
garlic-os Jun 24, 2024
8e1827e
Move cli/raider.yaml to cli/examples/template.yaml
garlic-os Jun 24, 2024
92f2483
Port example run configs from old raiderDelay CLI
garlic-os Jun 24, 2024
09800b8
Update CHANGELOG.md
garlic-os Jun 24, 2024
4048fa8
Move each example run config to separate folder
garlic-os Jun 24, 2024
cfdccef
Add example run configs' data files
garlic-os Jun 24, 2024
d617dac
update datetimes to be tz-aware and make sure all dates are datetime …
jlmaurer Jun 25, 2024
f3aa4bd
Integrate example run configurations into CLI
garlic-os Jun 25, 2024
81818ed
Create test_generate_config.py
garlic-os Jun 25, 2024
d148dec
autopep8
garlic-os Jun 25, 2024
363b013
Merge branch 'dev' into port-example-args-to-yamls
garlic-os Jun 25, 2024
306c056
Update filenames in comments
garlic-os Jun 25, 2024
566e09e
Update update_yaml with new default yaml path
garlic-os Jun 25, 2024
946275d
Update update_yaml with new default yaml path
garlic-os Jun 25, 2024
74e49e5
update unit tests and add new unit tests
jlmaurer Jun 26, 2024
7e420e8
fix weather model files for test_slant
jlmaurer Jun 26, 2024
b75c16c
fix a few formats and typos
jlmaurer Jun 26, 2024
7bb4ad5
add some missing files back
jlmaurer Jun 26, 2024
add9001
add back missing files
jlmaurer Jun 26, 2024
1600e63
Fix typo
garlic-os Jun 26, 2024
2ddb984
Remove double space
garlic-os Jun 26, 2024
9c4103c
Update main executable's name to raider.py
garlic-os Jun 26, 2024
21876af
Update CHANGELOG.md for #657
garlic-os Jun 26, 2024
e177667
Add None checks to aws.get_s3_file
garlic-os Jun 26, 2024
c27c7a6
AWS: Add type annotations
garlic-os Jun 26, 2024
3fdbd5f
autopep8
garlic-os Jun 26, 2024
831da7f
Update CHANGELOG.md for #648
garlic-os Jun 26, 2024
cf1ae49
Fix syntax errors from autopep8
garlic-os Jun 26, 2024
f5d6431
Parametrize
garlic-os Jun 26, 2024
70498fe
Parametrize tests
garlic-os Jun 26, 2024
6baec0e
fix datetime timezones in prepFromGUNW
jlmaurer Jun 26, 2024
80fa135
xarray doesn't like tz-aware datetimes
jlmaurer Jun 27, 2024
d8f7555
add a few more unit tests and examples for functions
jlmaurer Jun 27, 2024
1df39dc
add test for downloadGNSS module
jlmaurer Jun 29, 2024
63039cb
change merra2 to era5 for one test
jlmaurer Jun 29, 2024
1e73bab
make test_scenario_4 use a temp directory and fix one more utcnow ins…
jlmaurer Jun 30, 2024
3c0a9b8
Python 3.9 does not have the UTC object
jlmaurer Jun 30, 2024
521c4db
mark scenario_4 as long
jlmaurer Jun 30, 2024
ef92d75
Merge pull request #627 from jlmaurer/issue623
jlmaurer Jun 30, 2024
1b35ab7
Bump ASFHyP3/actions from 0.11.1 to 0.11.2
dependabot[bot] Jul 1, 2024
3c9f476
Merge pull request #659 from dbekaert/dependabot/github_actions/ASFHy…
jlmaurer Jul 1, 2024
8cbc0e6
Merge branch 'dev' into issue-648-missing-gunw-error-msg
garlic-os Jul 2, 2024
b9ec19e
Merge branch 'dev' into issue-638-do-not-overwrite-netrc
garlic-os Jul 2, 2024
6c7e438
Merge branch 'dev' into patch-1
garlic-os Jul 2, 2024
fc142ef
Secrets no longer needed for changelog check
jhkennedy Jul 3, 2024
e232831
Merge pull request #660 from dbekaert/jhkennedy-patch-1
jlmaurer Jul 3, 2024
09ef3ff
Use more consistent phrasing in my changelog entries
garlic-os Jul 3, 2024
56538fb
Merge pull request #657 from garlic-os/patch-1
jlmaurer Jul 3, 2024
890d8ed
Update dem-stitcher for new geoid url
cmarshak Jul 5, 2024
e6974aa
Update CHANGELOG.md
cmarshak Jul 5, 2024
f393345
Update CHANGELOG.md
jlmaurer Jul 5, 2024
5b7ba07
Merge pull request #662 from dbekaert/dem-stitcher-update
jlmaurer Jul 5, 2024
5c8165d
Fix call to get_stats in downloadGNSSDelays.py
jlmaurer Jun 21, 2024
af096fd
use better names for dataframe variables
jlmaurer Jul 2, 2024
22e1ef7
fix typos and bugs and add unit tests
jlmaurer Jul 4, 2024
0687461
Fix scipy sum bug and add unit tests
jlmaurer Jul 4, 2024
afb07cf
update changelog
jlmaurer Jul 5, 2024
a826e07
fix bug in test_GUNW to raise correct error
jlmaurer Jul 5, 2024
25c897a
Update CHANGELOG.md
cmarshak Jul 5, 2024
4c413ad
Merge pull request #661 from jlmaurer/fix_gnss_download
jlmaurer Jul 5, 2024
792c621
Parametrize tests
garlic-os Jul 6, 2024
ee6ed3f
Add None check for RC_FILENAMES
garlic-os Jul 6, 2024
98f5b94
Create test_envVars.py
garlic-os Jul 6, 2024
4fc5213
Merge branch 'dev' into issue-638-do-not-overwrite-netrc
garlic-os Jul 6, 2024
e0bf8dd
Refactor match back to if-else chain for 3.9
garlic-os Jul 6, 2024
bf73290
Merge branch 'issue-638-do-not-overwrite-netrc' of https://github.com…
garlic-os Jul 6, 2024
542494e
Add type annotations
garlic-os Jul 6, 2024
6087b4e
Create regression tests for #658
garlic-os Jul 6, 2024
2078051
Merge branch 'dev' into issue-648-missing-gunw-error-msg
garlic-os Jul 6, 2024
e09f1ac
Prefix test data paths with TEST_DIR
garlic-os Jul 6, 2024
23eb9b3
Switch boto3-type-annotations for boto3-stubs
garlic-os Jul 7, 2024
b237406
Fix autopep8 corruption
garlic-os Jul 7, 2024
b23302a
Fix autopep8 corruption
garlic-os Jul 7, 2024
abb93c7
Fix autopep8 corruption
garlic-os Jul 8, 2024
ff860bd
Merge branch 'dev' into port-example-args-to-yamls
garlic-os Jul 8, 2024
e37c73c
Merge pull request #658 from garlic-os/issue-648-missing-gunw-error-msg
jlmaurer Jul 9, 2024
201fd87
Merge branch 'dev' into issue-638-do-not-overwrite-netrc
jlmaurer Jul 9, 2024
5190b53
Merge branch 'dev' into port-example-args-to-yamls
garlic-os Jul 9, 2024
e4131dc
Merge pull request #656 from garlic-os/port-example-args-to-yamls
jlmaurer Jul 9, 2024
f72abcc
Merge branch 'dev' into issue-638-do-not-overwrite-netrc
jlmaurer Jul 10, 2024
701d788
Merge pull request #652 from garlic-os/issue-638-do-not-overwrite-netrc
jlmaurer Jul 12, 2024
2b7190c
Merge pull request #663 from dbekaert/Changelog
jlmaurer Jul 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ on:

jobs:
call-version-info-workflow:
uses: ASFHyP3/actions/.github/workflows/reusable-version-info.yml@v0.11.0
uses: ASFHyP3/actions/.github/workflows/reusable-version-info.yml@v0.11.2
with:
python_version: '3.10'

call-docker-ghcr-workflow:
needs: call-version-info-workflow
uses: ASFHyP3/actions/.github/workflows/reusable-docker-ghcr.yml@v0.11.0
uses: ASFHyP3/actions/.github/workflows/reusable-docker-ghcr.yml@v0.11.2
with:
version_tag: ${{ needs.call-version-info-workflow.outputs.version_tag }}
release_branch: main
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@ on:

jobs:
call-changelog-check-workflow:
uses: ASFHyP3/actions/.github/workflows/reusable-changelog-check.yml@v0.11.0
secrets:
USER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: ASFHyP3/actions/.github/workflows/reusable-changelog-check.yml@v0.11.2
2 changes: 1 addition & 1 deletion .github/workflows/labeled-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ on:

jobs:
call-labeled-pr-check-workflow:
uses: ASFHyP3/actions/.github/workflows/reusable-labeled-pr-check.yml@v0.11.0
uses: ASFHyP3/actions/.github/workflows/reusable-labeled-pr-check.yml@v0.11.2
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
call-release-workflow:
uses: ASFHyP3/actions/.github/workflows/reusable-release.yml@v0.11.0
uses: ASFHyP3/actions/.github/workflows/reusable-release.yml@v0.11.2
with:
release_prefix: RAiDER
develop_branch: dev
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
call-bump-version-workflow:
uses: ASFHyP3/actions/.github/workflows/reusable-bump-version.yml@v0.11.0
uses: ASFHyP3/actions/.github/workflows/reusable-bump-version.yml@v0.11.2
with:
user: dbekaert
email: bekaertdavid@gmail.com
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [PEP 440](https://www.python.org/dev/peps/pep-0440/)
and uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.5.2]
### Changed
* [627](https://github.com/dbekaert/RAiDER/pull/627) - Made Python datetimes timezone-aware and added unit tests and bug fixes.
* [651](https://github.com/dbekaert/RAiDER/pull/651) - Removed use of deprecated argument to `pandas.read_csv`.
* [652](https://github.com/dbekaert/RAiDER/pull/652) - Changed the behavior of `RAiDER.models.credentials.check_api` to not overwrite the user's API credential files.
* [656](https://github.com/dbekaert/RAiDER/pull/656) - Example run configuration files available through `raider.py --generate_config <example_name>`.
* [657](https://github.com/dbekaert/RAiDER/pull/657) - Fixed a few typos in `README.md`.
* [658](https://github.com/dbekaert/RAiDER/pull/658) - Fixed opaque error message if a GUNW file is not produced while HyP3 independently against a previous INSAR_ISCE.
* [661](https://github.com/dbekaert/RAiDER/pull/661) - Fixed bug in raiderDownloadGNSS, removed call to scipy.sum, and added unit tests.
* [662](https://github.com/dbekaert/RAiDER/pull/662) - Bumped dem-stitcher to >= v2.5.6, which updates the URL for reading the Geoid EGM 2008.

## [0.5.1]
### Changed
* Use hyp3-lib v3* to download orbits to be able to distribute load across ESA and ASF. Can be easily swapped out for `sentineleof` in future release.
Expand All @@ -28,6 +39,7 @@ and uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [0.4.6]

### Added
* Added check for intermediate grid creation in _get_delays_on_cube
* Adds an `s1_orbits.py` module which includes:
* `get_orbits_from_slc_ids` to download the associated orbit files for a list of Sentinel-1 SLC IDs
* `ensure_orbit_credentials` to ensure ESA CSDE credentials have been provides to download orbit files. This should be called before `sentineleof` is used to download orbits.
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ RAiDER does **not** currently run on arm64 processors on Mac. We will update thi

### Installing With Conda

RAiDER is available on [conda-forge](https://anaconda.org/conda-forge/raider). __[Conda](https://docs.conda.io/en/latest/index.html)__ is a cross-platform way to use Python that allows you to setup and use "virtual environments." These can help to keep dependencies for different sets of code separate. We recommend using [Miniforge](https://github.com/conda-forge/miniforge), a conda environment manager that uses conda-forge as its default code repo. Alternatively,see __[here](https://docs.anaconda.com/anaconda/install/)__ for help installing Anaconda and __[here](https://docs.conda.io/en/latest/miniconda.html)__ for installing Miniconda.
RAiDER is available on [conda-forge](https://anaconda.org/conda-forge/raider). __[Conda](https://docs.conda.io/en/latest/index.html)__ is a cross-platform way to use Python that allows you to setup and use "virtual environments." These can help to keep dependencies for different sets of code separate. We recommend using [Miniforge](https://github.com/conda-forge/miniforge), a conda environment manager that uses conda-forge as its default code repo. Alternatively, see __[here](https://docs.anaconda.com/anaconda/install/)__ for help installing Anaconda and __[here](https://docs.conda.io/en/latest/miniconda.html)__ for installing Miniconda.

Installing RAiDER:
```
Expand Down Expand Up @@ -85,8 +85,8 @@ RAiDER has the ability to download weather models from third-parties; some of wh
## 3. Running RAiDER and Documentation

For detailed documentation, examples, and Jupyter notebooks see the [RAiDER-docs repository](https://github.com/dbekaert/RAiDER-docs).
We welcome contributions of other examples on how to leverage the RAiDER (see [here](https://github.com/dbekaert/RAiDER/blob/dev/CONTRIBUTING.md) for instructions).
``` raiderDelay.py -h ``` provides a help menu and list of example commands to get started.
We welcome contributions of other examples on how to leverage the RAiDER (see [here](https://github.com/dbekaert/RAiDER/blob/dev/CONTRIBUTING.md) for instructions).
``` raider.py -h ``` provides a help menu and set of example run configurations to get started.
The RAiDER scripts are highly modularized in Python and allows for building your own processing workflow.

------
Expand Down
4 changes: 3 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencies:
- cdsapi
- cfgrib
- dask
- dem_stitcher>=2.3.1
- dem_stitcher>=2.5.6
- ecmwf-api-client
- h5netcdf
- h5py
Expand Down Expand Up @@ -67,3 +67,5 @@ dependencies:
- jupyter_contrib_nbextensions
- jupyterlab
- wand
# For development
- boto3-stubs
28 changes: 21 additions & 7 deletions test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import pytest
import subprocess
import shutil
import string
import random
from contextlib import contextmanager
from pathlib import Path

Expand Down Expand Up @@ -32,25 +34,30 @@ def pushd(dir):
def update_yaml(dct_cfg:dict, dst:str='temp.yaml'):
""" Write a new yaml file from a dictionary.

Updates parameters in the default 'raider.yaml' file.
Updates parameters in the default 'template.yaml' file.
Each key:value pair will in 'dct_cfg' will overwrite that in the default
"""
import RAiDER, yaml

template_file = os.path.join(
os.path.dirname(RAiDER.__file__), 'cli', 'raider.yaml')
run_config_path = os.path.join(
os.path.dirname(RAiDER.__file__),
'cli',
'examples',
'template',
'template.yaml'
)

with open(template_file, 'r') as f:
with open(run_config_path, 'r') as f:
try:
params = yaml.safe_load(f)
except yaml.YAMLError as exc:
print(exc)
raise ValueError(f'Something is wrong with the yaml file {template_file}')
raise ValueError(f'Something is wrong with the yaml file {run_config_path}')

params = {**params, **dct_cfg}

with open(dst, 'w') as fh:
yaml.safe_dump(params, fh, default_flow_style=False)
yaml.safe_dump(params, fh, default_flow_style=False)

return dst

Expand All @@ -77,4 +84,11 @@ def makeLatLonGrid(bbox, reg, out_dir, spacing=0.1):

def make_delay_name(weather_model_name, date, time, kind='ztd'):
assert kind in 'ztd std ray'.split(), 'Incorrect type of delays.'
return f'{weather_model_name}_tropo_{date}T{time.replace(":", "")}_{kind}.nc'
return f'{weather_model_name}_tropo_{date}T{time.replace(":", "")}_{kind}.nc'


def random_string(
length: int = 32,
alphabet: str = string.ascii_letters + string.digits
) -> str:
return ''.join(random.choices(alphabet, k=length))
75 changes: 75 additions & 0 deletions test/credentials/test_createFile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
'''
When update_rc_file is either True or False, the relevant API RC file should be
created if it doesn't exist.
'''
from typing import Tuple

import pytest
import os
from pathlib import Path
from platform import system
from RAiDER.models import credentials
from test import random_string


def get_creds_cds(rc_path: Path) -> Tuple[str, str]:
import cdsapi
cds_credentials = cdsapi.api.read_config(rc_path)
uid, key = cds_credentials['key'].split(':')
return uid, key


def get_creds_ecmwf(rc_path: Path) -> Tuple[str, str]:
import ecmwfapi
# Get current ECMWF API RC file path
old_rc_path = os.getenv("ECMWF_API_RC_FILE", ecmwfapi.api.DEFAULT_RCFILE_PATH)

# Point ecmwfapi to current dir to avoid overwriting ~/.ecmwfapirc
os.environ["ECMWF_API_RC_FILE"] = str(rc_path)
key, _, uid = ecmwfapi.api.get_apikey_values()

# Point ecmwfapi back to previous value and remove local API file
os.environ["ECMWF_API_RC_FILE"] = old_rc_path
return uid, key


def get_creds_netrc(rc_path: Path) -> Tuple[str, str]:
import netrc
host = 'urs.earthdata.nasa.gov'
netrc_credentials = netrc.netrc(rc_path)
uid, _, key = netrc_credentials.authenticators(host)
return uid, key


@pytest.mark.parametrize(
'model_name,get_creds',
(
('ERA5', get_creds_cds),
('ERA5T', get_creds_cds),
('HRES', get_creds_ecmwf),
('GMAO', get_creds_netrc),
('MERRA2', get_creds_netrc)
)
)
def test_createFile(model_name, get_creds):
# Get the rc file's path
hidden_ext = '_' if system() == "Windows" else '.'
rc_filename = credentials.RC_FILENAMES[model_name]
if rc_filename is None:
return
rc_path = Path('./') / (hidden_ext + rc_filename)
rc_path = rc_path.expanduser()
rc_path.unlink(missing_ok=True)

test_uid = random_string()
test_key = random_string()

# Test creation of the rc file
credentials.check_api(model_name, test_uid, test_key, './', update_rc_file=False)
assert rc_path.exists(), f'{rc_path} does not exist'

# Check if API is written correctly
uid, key = get_creds(rc_path)
rc_path.unlink()
assert uid == test_uid, f'{rc_path}: UID was not written correctly'
assert key == test_key, f'{rc_path}: KEY was not written correctly'
108 changes: 108 additions & 0 deletions test/credentials/test_envVars.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
'''
Environment variables specific to each model are accepted iff uid and key
arguments are None.
'''

import pytest
from pathlib import Path
from platform import system
from RAiDER.models import credentials
from test import random_string

@pytest.mark.parametrize(
'model_name,template,env_var_name_uid,env_var_name_key',
[
(
'ERA5', (
'url: https://cds.climate.copernicus.eu/api/v2\n'
'key: {uid}:{key}\n'
),
'RAIDER_ECMWF_ERA5_UID',
'RAIDER_ECMWF_ERA5_API_KEY'
),
(
'ERA5T', (
'url: https://cds.climate.copernicus.eu/api/v2\n'
'key: {uid}:{key}\n'
),
'RAIDER_ECMWF_ERA5_UID',
'RAIDER_ECMWF_ERA5_API_KEY'
),
(
'HRES', (
'{{\n'
' "url" : "https://api.ecmwf.int/v1",\n'
' "key" : "{key}",\n'
' "email" : "{uid}"\n'
'}}\n'
),
'RAIDER_HRES_EMAIL',
'RAIDER_HRES_API_KEY'
),
(
# Simulate a .netrc file with multiple sets of credentials.
# The ones not for urs.earthdata.nasa.gov should NOT be touched.
# Indentation is done with TABS, as that is what the netrc package
# generates.
'GMAO', (
'machine example.com\n'
' login johndoe\n'
' password hunter2\n'
'machine urs.earthdata.nasa.gov\n'
' login {uid}\n'
' password {key}\n'
'machine 127.0.0.1\n'
' login bobsmith\n'
' password dolphins\n'
),
'EARTHDATA_USERNAME',
'EARTHDATA_PASSWORD'
),
(
'MERRA2', (
'machine example.com\n'
' login johndoe\n'
' password hunter2\n'
'machine urs.earthdata.nasa.gov\n'
' login {uid}\n'
' password {key}\n'
'machine 127.0.0.1\n'
' login bobsmith\n'
' password dolphins\n'
),
'EARTHDATA_USERNAME',
'EARTHDATA_PASSWORD'
),
]
)
def test_envVars(
monkeypatch,
model_name,
template,
env_var_name_uid,
env_var_name_key
):
hidden_ext = '_' if system() == "Windows" else '.'
rc_filename = credentials.RC_FILENAMES[model_name]
if rc_filename is None:
return
rc_path = Path('./') / (hidden_ext + rc_filename)
rc_path = rc_path.expanduser()
rc_path.unlink(missing_ok=True)

test_uid = random_string()
test_key = random_string()

with monkeypatch.context() as mp:
mp.setenv(env_var_name_uid, test_uid)
mp.setenv(env_var_name_key, test_key)
credentials.check_api(model_name, None, None, './', update_rc_file=False)

expected_content = template.format(uid=test_uid, key=test_key)
actual_content = rc_path.read_text()
rc_path.unlink()

assert (
expected_content == actual_content,
f'{rc_path} was not updated correctly'
)
31 changes: 31 additions & 0 deletions test/credentials/test_updateFalse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'''
When update_rc_file is False, the RC file should NOT be modified if it already
exists.
'''
import pytest

from pathlib import Path
from platform import system
from RAiDER.models import credentials


@pytest.mark.parametrize('model_name', 'ERA5 ERA5T HRES GMAO MERRA2'.split())
def test_updateFalse(model_name):
# Get the rc file's path
hidden_ext = '_' if system() == "Windows" else '.'
rc_filename = credentials.RC_FILENAMES[model_name]
if rc_filename is None:
return
rc_path = Path('./') / (hidden_ext + rc_filename)
rc_path = rc_path.expanduser()

# Write some example text to test for
rc_path.write_text('dummy')

# Test creation of this model's RC file in current dir
credentials.check_api(model_name, None, None, './', update_rc_file=False)

# Assert the content was unchanged
content = rc_path.read_text()
rc_path.unlink()
assert content == 'dummy', f'{rc_path} was modified'
Loading