Skip to content
Draft
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
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']

steps:
- uses: actions/checkout@v2
Expand Down
19 changes: 0 additions & 19 deletions .travis.yml

This file was deleted.

12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,18 @@ pre-commit: .git/hooks/pre-commit ## Create the pre-commit hook
# Linting and code analysis
.PHONY: black
black: venv ## Format the code using black
$(BLACK) --safe --line-length 120 --target-version py35 $(PACKAGE_DIR)
$(BLACK) --safe --line-length 120 --target-version py35 $(TEST_DIR)
$(BLACK) --safe --line-length 120 --target-version py39 $(PACKAGE_DIR)
$(BLACK) --safe --line-length 120 --target-version py39 $(TEST_DIR)
ifneq ("$(wildcard setup.py)", "")
$(BLACK) --safe --line-length 120 --target-version py35 setup.py
$(BLACK) --safe --line-length 120 --target-version py39 setup.py
endif

.PHONY: lint-black
lint-black: venv ## Check that the code is formatted using black
$(BLACK) --check --line-length 120 --safe --target-version py35 $(PACKAGE_DIR)
$(BLACK) --check --line-length 120 --safe --target-version py35 $(TEST_DIR)
$(BLACK) --check --line-length 120 --safe --target-version py39 $(PACKAGE_DIR)
$(BLACK) --check --line-length 120 --safe --target-version py39 $(TEST_DIR)
ifneq ("$(wildcard setup.py)", "")
$(BLACK) --check --line-length 120 --safe --target-version py35 setup.py
$(BLACK) --check --line-length 120 --safe --target-version py39 setup.py
endif

.PHONY: lint-flake8
Expand Down
4 changes: 1 addition & 3 deletions androidtv/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""Exceptions for use throughout the code.

"""
"""Exceptions for use throughout the code."""


class LockNotAcquiredException(Exception):
Expand Down
26 changes: 16 additions & 10 deletions tests/test_adb_manager_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,9 @@ async def test_adb_shell_fail_lock_released(self):
with async_patchers.patch_connect(True)[self.PATCH_KEY], async_patchers.patch_shell("TEST")[self.PATCH_KEY]:
self.assertTrue(await self.adb.connect())

with async_patchers.patch_shell("TEST", error=True)[self.PATCH_KEY], patch.object(
self.adb, "_adb_lock", AsyncFakeLock()
with (
async_patchers.patch_shell("TEST", error=True)[self.PATCH_KEY],
patch.object(self.adb, "_adb_lock", AsyncFakeLock()),
):
with patch("{}.AsyncFakeLock.release".format(__name__)) as release:
with self.assertRaises(Exception):
Expand Down Expand Up @@ -261,8 +262,9 @@ async def test_adb_screencap_lock_not_acquired(self):
self.assertTrue(await self.adb.connect())
self.assertEqual(await self.adb.shell("TEST"), "TEST")

with async_patchers.patch_shell(PNG_IMAGE)[self.PATCH_KEY], patch.object(
self.adb, "_adb_lock", AsyncLockedLock()
with (
async_patchers.patch_shell(PNG_IMAGE)[self.PATCH_KEY],
patch.object(self.adb, "_adb_lock", AsyncLockedLock()),
):
with patch("{}.AsyncLockedLock.release".format(__name__)) as release:
with self.assertRaises(LockNotAcquiredException):
Expand Down Expand Up @@ -332,9 +334,11 @@ def setUp(self):
@awaiter
async def test_connect_success_with_priv_key(self):
"""Test when the connect attempt is successful when using a private key."""
with async_patchers.patch_connect(True)[self.PATCH_KEY], patch(
"androidtv.adb_manager.adb_manager_async.aiofiles.open", open_priv
), patch("androidtv.adb_manager.adb_manager_async.PythonRSASigner", return_value="TEST"):
with (
async_patchers.patch_connect(True)[self.PATCH_KEY],
patch("androidtv.adb_manager.adb_manager_async.aiofiles.open", open_priv),
patch("androidtv.adb_manager.adb_manager_async.PythonRSASigner", return_value="TEST"),
):
self.assertTrue(await self.adb.connect())
self.assertTrue(self.adb.available)

Expand All @@ -347,9 +351,11 @@ async def test_connect_success_with_priv_key(self):
@awaiter
async def test_connect_success_with_priv_pub_key(self):
"""Test when the connect attempt is successful when using private and public keys."""
with async_patchers.patch_connect(True)[self.PATCH_KEY], patch(
"androidtv.adb_manager.adb_manager_async.aiofiles.open", open_priv_pub
), patch("androidtv.adb_manager.adb_manager_async.PythonRSASigner", return_value=None):
with (
async_patchers.patch_connect(True)[self.PATCH_KEY],
patch("androidtv.adb_manager.adb_manager_async.aiofiles.open", open_priv_pub),
patch("androidtv.adb_manager.adb_manager_async.PythonRSASigner", return_value=None),
):
self.assertTrue(await self.adb.connect())
self.assertTrue(self.adb.available)

Expand Down
16 changes: 10 additions & 6 deletions tests/test_adb_manager_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,11 @@ def setUp(self):

def test_connect_success_with_priv_key(self):
"""Test when the connect attempt is successful when using a private key."""
with patchers.patch_connect(True)[self.PATCH_KEY], patch(
"androidtv.adb_manager.adb_manager_sync.open", open_priv
), patch("androidtv.adb_manager.adb_manager_sync.PythonRSASigner", return_value="TEST"):
with (
patchers.patch_connect(True)[self.PATCH_KEY],
patch("androidtv.adb_manager.adb_manager_sync.open", open_priv),
patch("androidtv.adb_manager.adb_manager_sync.PythonRSASigner", return_value="TEST"),
):
self.assertTrue(self.adb.connect())
self.assertTrue(self.adb.available)

Expand All @@ -309,9 +311,11 @@ def test_connect_success_with_priv_key(self):

def test_connect_success_with_priv_pub_key(self):
"""Test when the connect attempt is successful when using private and public keys."""
with patchers.patch_connect(True)[self.PATCH_KEY], patch(
"androidtv.adb_manager.adb_manager_sync.open", open_priv_pub
), patch("androidtv.adb_manager.adb_manager_sync.PythonRSASigner", return_value=None):
with (
patchers.patch_connect(True)[self.PATCH_KEY],
patch("androidtv.adb_manager.adb_manager_sync.open", open_priv_pub),
patch("androidtv.adb_manager.adb_manager_sync.PythonRSASigner", return_value=None),
):
self.assertTrue(self.adb.connect())
self.assertTrue(self.adb.available)

Expand Down
73 changes: 32 additions & 41 deletions tests/test_androidtv_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ class TestAndroidTVAsyncPython(unittest.TestCase):

@awaiter
async def setUp(self):
with async_patchers.PATCH_ADB_DEVICE_TCP, async_patchers.patch_connect(True)[
self.PATCH_KEY
], async_patchers.patch_shell("")[self.PATCH_KEY]:
with (
async_patchers.PATCH_ADB_DEVICE_TCP,
async_patchers.patch_connect(True)[self.PATCH_KEY],
async_patchers.patch_shell("")[self.PATCH_KEY],
):
self.atv = AndroidTVAsync("HOST", 5555)
await self.atv.adb_connect()

Expand Down Expand Up @@ -105,11 +107,12 @@ async def test_running_apps(self):
async def test_stream_music_properties(self):
"""Check that the ``stream_music_properties`` method works correctly."""
with async_patchers.patch_shell(None)[self.PATCH_KEY]:
with patch_calls(self.atv, self.atv._audio_output_device) as audio_output_device, patch_calls(
self.atv, self.atv._is_volume_muted
) as is_volume_muted, patch_calls(self.atv, self.atv._volume) as volume, patch_calls(
self.atv, self.atv._volume_level
) as volume_level:
with (
patch_calls(self.atv, self.atv._audio_output_device) as audio_output_device,
patch_calls(self.atv, self.atv._is_volume_muted) as is_volume_muted,
patch_calls(self.atv, self.atv._volume) as volume,
patch_calls(self.atv, self.atv._volume_level) as volume_level,
):
await self.atv.stream_music_properties()
assert audio_output_device.called
assert is_volume_muted.called
Expand Down Expand Up @@ -220,51 +223,39 @@ async def test_volume_down(self):
async def test_get_properties(self):
"""Check that ``get_properties()`` works correctly."""
with async_patchers.patch_shell(None)[self.PATCH_KEY]:
with patch_calls(
self.atv, self.atv.screen_on_awake_wake_lock_size
) as screen_on_awake_wake_lock_size, patch_calls(
self.atv, self.atv.current_app_media_session_state
) as current_app_media_session_state, patch_calls(
self.atv, self.atv.stream_music_properties
) as stream_music_properties, patch_calls(
self.atv, self.atv.running_apps
) as running_apps, patch_calls(
self.atv, self.atv.get_hdmi_input
) as get_hdmi_input:
with (
patch_calls(self.atv, self.atv.screen_on_awake_wake_lock_size) as screen_on_awake_wake_lock_size,
patch_calls(self.atv, self.atv.current_app_media_session_state) as current_app_media_session_state,
patch_calls(self.atv, self.atv.stream_music_properties) as stream_music_properties,
patch_calls(self.atv, self.atv.running_apps) as running_apps,
patch_calls(self.atv, self.atv.get_hdmi_input) as get_hdmi_input,
):
await self.atv.get_properties(lazy=True)
assert screen_on_awake_wake_lock_size.called
assert not current_app_media_session_state.called
assert not running_apps.called
assert not get_hdmi_input.called

with patch_calls(
self.atv, self.atv.screen_on_awake_wake_lock_size
) as screen_on_awake_wake_lock_size, patch_calls(
self.atv, self.atv.current_app_media_session_state
) as current_app_media_session_state, patch_calls(
self.atv, self.atv.stream_music_properties
) as stream_music_properties, patch_calls(
self.atv, self.atv.running_apps
) as running_apps, patch_calls(
self.atv, self.atv.get_hdmi_input
) as get_hdmi_input:
with (
patch_calls(self.atv, self.atv.screen_on_awake_wake_lock_size) as screen_on_awake_wake_lock_size,
patch_calls(self.atv, self.atv.current_app_media_session_state) as current_app_media_session_state,
patch_calls(self.atv, self.atv.stream_music_properties) as stream_music_properties,
patch_calls(self.atv, self.atv.running_apps) as running_apps,
patch_calls(self.atv, self.atv.get_hdmi_input) as get_hdmi_input,
):
await self.atv.get_properties(lazy=False, get_running_apps=True)
assert screen_on_awake_wake_lock_size.called
assert current_app_media_session_state.called
assert running_apps.called
assert get_hdmi_input.called

with patch_calls(
self.atv, self.atv.screen_on_awake_wake_lock_size
) as screen_on_awake_wake_lock_size, patch_calls(
self.atv, self.atv.current_app_media_session_state
) as current_app_media_session_state, patch_calls(
self.atv, self.atv.stream_music_properties
) as stream_music_properties, patch_calls(
self.atv, self.atv.running_apps
) as running_apps, patch_calls(
self.atv, self.atv.get_hdmi_input
) as get_hdmi_input:
with (
patch_calls(self.atv, self.atv.screen_on_awake_wake_lock_size) as screen_on_awake_wake_lock_size,
patch_calls(self.atv, self.atv.current_app_media_session_state) as current_app_media_session_state,
patch_calls(self.atv, self.atv.stream_music_properties) as stream_music_properties,
patch_calls(self.atv, self.atv.running_apps) as running_apps,
patch_calls(self.atv, self.atv.get_hdmi_input) as get_hdmi_input,
):
await self.atv.get_properties(lazy=False, get_running_apps=False)
assert screen_on_awake_wake_lock_size.called
assert current_app_media_session_state.called
Expand Down
74 changes: 38 additions & 36 deletions tests/test_androidtv_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@ class TestAndroidTVSyncPython(unittest.TestCase):
ADB_ATTR = "_adb"

def setUp(self):
with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell("")[
self.PATCH_KEY
]:
with (
patchers.PATCH_ADB_DEVICE_TCP,
patchers.patch_connect(True)[self.PATCH_KEY],
patchers.patch_shell("")[self.PATCH_KEY],
):
self.atv = AndroidTVSync("HOST", 5555)
self.atv.adb_connect()

Expand Down Expand Up @@ -283,51 +285,51 @@ def test_volume_down(self):
def test_get_properties(self):
"""Check that ``get_properties()`` works correctly."""
with patchers.patch_shell(None)[self.PATCH_KEY]:
with patchers.patch_calls(
self.atv, self.atv.screen_on_awake_wake_lock_size
) as screen_on_awake_wake_lock_size, patchers.patch_calls(
self.atv, self.atv.current_app_media_session_state
) as current_app_media_session_state, patchers.patch_calls(
self.atv, self.atv.stream_music_properties
) as stream_music_properties, patchers.patch_calls(
self.atv, self.atv.running_apps
) as running_apps, patchers.patch_calls(
self.atv, self.atv.get_hdmi_input
) as get_hdmi_input:
with (
patchers.patch_calls(
self.atv, self.atv.screen_on_awake_wake_lock_size
) as screen_on_awake_wake_lock_size,
patchers.patch_calls(
self.atv, self.atv.current_app_media_session_state
) as current_app_media_session_state,
patchers.patch_calls(self.atv, self.atv.stream_music_properties) as stream_music_properties,
patchers.patch_calls(self.atv, self.atv.running_apps) as running_apps,
patchers.patch_calls(self.atv, self.atv.get_hdmi_input) as get_hdmi_input,
):
self.atv.get_properties(lazy=True)
assert screen_on_awake_wake_lock_size.called
assert not current_app_media_session_state.called
assert not running_apps.called
assert not get_hdmi_input.called

with patchers.patch_calls(
self.atv, self.atv.screen_on_awake_wake_lock_size
) as screen_on_awake_wake_lock_size, patchers.patch_calls(
self.atv, self.atv.current_app_media_session_state
) as current_app_media_session_state, patchers.patch_calls(
self.atv, self.atv.stream_music_properties
) as stream_music_properties, patchers.patch_calls(
self.atv, self.atv.running_apps
) as running_apps, patchers.patch_calls(
self.atv, self.atv.get_hdmi_input
) as get_hdmi_input:
with (
patchers.patch_calls(
self.atv, self.atv.screen_on_awake_wake_lock_size
) as screen_on_awake_wake_lock_size,
patchers.patch_calls(
self.atv, self.atv.current_app_media_session_state
) as current_app_media_session_state,
patchers.patch_calls(self.atv, self.atv.stream_music_properties) as stream_music_properties,
patchers.patch_calls(self.atv, self.atv.running_apps) as running_apps,
patchers.patch_calls(self.atv, self.atv.get_hdmi_input) as get_hdmi_input,
):
self.atv.get_properties(lazy=False, get_running_apps=True)
assert screen_on_awake_wake_lock_size.called
assert current_app_media_session_state.called
assert running_apps.called
assert get_hdmi_input.called

with patchers.patch_calls(
self.atv, self.atv.screen_on_awake_wake_lock_size
) as screen_on_awake_wake_lock_size, patchers.patch_calls(
self.atv, self.atv.current_app_media_session_state
) as current_app_media_session_state, patchers.patch_calls(
self.atv, self.atv.stream_music_properties
) as stream_music_properties, patchers.patch_calls(
self.atv, self.atv.running_apps
) as running_apps, patchers.patch_calls(
self.atv, self.atv.get_hdmi_input
) as get_hdmi_input:
with (
patchers.patch_calls(
self.atv, self.atv.screen_on_awake_wake_lock_size
) as screen_on_awake_wake_lock_size,
patchers.patch_calls(
self.atv, self.atv.current_app_media_session_state
) as current_app_media_session_state,
patchers.patch_calls(self.atv, self.atv.stream_music_properties) as stream_music_properties,
patchers.patch_calls(self.atv, self.atv.running_apps) as running_apps,
patchers.patch_calls(self.atv, self.atv.get_hdmi_input) as get_hdmi_input,
):
self.atv.get_properties(lazy=False, get_running_apps=False)
assert screen_on_awake_wake_lock_size.called
assert current_app_media_session_state.called
Expand Down
8 changes: 5 additions & 3 deletions tests/test_basetv_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ class TestBaseTVAsyncPython(unittest.TestCase):

@awaiter
async def setUp(self):
with async_patchers.PATCH_ADB_DEVICE_TCP, async_patchers.patch_connect(True)[
self.PATCH_KEY
], async_patchers.patch_shell("")[self.PATCH_KEY]:
with (
async_patchers.PATCH_ADB_DEVICE_TCP,
async_patchers.patch_connect(True)[self.PATCH_KEY],
async_patchers.patch_shell("")[self.PATCH_KEY],
):
self.btv = BaseTVAsync("HOST", 5555)
await self.btv.adb_connect()

Expand Down
Loading