Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion android_env/components/adb_call_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,15 @@ def _install_apk(
['install', '-r', '-t', '-g', fpath], timeout=timeout
)
case 'blob':
with tempfile.NamedTemporaryFile(suffix='.apk') as f:

# `delete_on_close` was only added in Python 3.12 so we add a switch
# here to still support previous Python versions.
if sys.version_info >= (3, 12):
kwargs = {'suffix': '.apk', 'delete_on_close': False}
else:
kwargs = {'suffix': '.apk'}

with tempfile.NamedTemporaryFile(**kwargs) as f:
fpath = f.name
f.write(install_apk.blob.contents)

Expand Down
7 changes: 6 additions & 1 deletion android_env/components/adb_call_parser_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,13 @@ def test_install_apk_from_blob(self, mock_tempfile):
['install', '-r', '-t', '-g', '/my/home/test.apk'], None
)
# pytype: disable=attribute-error
expected_tempfile_kwargs = (
{'suffix': '.apk', 'delete_on_close': False}
if sys.version_info > (3, 12)
else {'suffix': '.apk'}
)
mock_tempfile.assert_has_calls([
mock.call(suffix='.apk'), # Constructor
mock.call(**expected_tempfile_kwargs), # Constructor
mock.call().__enter__(), # Enter context
mock.call().__enter__().write(blob_content), # Call write function
mock.call().__exit__(None, None, None), # Exit context
Expand Down