Skip to content

Commit 49da66f

Browse files
authored
Merge pull request #131 from planetlabs/fix-make-check
Fix make check
2 parents ed73ef9 + b804c90 commit 49da66f

File tree

6 files changed

+20
-21
lines changed

6 files changed

+20
-21
lines changed

planet/api/_fatomic.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ def atomic_open(filename, mode, *args, **kwargs):
5252
dir=os.path.dirname(filename),
5353
suffix='.tmp',
5454
delete=False)
55-
_discard = [False]
55+
# track: explicitly discarded, normal/abnormal completion
56+
_discard = [None]
5657
try:
5758
if mode[0] == 'a':
5859
try:
@@ -63,17 +64,18 @@ def atomic_open(filename, mode, *args, **kwargs):
6364
pass
6465

6566
def discard(self, _discard=_discard):
67+
# explicit discard
6668
_discard[0] = True
6769
f.discard = types.MethodType(discard, f)
6870
yield f
69-
# ischneider addition to fatomic - catch/raise any exception thrown in with
71+
# normal completion
72+
if not _discard[0]:
73+
_discard[0] = False
7074
# block and force discarding
71-
except:
72-
_discard = [True]
73-
raise
7475
finally:
7576
f.close()
76-
if _discard[0]:
77+
# if we didn't complete or were aborted, delete
78+
if _discard[0] is None or _discard[0]:
7779
os.unlink(f.name)
7880
else:
7981
_replace_file(f.name, filename)

planet/api/downloader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from planet.api.exceptions import RequestCancelled
2020
try:
2121
import Queue as queue
22-
except:
22+
except ImportError:
2323
# renamed in 3
2424
import queue
2525

planet/scripts/item_asset_types.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# In case the API fails to respond or takes too long.
1212
DEFAULT_ITEM_TYPES = [
1313
"PSScene4Band", "PSScene3Band", "REScene", "SkySatScene",
14-
"REOrthoTile", "Sentinel2L1C", "PSOrthoTile", "Landsat8L1G"]
14+
"REOrthoTile", "Sentinel2L1C", "PSOrthoTile", "Landsat8L1G", "Sentinel1"]
1515

1616
DEFAULT_ASSET_TYPES = [
1717
"analytic", "analytic_b1", "analytic_b10", "analytic_b11", "analytic_b12",
@@ -43,20 +43,16 @@ def _get_json_or_raise(url, timeout=0.7):
4343
def get_item_types():
4444
global _item_types
4545
if _item_types is None:
46-
try:
47-
data = _get_json_or_raise(ITEM_TYPE_URL)
48-
_item_types = [it['id'] for it in data['item_types']]
49-
except:
50-
_item_types = DEFAULT_ITEM_TYPES
46+
_item_types = DEFAULT_ITEM_TYPES
47+
data = _get_json_or_raise(ITEM_TYPE_URL)
48+
_item_types = [it['id'] for it in data['item_types']]
5149
return _item_types
5250

5351

5452
def get_asset_types():
5553
global _asset_types
5654
if _asset_types is None:
57-
try:
58-
data = _get_json_or_raise(ASSET_TYPE_URL)
59-
_asset_types = [a['id'] for a in data['asset_types']]
60-
except:
61-
_asset_types = DEFAULT_ASSET_TYPES
55+
_asset_types = DEFAULT_ASSET_TYPES
56+
data = _get_json_or_raise(ASSET_TYPE_URL)
57+
_asset_types = [a['id'] for a in data['asset_types']]
6258
return _asset_types

tests/test_atomic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def assert_content_is(expected):
3737
with atomic_open(outfile, 'w') as fp:
3838
fp.write('bazzy')
3939
raise Exception('drat')
40-
except:
40+
except Exception:
4141
assert_content_is('bar')
4242
else:
4343
assert False

tests/test_types.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ def test_item_type():
3333
check('all', get_item_types())
3434
check('psscene', ['PSScene3Band', 'PSScene4Band'])
3535
check('Sentinel2L1C', ['Sentinel2L1C'])
36-
check('psscene,sent', ['PSScene3Band', 'PSScene4Band', 'Sentinel2L1C'])
36+
check('psscene,sent', ['PSScene3Band', 'PSScene4Band',
37+
'Sentinel1', 'Sentinel2L1C'])
3738

3839
with pytest.raises(Exception) as e:
3940
ItemType().convert('x', None, None)

tests/test_v1_cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def assert_success(result, expected_output, exit_code=0):
3939
pass
4040
try:
4141
assert json.loads(result.output) == expected_output
42-
except:
42+
except ValueError:
4343
assert result.output == expected_output
4444

4545

0 commit comments

Comments
 (0)