Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelina-C committed Jun 11, 2024
1 parent 3fdbbaa commit 6155ef8
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 23 deletions.
10 changes: 0 additions & 10 deletions adb_pywrapper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,9 @@
from os.path import dirname, abspath, isdir, expanduser
from sys import stdout

from adb_pywrapper.adb_device import AdbDevice
from adb_pywrapper.adb_result import AdbResult
from adb_pywrapper.adb_screen_recorder import AdbScreenRecorder
from adb_pywrapper.pull_result import PullResult

logger = logging.getLogger(__name__)

__all__ = [
'AdbResult',
'PullResult',
'AdbDevice',
'AdbScreenRecorder',
]
###########################
# ADB INITIALISATION CODE #
###########################
Expand Down
4 changes: 3 additions & 1 deletion adb_pywrapper/adb_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
from time import sleep
from typing import Optional

from adb_pywrapper import logger, log_error_and_raise_exception, ADB_PATH, AdbResult, PullResult
from adb_pywrapper import logger, log_error_and_raise_exception, ADB_PATH
from adb_pywrapper.adb_result import AdbResult
from adb_pywrapper.pull_result import PullResult


class AdbDevice:
Expand Down
3 changes: 2 additions & 1 deletion adb_pywrapper/adb_screen_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from time import sleep
from uuid import uuid4

from adb_pywrapper import log_error_and_raise_exception, logger, ADB_PATH, AdbDevice
from adb_pywrapper import log_error_and_raise_exception, logger, ADB_PATH
from adb_pywrapper.adb_device import AdbDevice


class AdbScreenRecorder:
Expand Down
2 changes: 1 addition & 1 deletion adb_pywrapper/pull_result.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

from adb_pywrapper import AdbResult
from adb_pywrapper.adb_result import AdbResult


class PullResult:
Expand Down
21 changes: 11 additions & 10 deletions test/test_adb_pywrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import unittest
from unittest.mock import patch, Mock

from adb_pywrapper import AdbResult, AdbDevice
from adb_pywrapper.adb_device import AdbDevice
from adb_pywrapper.adb_result import AdbResult

PROCESS = subprocess.run('echo hello', shell=True, capture_output=True)
MOCK_SUCCESSFULLY_PULLED_FILE = ['abc.apk', 'bla.jpg']
Expand Down Expand Up @@ -319,7 +320,7 @@ def test_get_state(self):
self.assertFalse(result.success)
self.assertIn('Invalid command', result.stderr)

@patch('adb_pywrapper.AdbDevice._snapshot_command')
@patch('adb_pywrapper.adb_device.AdbDevice._snapshot_command')
def test_emulator_snapshots_list(self, mock_snapshot_command):
# Test emulator_snapshots_list function
snapshot_list_output = """List of snapshots present on all disks:
Expand All @@ -334,8 +335,8 @@ def test_emulator_snapshots_list(self, mock_snapshot_command):
mock_snapshot_command.assert_called_once_with('list')
self.assertEqual(result, ['snap_2023-11-23_13-13-02', 'snap_2023-12-05_12-56-56'])

@patch('adb_pywrapper.AdbDevice._snapshot_exists')
@patch('adb_pywrapper.AdbDevice._snapshot_command')
@patch('adb_pywrapper.adb_device.AdbDevice._snapshot_exists')
@patch('adb_pywrapper.adb_device.AdbDevice._snapshot_command')
def test_emulator_snapshot_load_existing(self, mock_snapshot_command, mock_snapshot_exists):
# Test emulator_snapshot_load function with an existing snapshot
mock_snapshot_exists.return_value = True
Expand All @@ -346,7 +347,7 @@ def test_emulator_snapshot_load_existing(self, mock_snapshot_command, mock_snaps
mock_snapshot_exists.assert_called_once_with('snapshot1')
mock_snapshot_command.assert_called_once_with('load', 'snapshot1')

@patch('adb_pywrapper.AdbDevice._snapshot_exists')
@patch('adb_pywrapper.adb_device.AdbDevice._snapshot_exists')
def test_emulator_snapshot_load_non_existing(self, mock_snapshot_exists):
# Test emulator_snapshot_load function with a non-existing snapshot
mock_snapshot_exists.return_value = False
Expand All @@ -356,8 +357,8 @@ def test_emulator_snapshot_load_non_existing(self, mock_snapshot_exists):
mock_snapshot_exists.assert_called_once_with('non_existing_snapshot')
self.assertFalse(result.success)

@patch('adb_pywrapper.AdbDevice._snapshot_exists')
@patch('adb_pywrapper.AdbDevice._snapshot_command')
@patch('adb_pywrapper.adb_device.AdbDevice._snapshot_exists')
@patch('adb_pywrapper.adb_device.AdbDevice._snapshot_command')
def test_emulator_snapshot_save(self, mock_snapshot_command, mock_snapshot_exists):
# Test emulator_snapshot_save function
mock_snapshot_exists.return_value = False
Expand All @@ -368,9 +369,9 @@ def test_emulator_snapshot_save(self, mock_snapshot_command, mock_snapshot_exist
mock_snapshot_exists.assert_called_once_with('snapshot1')
mock_snapshot_command.assert_called_once_with('save', 'snapshot1')

@patch('adb_pywrapper.AdbDevice.emulator_snapshots_list', return_value=['snapshot1', 'snapshot2'])
@patch('adb_pywrapper.AdbDevice._snapshot_exists')
@patch('adb_pywrapper.AdbDevice._snapshot_command')
@patch('adb_pywrapper.adb_device.AdbDevice.emulator_snapshots_list', return_value=['snapshot1', 'snapshot2'])
@patch('adb_pywrapper.adb_device.AdbDevice._snapshot_exists')
@patch('adb_pywrapper.adb_device.AdbDevice._snapshot_command')
def test_emulator_snapshot_delete(self, mock_snapshot_command, mock_snapshot_exists, mock_emulator_snapshots_list):
# Test emulator_snapshot_delete function
mock_snapshot_exists.return_value = True # Existing snapshots
Expand Down

0 comments on commit 6155ef8

Please sign in to comment.