Skip to content

Commit 74cb8b0

Browse files
committed
rename filepath for authfile
1 parent 4ea9306 commit 74cb8b0

File tree

2 files changed

+45
-69
lines changed

2 files changed

+45
-69
lines changed

tests/conftest.py

Lines changed: 44 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,57 @@
11
#!/usr/bin/env python3
2-
# -*- coding: utf-8 -*-
32
"""
43
54
@author: Adrien Wehrlé, University of Zurich, Switzerland
65
76
"""
87

9-
import earthspy.earthspy as es
10-
import pytest
118
import os
129

10+
import pytest
11+
12+
import earthspy.earthspy as es
13+
14+
1315
def pytest_addoption(parser):
14-
parser.addoption("--filepath", action="store", default="test")
15-
16+
parser.addoption("--authfile", action="store", default="test")
1617

17-
if os.getenv("CI") is not None:
18+
19+
if os.getenv("CI") is not None:
1820
# create local variables from environment secrets for convenience
1921
SH_CLIENT_ID = os.environ["SH_CLIENT_ID"]
2022
SH_CLIENT_SECRET = os.environ["SH_CLIENT_SECRET"]
21-
23+
2224
# path to credential file to be created
23-
filepath = "auth.txt"
24-
25+
authfile = "auth.txt"
26+
2527
# create file containing credentials for testing
26-
with open(filepath, "w") as out:
28+
with open(authfile, "w") as out:
2729
out.write(f"{SH_CLIENT_ID}\n{SH_CLIENT_SECRET}")
2830
else:
31+
2932
@pytest.fixture(scope="session")
30-
def filepath(pytestconfig):
31-
return pytestconfig.getoption("filepath")
32-
33+
def authfile(pytestconfig):
34+
return pytestconfig.getoption("authfile")
35+
3336
@pytest.fixture(scope="session")
34-
def credentials(filepath):
37+
def credentials(authfile):
3538
# read credentials stored in text file
36-
with open(filepath) as file:
39+
with open(authfile) as file:
3740
credentials = file.read().splitlines()
3841
return credentials
39-
42+
4043
@pytest.fixture(scope="session")
41-
def SH_CLIENT_ID(credentials) -> None:
44+
def SH_CLIENT_ID(credentials) -> None:
4245
# extract credentials from lines
4346
SH_CLIENT_ID = credentials[0]
4447
return SH_CLIENT_ID
45-
48+
4649
@pytest.fixture(scope="session")
4750
def SH_CLIENT_SECRET(credentials) -> None:
4851
SH_CLIENT_SECRET = credentials[1]
4952
return SH_CLIENT_SECRET
5053

5154

52-
5355
@pytest.fixture(scope="session")
5456
def test_evalscript():
5557
test_evalscript = """
@@ -69,37 +71,42 @@ def test_evalscript():
6971
}
7072
"""
7173
return test_evalscript
72-
74+
75+
7376
@pytest.fixture(scope="session")
74-
def test_url():
77+
def test_url():
7578
test_url = (
7679
"https://custom-scripts.sentinel-hub.com/custom-scripts/"
7780
+ "sentinel-2/true_color/script.js"
7881
)
7982
return test_url
8083

84+
8185
@pytest.fixture(scope="session")
82-
def test_collection():
86+
def test_collection():
8387
# an example of data collection
8488
test_collection = "SENTINEL2_L2A"
8589
return test_collection
86-
90+
91+
8792
@pytest.fixture(scope="session")
88-
def test_bounding_box():
93+
def test_bounding_box():
8994
# an example of footprint area
9095
test_bounding_box = [-51.13, 69.204, -51.06, 69.225]
9196
return test_bounding_box
92-
97+
98+
9399
@pytest.fixture(scope="session")
94-
def test_area_name():
100+
def test_area_name():
95101
# an example of area available as GEOJSON file
96102
test_area_name = "Ilulissat"
97103
return test_area_name
98104

105+
99106
@pytest.fixture(scope="session")
100-
def t1(filepath, test_evalscript, test_collection, test_bounding_box):
107+
def t1(authfile, test_evalscript, test_collection, test_bounding_box):
101108
# example of query with default parameters
102-
t1 = es.EarthSpy(filepath)
109+
t1 = es.EarthSpy(authfile)
103110
t1.set_query_parameters(
104111
bounding_box=test_bounding_box,
105112
time_interval=["2019-08-23"],
@@ -109,10 +116,11 @@ def t1(filepath, test_evalscript, test_collection, test_bounding_box):
109116
)
110117
return t1
111118

119+
112120
@pytest.fixture(scope="session")
113-
def t2(filepath, test_evalscript, test_collection, test_area_name):
121+
def t2(authfile, test_evalscript, test_collection, test_area_name):
114122
# example of query with direct area name
115-
t2 = es.EarthSpy(filepath)
123+
t2 = es.EarthSpy(authfile)
116124
t2.set_query_parameters(
117125
bounding_box=test_area_name,
118126
time_interval=["2019-08-23"],
@@ -122,10 +130,11 @@ def t2(filepath, test_evalscript, test_collection, test_area_name):
122130
)
123131
return t2
124132

133+
125134
@pytest.fixture(scope="session")
126-
def t3(filepath, test_evalscript, test_collection, test_bounding_box):
135+
def t3(authfile, test_evalscript, test_collection, test_bounding_box):
127136
# example of query with direct mode
128-
t3 = es.EarthSpy(filepath)
137+
t3 = es.EarthSpy(authfile)
129138
t3.set_query_parameters(
130139
bounding_box=test_bounding_box,
131140
time_interval=["2019-08-23"],
@@ -135,10 +144,11 @@ def t3(filepath, test_evalscript, test_collection, test_bounding_box):
135144
)
136145
return t3
137146

147+
138148
@pytest.fixture(scope="session")
139-
def t4(filepath, test_evalscript, test_collection, test_bounding_box):
149+
def t4(authfile, test_evalscript, test_collection, test_bounding_box):
140150
# example of query with direct mode
141-
t4 = es.EarthSpy(filepath)
151+
t4 = es.EarthSpy(authfile)
142152
t4.set_query_parameters(
143153
bounding_box=test_bounding_box,
144154
time_interval=["2019-08-23"],
@@ -148,34 +158,3 @@ def t4(filepath, test_evalscript, test_collection, test_bounding_box):
148158
raster_compression="LZW",
149159
)
150160
return t4
151-
152-
153-
154-
155-
156-
157-
158-
159-
160-
161-
162-
163-
164-
165-
166-
167-
168-
169-
170-
171-
172-
173-
174-
175-
176-
177-
178-
179-
180-
181-

tests/test_earthspy.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@
55
66
"""
77

8-
import glob
9-
import json
10-
import os
11-
128
import numpy as np
139
import pandas as pd
1410
import requests
1511
import sentinelhub as shb
1612

13+
1714
def test_init(t1, SH_CLIENT_ID, SH_CLIENT_SECRET) -> None:
1815
"""Test auth.txt parsing and connection configuration."""
1916

0 commit comments

Comments
 (0)