• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

dbekaert / RAiDER / 07570d2f-2174-4f46-b35a-1bf8a5be889a

10 Jun 2025 01:17AM UTC coverage: 94.415%. Remained the same
07570d2f-2174-4f46-b35a-1bf8a5be889a

Pull #726

circleci

garlic-os
Add note to existing users about CDS API changes
Pull Request #726: Update RAiDER for CDS API changes

10 of 13 new or added lines in 4 files covered. (76.92%)

9 existing lines in 4 files now uncovered.

3246 of 3438 relevant lines covered (94.42%)

0.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.0
/test/credentials/test_envVars.py
1
'''
2
Environment variables specific to each model are accepted iff uid and key
3
arguments are None.
4
'''
5

6
import pytest
1✔
7
from pathlib import Path
1✔
8
from platform import system
1✔
9
from RAiDER.models import credentials
1✔
10
from test import random_string
1✔
11

12
@pytest.mark.parametrize(
1✔
13
    'model_name,template,env_var_name_uid,env_var_name_key',
14
    [
15
        (
16
            'ERA5', (
17
                'url: https://cds.climate.copernicus.eu/api/v2\n'
18
                'key: {uid}:{key}\n'
19
            ),
20
            'RAIDER_ECMWF_ERA5_UID',
21
            'RAIDER_ECMWF_ERA5_API_KEY'
22
        ),
23
        (
24
            'ERA5T', (
25
                'url: https://cds.climate.copernicus.eu/api/v2\n'
26
                'key: {uid}:{key}\n'
27
            ),
28
            'RAIDER_ECMWF_ERA5_UID',
29
            'RAIDER_ECMWF_ERA5_API_KEY'
30
        ),
31
        (
32
            'HRES', (
33
                '{{\n'
34
                '    "url"   : "https://api.ecmwf.int/v1",\n'
35
                '    "key"   : "{key}",\n'
36
                '    "email" : "{uid}"\n'
37
                '}}\n'
38
            ),
39
            'RAIDER_HRES_EMAIL',
40
            'RAIDER_HRES_API_KEY'
41
        ),
42
        (
43
            # Simulate a .netrc file with multiple sets of credentials.
44
            # The ones not for urs.earthdata.nasa.gov should NOT be touched.
45
            # Indentation is done with TABS, as that is what the netrc package
46
            # generates.
47
            'GMAO', (
48
                'machine example.com\n'
49
                '        login johndoe\n'
50
                '        password hunter2\n'
51
                'machine urs.earthdata.nasa.gov\n'
52
                '        login {uid}\n'
53
                '        password {key}\n'
54
                'machine 127.0.0.1\n'
55
                '        login bobsmith\n'
56
                '        password dolphins\n'
57
            ),
58
            'EARTHDATA_USERNAME',
59
            'EARTHDATA_PASSWORD'
60
        ),
61
        (
62
            'MERRA2', (
63
                'machine example.com\n'
64
                '        login johndoe\n'
65
                '        password hunter2\n'
66
                'machine urs.earthdata.nasa.gov\n'
67
                '        login {uid}\n'
68
                '        password {key}\n'
69
                'machine 127.0.0.1\n'
70
                '        login bobsmith\n'
71
                '        password dolphins\n'
72
            ),
73
            'EARTHDATA_USERNAME',
74
            'EARTHDATA_PASSWORD'
75
        ),
76
    ]
77
)
78
def test_envVars(
1✔
79
    monkeypatch,
80
    model_name,
81
    template,
82
    env_var_name_uid,
83
    env_var_name_key
84
):
85
    hidden_ext = '_' if system() == "Windows" else '.'
1✔
86
    rc_filename = credentials.RC_FILENAMES[model_name]
1✔
87
    if rc_filename is None:
1✔
UNCOV
88
        return
×
89
    rc_path = Path('./') / (hidden_ext + rc_filename)
1✔
90
    rc_path = rc_path.expanduser()
1✔
91
    rc_path.unlink(missing_ok=True)
1✔
92

93
    # Give the rc file mock contents
94
    rc_path.write_text(template.format(uid=random_string(), key=random_string()))
1✔
95

96
    test_uid = random_string()
1✔
97
    test_key = random_string()
1✔
98

99
    with monkeypatch.context() as mp:
1✔
100
        mp.setenv(env_var_name_uid, test_uid)
1✔
101
        mp.setenv(env_var_name_key, test_key)
1✔
102
        credentials.check_api(model_name, None, None, './', update_rc_file=True)
1✔
103

104
    expected_content = template.format(uid=test_uid, key=test_key)
1✔
105
    actual_content = rc_path.read_text()
1✔
106
    rc_path.unlink()
1✔
107

108
    assert expected_content == actual_content, f'{rc_path} was not created correctly'
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc