Skip to content

Commit 3c1ad61

Browse files
schwehrGoogle Earth Engine Authors
authored andcommitted
batch.py: Use !r in the f-string for exceptions to use the repr of the variables
PiperOrigin-RevId: 863443403
1 parent d3ff44e commit 3c1ad61

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

python/ee/batch.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1990,12 +1990,11 @@ def _canonicalize_parameters(config: dict[str, Any], destination: str) -> None:
19901990
config.update(config['kwargs'])
19911991
del config['kwargs']
19921992

1993-
19941993
def canonicalize_name(a: str, b: str) -> None:
19951994
"""Renames config[a] to config[b]."""
19961995
if a in config:
19971996
if b in config:
1998-
raise ee_exception.EEException(f'Both {a} and {b} are specified.')
1997+
raise ee_exception.EEException(f'Both {a!r} and {b!r} are specified.')
19991998
config[b] = config.pop(a)
20001999

20012000
canonicalize_name('crsTransform', 'crs_transform')
@@ -2036,7 +2035,7 @@ def canonicalize_name(a: str, b: str) -> None:
20362035
remapped_key = remapped_key[:1].lower() + remapped_key[1:]
20372036
if remapped_key in format_options:
20382037
raise ee_exception.EEException(
2039-
f'Both {key} and {remapped_key} are specified.'
2038+
f'Both {key!r} and {remapped_key!r} are specified.'
20402039
)
20412040
format_options[remapped_key] = value
20422041
keys_to_delete.append(key)

python/ee/tests/batch_test.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,27 @@ def test_export_image_with_tf_record_cloud_api(self):
397397
task.config,
398398
)
399399

400+
def test_canonicalize_parameters_collision(self):
401+
"""Verifies canonicalize_name collision raises an error."""
402+
config = {'crsTransform': 1, 'crs_transform': 2}
403+
with self.assertRaisesRegex(
404+
ee.EEException, "Both 'crsTransform' and 'crs_transform' are specified."
405+
):
406+
batch._canonicalize_parameters(config, batch.Task.ExportDestination.DRIVE)
407+
408+
def test_canonicalize_parameters_tiff_collision(self):
409+
"""Verifies formatOptions collision raises an error."""
410+
config = {
411+
'fileFormat': 'GeoTIFF',
412+
'tiffCloudOptimized': True,
413+
'formatOptions': {'cloudOptimized': True},
414+
}
415+
with self.assertRaisesRegex(
416+
ee.EEException,
417+
"Both 'tiffCloudOptimized' and 'cloudOptimized' are specified.",
418+
):
419+
batch._canonicalize_parameters(config, batch.Task.ExportDestination.GCS)
420+
400421
def test_export_image_to_asset_cloud_api(self):
401422
"""Verifies the Asset export task created by Export.image.toAsset()."""
402423
with apitestcase.UsingCloudApi():

0 commit comments

Comments
 (0)