1
1
#!/usr/bin/env python3
2
- # -*- coding: utf-8 -*-
3
2
"""
4
3
5
4
@author: Adrien Wehrlé, University of Zurich, Switzerland
6
5
7
6
"""
8
7
9
- import earthspy .earthspy as es
10
- import pytest
11
8
import os
12
9
10
+ import pytest
11
+
12
+ import earthspy .earthspy as es
13
+
14
+
13
15
def pytest_addoption (parser ):
14
- parser .addoption ("--filepath" , action = "store" , default = "test" )
15
-
16
+ parser .addoption ("--authfile" , action = "store" , default = "test" )
16
17
17
- if os .getenv ("CI" ) is not None :
18
+
19
+ if os .getenv ("CI" ) is not None :
18
20
# create local variables from environment secrets for convenience
19
21
SH_CLIENT_ID = os .environ ["SH_CLIENT_ID" ]
20
22
SH_CLIENT_SECRET = os .environ ["SH_CLIENT_SECRET" ]
21
-
23
+
22
24
# path to credential file to be created
23
- filepath = "auth.txt"
24
-
25
+ authfile = "auth.txt"
26
+
25
27
# create file containing credentials for testing
26
- with open (filepath , "w" ) as out :
28
+ with open (authfile , "w" ) as out :
27
29
out .write (f"{ SH_CLIENT_ID } \n { SH_CLIENT_SECRET } " )
28
30
else :
31
+
29
32
@pytest .fixture (scope = "session" )
30
- def filepath (pytestconfig ):
31
- return pytestconfig .getoption ("filepath " )
32
-
33
+ def authfile (pytestconfig ):
34
+ return pytestconfig .getoption ("authfile " )
35
+
33
36
@pytest .fixture (scope = "session" )
34
- def credentials (filepath ):
37
+ def credentials (authfile ):
35
38
# read credentials stored in text file
36
- with open (filepath ) as file :
39
+ with open (authfile ) as file :
37
40
credentials = file .read ().splitlines ()
38
41
return credentials
39
-
42
+
40
43
@pytest .fixture (scope = "session" )
41
- def SH_CLIENT_ID (credentials ) -> None :
44
+ def SH_CLIENT_ID (credentials ) -> None :
42
45
# extract credentials from lines
43
46
SH_CLIENT_ID = credentials [0 ]
44
47
return SH_CLIENT_ID
45
-
48
+
46
49
@pytest .fixture (scope = "session" )
47
50
def SH_CLIENT_SECRET (credentials ) -> None :
48
51
SH_CLIENT_SECRET = credentials [1 ]
49
52
return SH_CLIENT_SECRET
50
53
51
54
52
-
53
55
@pytest .fixture (scope = "session" )
54
56
def test_evalscript ():
55
57
test_evalscript = """
@@ -69,37 +71,42 @@ def test_evalscript():
69
71
}
70
72
"""
71
73
return test_evalscript
72
-
74
+
75
+
73
76
@pytest .fixture (scope = "session" )
74
- def test_url ():
77
+ def test_url ():
75
78
test_url = (
76
79
"https://custom-scripts.sentinel-hub.com/custom-scripts/"
77
80
+ "sentinel-2/true_color/script.js"
78
81
)
79
82
return test_url
80
83
84
+
81
85
@pytest .fixture (scope = "session" )
82
- def test_collection ():
86
+ def test_collection ():
83
87
# an example of data collection
84
88
test_collection = "SENTINEL2_L2A"
85
89
return test_collection
86
-
90
+
91
+
87
92
@pytest .fixture (scope = "session" )
88
- def test_bounding_box ():
93
+ def test_bounding_box ():
89
94
# an example of footprint area
90
95
test_bounding_box = [- 51.13 , 69.204 , - 51.06 , 69.225 ]
91
96
return test_bounding_box
92
-
97
+
98
+
93
99
@pytest .fixture (scope = "session" )
94
- def test_area_name ():
100
+ def test_area_name ():
95
101
# an example of area available as GEOJSON file
96
102
test_area_name = "Ilulissat"
97
103
return test_area_name
98
104
105
+
99
106
@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 ):
101
108
# example of query with default parameters
102
- t1 = es .EarthSpy (filepath )
109
+ t1 = es .EarthSpy (authfile )
103
110
t1 .set_query_parameters (
104
111
bounding_box = test_bounding_box ,
105
112
time_interval = ["2019-08-23" ],
@@ -109,10 +116,11 @@ def t1(filepath, test_evalscript, test_collection, test_bounding_box):
109
116
)
110
117
return t1
111
118
119
+
112
120
@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 ):
114
122
# example of query with direct area name
115
- t2 = es .EarthSpy (filepath )
123
+ t2 = es .EarthSpy (authfile )
116
124
t2 .set_query_parameters (
117
125
bounding_box = test_area_name ,
118
126
time_interval = ["2019-08-23" ],
@@ -122,10 +130,11 @@ def t2(filepath, test_evalscript, test_collection, test_area_name):
122
130
)
123
131
return t2
124
132
133
+
125
134
@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 ):
127
136
# example of query with direct mode
128
- t3 = es .EarthSpy (filepath )
137
+ t3 = es .EarthSpy (authfile )
129
138
t3 .set_query_parameters (
130
139
bounding_box = test_bounding_box ,
131
140
time_interval = ["2019-08-23" ],
@@ -135,10 +144,11 @@ def t3(filepath, test_evalscript, test_collection, test_bounding_box):
135
144
)
136
145
return t3
137
146
147
+
138
148
@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 ):
140
150
# example of query with direct mode
141
- t4 = es .EarthSpy (filepath )
151
+ t4 = es .EarthSpy (authfile )
142
152
t4 .set_query_parameters (
143
153
bounding_box = test_bounding_box ,
144
154
time_interval = ["2019-08-23" ],
@@ -148,34 +158,3 @@ def t4(filepath, test_evalscript, test_collection, test_bounding_box):
148
158
raster_compression = "LZW" ,
149
159
)
150
160
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
-
0 commit comments