Skip to content

Commit 3585cf0

Browse files
committed
test: update tests to use serialized calls
1 parent a55e959 commit 3585cf0

File tree

43 files changed

+4266
-1091
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+4266
-1091
lines changed

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Homepage = "https://github.com/gee-community/geetools"
6363
"httplib2",
6464
"pytest-regressions",
6565
"Pillow",
66-
"pytest-gee>=0.4.0", # get the special regressions
66+
"pytest-gee>=0.6.0", # get the serialized regressions
6767
"jsonschema",
6868
]
6969
doc = [

tests/test_Feature.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
"""Test the ``Feature`` class."""
2+
import ee
3+
4+
import geetools # noqa: F401
25

36

47
class TestToFeatureCollection:
58
"""Test the ``toFeatureCollection`` method."""
69

7-
def test_to_feature_collection(self, multipoint_feature, data_regression):
10+
def test_to_feature_collection(self, multipoint_feature, ee_feature_collection_regression):
811
fc = multipoint_feature.geetools.toFeatureCollection()
9-
data_regression.check(fc.getInfo())
12+
ee_feature_collection_regression.check(fc)
1013

1114

1215
class TestRemoveProperties:
1316
"""Test the ``removeProperties`` method."""
1417

15-
def test_remove_properties(self, multipoint_feature, data_regression):
18+
def test_remove_properties(self, multipoint_feature, ee_feature_collection_regression):
1619
feature = multipoint_feature.geetools.removeProperties(["foo"])
17-
data_regression.check(feature.getInfo())
20+
ee_feature_collection_regression.check(ee.FeatureCollection(feature))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
result: '0'
2+
values:
3+
'0':
4+
functionInvocationValue:
5+
arguments:
6+
destination:
7+
functionInvocationValue:
8+
arguments:
9+
geometry:
10+
functionInvocationValue:
11+
arguments:
12+
feature:
13+
valueReference: '1'
14+
functionName: Feature.geometry
15+
functionName: Feature
16+
exclude:
17+
arrayValue:
18+
values:
19+
- valueReference: '3'
20+
source:
21+
valueReference: '1'
22+
functionName: Element.copyProperties
23+
'1':
24+
functionInvocationValue:
25+
arguments:
26+
key:
27+
valueReference: '2'
28+
object:
29+
functionInvocationValue:
30+
arguments:
31+
key:
32+
valueReference: '3'
33+
object:
34+
functionInvocationValue:
35+
arguments:
36+
geometry:
37+
functionInvocationValue:
38+
arguments:
39+
coordinates:
40+
constantValue:
41+
- - 0
42+
- 0
43+
- - 0
44+
- 1
45+
functionName: GeometryConstructors.MultiPoint
46+
functionName: Feature
47+
value:
48+
valueReference: '2'
49+
functionName: Element.set
50+
value:
51+
valueReference: '3'
52+
functionName: Element.set
53+
'2':
54+
constantValue: bar
55+
'3':
56+
constantValue: foo
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
result: '0'
2+
values:
3+
'0':
4+
functionInvocationValue:
5+
arguments:
6+
features:
7+
functionInvocationValue:
8+
arguments:
9+
baseAlgorithm:
10+
functionDefinitionValue:
11+
argumentNames:
12+
- _MAPPING_VAR_0_0
13+
body: '1'
14+
dropNulls:
15+
constantValue: false
16+
list:
17+
functionInvocationValue:
18+
arguments:
19+
geometry:
20+
functionInvocationValue:
21+
arguments:
22+
feature:
23+
valueReference: '2'
24+
functionName: Feature.geometry
25+
functionName: Geometry.geometries
26+
functionName: List.map
27+
functionName: Collection
28+
'1':
29+
functionInvocationValue:
30+
arguments:
31+
feature:
32+
valueReference: '2'
33+
geometry:
34+
argumentReference: _MAPPING_VAR_0_0
35+
functionName: Feature.setGeometry
36+
'2':
37+
functionInvocationValue:
38+
arguments:
39+
key:
40+
valueReference: '3'
41+
object:
42+
functionInvocationValue:
43+
arguments:
44+
key:
45+
valueReference: '4'
46+
object:
47+
functionInvocationValue:
48+
arguments:
49+
geometry:
50+
functionInvocationValue:
51+
arguments:
52+
coordinates:
53+
constantValue:
54+
- - 0
55+
- 0
56+
- - 0
57+
- 1
58+
functionName: GeometryConstructors.MultiPoint
59+
functionName: Feature
60+
value:
61+
valueReference: '3'
62+
functionName: Element.set
63+
value:
64+
valueReference: '4'
65+
functionName: Element.set
66+
'3':
67+
constantValue: bar
68+
'4':
69+
constantValue: foo

tests/test_FeatureCollection.py

+21-20
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ def vatican(self):
3636
class TestToDictionary:
3737
"""Test the ``toDictionary`` method."""
3838

39-
def test_to_dictionary(self, data_regression):
40-
output = self.table.geetools.toDictionary("ADM0_NAME", ["ADM0_CODE", "Shape_Area"])
41-
data_regression.check(output.getInfo())
39+
def test_to_dictionary(self, ee_dictionary_regression):
40+
d = self.table.geetools.toDictionary("ADM0_NAME", ["ADM0_CODE", "Shape_Area"])
41+
ee_dictionary_regression.check(d, prescision=4)
4242

4343
@property
4444
def table(self):
@@ -70,8 +70,9 @@ def test_merge_geometries(self, gaul_3_countries, data_regression):
7070
class TestToPolygons:
7171
"""Test the ``toPolygons`` method."""
7272

73-
def test_to_polygons(self, fc_instance, dataframe_regression):
73+
def test_to_polygons(self, fc_instance):
7474
fc = fc_instance.geetools.toPolygons()
75+
# ee_feature_collection_regression.check(fc, prescision=4)
7576
gdf = gpd.GeoDataFrame.from_features(fc.getInfo())
7677
vertex = gdf.geometry.apply(lambda g: sum(len(p.exterior.coords) for p in g.geoms))
7778
assert vertex.sum() == 66
@@ -80,33 +81,33 @@ def test_to_polygons(self, fc_instance, dataframe_regression):
8081
class TestByProperties:
8182
"""Test the ``byProperties`` method."""
8283

83-
def test_by_properties(self, ecoregions, data_regression):
84+
def test_by_properties(self, ecoregions, ee_dictionary_regression):
8485
fc = ecoregions.geetools.byProperties()
85-
data_regression.check(fc.getInfo())
86+
ee_dictionary_regression.check(fc, prescision=4)
8687

87-
def test_by_properties_with_id(self, ecoregions, data_regression):
88+
def test_by_properties_with_id(self, ecoregions, ee_dictionary_regression):
8889
fc = ecoregions.geetools.byProperties("label")
89-
data_regression.check(fc.getInfo())
90+
ee_dictionary_regression.check(fc, prescision=4)
9091

91-
def test_by_properties_with_properties(self, ecoregions, data_regression):
92+
def test_by_properties_with_properties(self, ecoregions, ee_dictionary_regression):
9293
fc = ecoregions.geetools.byProperties("label", properties=["01_tmean", "02_tmean"])
93-
data_regression.check(fc.getInfo())
94+
ee_dictionary_regression.check(fc, prescision=4)
9495

9596

9697
class TestByFeatures:
9798
"""Test the ``byFeatures`` method."""
9899

99-
def test_by_features(self, ecoregions, data_regression):
100+
def test_by_features(self, ecoregions, ee_dictionary_regression):
100101
fc = ecoregions.geetools.byFeatures()
101-
data_regression.check(fc.getInfo())
102+
ee_dictionary_regression.check(fc, prescision=4)
102103

103-
def test_by_features_with_id(self, ecoregions, data_regression):
104+
def test_by_features_with_id(self, ecoregions, ee_dictionary_regression):
104105
fc = ecoregions.geetools.byFeatures("label")
105-
data_regression.check(fc.getInfo())
106+
ee_dictionary_regression.check(fc, prescision=4)
106107

107-
def test_by_features_with_properties(self, ecoregions, data_regression):
108+
def test_by_features_with_properties(self, ecoregions, ee_dictionary_regression):
108109
fc = ecoregions.geetools.byFeatures("label", properties=["01_tmean", "02_tmean"])
109-
data_regression.check(fc.getInfo())
110+
ee_dictionary_regression.check(fc, prescision=4)
110111

111112

112113
class TestPlotByFeatures:
@@ -297,13 +298,13 @@ def hydroshed(self):
297298
class TestFromGeoInterface:
298299
"""Test the ``fromGeoInterface`` method."""
299300

300-
def test_from_geo_interface(self, gdf, data_regression):
301+
def test_from_geo_interface(self, gdf, ee_feature_collection_regression):
301302
fc = ee.FeatureCollection.geetools.fromGeoInterface(gdf)
302-
data_regression.check(fc.getInfo())
303+
ee_feature_collection_regression.check(fc, prescision=4)
303304

304-
def test_from_geo_interface_from_dict(self, gdf, data_regression):
305+
def test_from_geo_interface_from_dict(self, gdf, ee_feature_collection_regression):
305306
fc = ee.FeatureCollection.geetools.fromGeoInterface(gdf.__geo_interface__)
306-
data_regression.check(fc.getInfo())
307+
ee_feature_collection_regression.check(fc, prescision=4)
307308

308309
def test_error_from_geo_interface_(self):
309310
with pytest.raises(ValueError):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
result: '0'
2+
values:
3+
'0':
4+
functionInvocationValue:
5+
arguments:
6+
keys:
7+
functionInvocationValue:
8+
arguments:
9+
baseAlgorithm:
10+
functionDefinitionValue:
11+
argumentNames:
12+
- _MAPPING_VAR_0_0
13+
body: '1'
14+
dropNulls:
15+
constantValue: false
16+
list:
17+
functionInvocationValue:
18+
arguments:
19+
collection:
20+
valueReference: '2'
21+
property:
22+
valueReference: '3'
23+
functionName: AggregateFeatureCollection.array
24+
functionName: List.map
25+
values:
26+
functionInvocationValue:
27+
arguments:
28+
baseAlgorithm:
29+
functionDefinitionValue:
30+
argumentNames:
31+
- _MAPPING_VAR_0_0
32+
body: '4'
33+
dropNulls:
34+
constantValue: false
35+
list:
36+
functionInvocationValue:
37+
arguments:
38+
collection:
39+
functionInvocationValue:
40+
arguments:
41+
baseAlgorithm:
42+
functionDefinitionValue:
43+
argumentNames:
44+
- _MAPPING_VAR_0_0
45+
body: '6'
46+
collection:
47+
valueReference: '2'
48+
functionName: Collection.map
49+
count:
50+
functionInvocationValue:
51+
arguments:
52+
collection:
53+
valueReference: '2'
54+
functionName: Collection.size
55+
functionName: Collection.toList
56+
functionName: List.map
57+
functionName: Dictionary.fromLists
58+
'1':
59+
functionInvocationValue:
60+
arguments:
61+
condition:
62+
functionInvocationValue:
63+
arguments:
64+
left:
65+
functionInvocationValue:
66+
arguments:
67+
string1:
68+
functionInvocationValue:
69+
arguments:
70+
value:
71+
argumentReference: _MAPPING_VAR_0_0
72+
functionName: ObjectType
73+
string2:
74+
constantValue: String
75+
functionName: String.compareTo
76+
right:
77+
constantValue: 0
78+
functionName: Number.eq
79+
falseCase:
80+
functionInvocationValue:
81+
arguments:
82+
number:
83+
argumentReference: _MAPPING_VAR_0_0
84+
functionName: Number.format
85+
trueCase:
86+
argumentReference: _MAPPING_VAR_0_0
87+
functionName: If
88+
'2':
89+
functionInvocationValue:
90+
arguments:
91+
tableId:
92+
constantValue: projects/google/charts_feature_example
93+
functionName: Collection.loadTable
94+
'3':
95+
constantValue: system:index
96+
'4':
97+
functionInvocationValue:
98+
arguments:
99+
element:
100+
functionInvocationValue:
101+
arguments:
102+
input:
103+
argumentReference: _MAPPING_VAR_0_0
104+
newProperties:
105+
valueReference: '5'
106+
propertySelectors:
107+
valueReference: '5'
108+
functionName: Feature.select
109+
properties:
110+
valueReference: '5'
111+
functionName: Element.toDictionary
112+
'5':
113+
functionInvocationValue:
114+
arguments:
115+
element:
116+
valueReference: '3'
117+
list:
118+
functionInvocationValue:
119+
arguments:
120+
element:
121+
functionInvocationValue:
122+
arguments:
123+
collection:
124+
valueReference: '2'
125+
functionName: Collection.first
126+
functionName: Element.propertyNames
127+
functionName: List.remove
128+
'6':
129+
functionInvocationValue:
130+
arguments:
131+
input:
132+
argumentReference: _MAPPING_VAR_0_0
133+
newProperties:
134+
valueReference: '5'
135+
propertySelectors:
136+
valueReference: '5'
137+
retainGeometry:
138+
constantValue: true
139+
functionName: Feature.select

0 commit comments

Comments
 (0)