Skip to content

Commit

Permalink
Feature, FeatureCollection, Image, and ImageCollection copyProperties…
Browse files Browse the repository at this point in the history
…: add testing

PiperOrigin-RevId: 636566626
  • Loading branch information
schwehr authored and Google Earth Engine Authors committed May 23, 2024
1 parent 49ee8b8 commit e2c0bca
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 2 deletions.
32 changes: 32 additions & 0 deletions python/ee/tests/feature_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,20 @@
'arguments': {'crs': {'constantValue': EPSG_4326}},
}
}
# ee.Feature(None).serialize())['values']['0']
FEATURE_NONE_GRAPH = {
'functionInvocationValue': {
'functionName': 'Feature',
'arguments': {},
}
}
# ee.Feature(None, {'a': 'b'}).serialize())['values']['0']
FEATURE_A_GRAPH = {
'functionInvocationValue': {
'functionName': 'Feature',
'arguments': {'metadata': {'constantValue': {'a': 'b'}}},
}
}


def right_maxerror_proj(function_name: str) -> Dict[str, Any]:
Expand Down Expand Up @@ -250,6 +258,30 @@ def test_convex_hull(self):
result = json.loads(expression.serialize())
self.assertEqual(expect, result)

def test_copy_properties(self):
source = ee.Feature(None, {'a': 'b'})
properties = ['c', 'd']
exclude = ['e', 'f']
expect = make_expression_graph({
'arguments': {
'destination': FEATURE_NONE_GRAPH,
'source': FEATURE_A_GRAPH,
'properties': {'constantValue': properties},
'exclude': {'constantValue': exclude},
},
# Note this is Element rather than Feature
'functionName': 'Element.copyProperties',
})
expression = ee.Feature(None).copyProperties(source, properties, exclude)
result = json.loads(expression.serialize())
self.assertEqual(expect, result)

expression = ee.Feature(None).copyProperties(
source=source, properties=properties, exclude=exclude
)
result = json.loads(expression.serialize())
self.assertEqual(expect, result)

def test_cutLines(self):
expect = make_expression_graph({
'arguments': {
Expand Down
40 changes: 39 additions & 1 deletion python/ee/tests/featurecollection_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ def make_expression_graph(
}
}

FEATURES_A = {
'functionInvocationValue': {
'functionName': 'Collection.loadTable',
'arguments': {'tableId': {'constantValue': 'a'}},
}
}

FEATURES_B = {
'functionInvocationValue': {
'functionName': 'Collection.loadTable',
'arguments': {'tableId': {'constantValue': 'b'}},
}
}

class FeatureCollectionTestCase(apitestcase.ApiTestCase):

Expand Down Expand Up @@ -203,6 +216,32 @@ def test_cluster(self):
result = json.loads(expression.serialize())
self.assertEqual(expect, result)

def test_copy_properties(self):
source = ee.FeatureCollection('b')
properties = ['c', 'd']
exclude = ['e', 'f']
expect = make_expression_graph({
'arguments': {
'destination': FEATURES_A,
'source': FEATURES_B,
'properties': {'constantValue': properties},
'exclude': {'constantValue': exclude},
},
# Note this is Element rather than FeatureCollection
'functionName': 'Element.copyProperties',
})
expression = ee.FeatureCollection('a').copyProperties(
source, properties, exclude
)
result = json.loads(expression.serialize())
self.assertEqual(expect, result)

expression = ee.FeatureCollection('a').copyProperties(
source=source, properties=properties, exclude=exclude
)
result = json.loads(expression.serialize())
self.assertEqual(expect, result)

def test_inverse_distance(self):
a_range = 2
property_name = 'property name'
Expand Down Expand Up @@ -356,6 +395,5 @@ def test_random_points(self):
self.assertEqual(expect, result)



if __name__ == '__main__':
unittest.main()
27 changes: 26 additions & 1 deletion python/ee/tests/imagecollection_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,32 @@ def test_combine(self):
result = json.loads(expression.serialize())
self.assertEqual(expect, result)

def test_copy_properties(self):
source = ee.ImageCollection('b')
properties = ['c', 'd']
exclude = ['e', 'f']
expect = make_expression_graph({
'arguments': {
'destination': IMAGES_A,
'source': IMAGES_B,
'properties': {'constantValue': properties},
'exclude': {'constantValue': exclude},
},
# Note this is Element rather than ImageCollection
'functionName': 'Element.copyProperties',
})
expression = ee.ImageCollection('a').copyProperties(
source, properties, exclude
)
result = json.loads(expression.serialize())
self.assertEqual(expect, result)

expression = ee.ImageCollection('a').copyProperties(
source=source, properties=properties, exclude=exclude
)
result = json.loads(expression.serialize())
self.assertEqual(expect, result)

def test_forma_trend(self):
covariates = ee.ImageCollection('b')
window_size = 3
Expand Down Expand Up @@ -376,6 +402,5 @@ def test_to_bands(self):
self.assertEqual(expect, result)



if __name__ == '__main__':
unittest.main()

0 comments on commit e2c0bca

Please sign in to comment.