Google Earth Engine Authors 0950defb0d v0.1.381
PiperOrigin-RevId: 584437309
2023-11-29 20:23:07 -08:00

53 lines
1.3 KiB
Python

#!/usr/bin/env python3
"""Test for the blob module."""
import json
import ee
from ee import apitestcase
import unittest
class BlobTest(apitestcase.ApiTestCase):
def test_blob(self):
url = 'gs://ee-docs-demos/something'
blob = ee.Blob(url)
blob_func = ee.ApiFunction.lookup('Blob')
self.assertEqual(blob_func, blob.func)
self.assertFalse(blob.isVariable())
self.assertEqual({'url': url}, blob.args)
result = json.loads(blob.serialize())
expect = {
'result': '0',
'values': {
'0': {
'functionInvocationValue': {
'arguments': {
'url': {'constantValue': url}
},
'functionName': 'Blob',
}
}
},
}
self.assertEqual(expect, result)
def test_wrong_arg_type(self):
message = 'Blob url must be a string: <class \'int\'> -> "123"'
with self.assertRaisesRegex(ValueError, message):
ee.Blob(123) # pytype: disable=wrong-arg-types
def test_does_not_start_with_gs(self):
url = 'http://example.com/something'
message = f'Blob url must start with "gs://": "{url}"'
with self.assertRaisesRegex(ValueError, message):
ee.Blob(url)
if __name__ == '__main__':
unittest.main()