Skip to content

Commit

Permalink
fix linter errors & ignore unwanted errors in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
seamus-sloan committed Oct 23, 2023
1 parent c3f72c8 commit 977c808
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 26 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"cSpell.words": [
"capsys",
"sadb",
"scrcpy",
"screencap",
Expand Down
3 changes: 3 additions & 0 deletions sadb.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"""Module for controlling multiple android devices at once with adb"""
#!/usr/bin/python3

#pylint: disable=subprocess-run-check, unspecified-encoding

# Created by: Seamus Sloan
# Last Edited: July 10, 2023

Expand Down
10 changes: 6 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Test all functions are sending the correct commands"""
#!/usr/bin/python3

#pylint: disable=missing-function-docstring, wrong-import-position
# Created by: Seamus Sloan
# Last Edited: July 10, 2023

Expand All @@ -9,14 +11,14 @@
DEVICE_IDS = ["FA79J1A00421", "ZY223TDZ43", "HT4CJ0203660", "R58M45YME1R", "emulator-5554"]

@pytest.fixture
def testDeviceList():
def test_device_list():
return DEVICE_IDS

@pytest.fixture
def testDevices():
def _testDevices(number_of_devices):
def test_devices():
def _test_devices(number_of_devices):
result = "List of devices attached\n"
for i in range(number_of_devices):
result += DEVICE_IDS[i] + "\tdevice\n"
return result
return _testDevices
return _test_devices
3 changes: 3 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"""Test all functions are sending the correct commands"""
#!/usr/bin/python3

#pylint: disable=missing-function-docstring, wrong-import-position

# Created by: Seamus Sloan
# Last Edited: July 10, 2023

Expand Down
19 changes: 11 additions & 8 deletions tests/test_get_devices.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
"""Test get devices is returning the correct devices"""
#!/usr/bin/python3

#pylint: disable=missing-function-docstring, wrong-import-position

# Created by: Seamus Sloan
# Last Edited: July 10, 2023

import sys
sys.path.append("..")
from sadb import split_get_devices

def test_get_devices_returns_correct_three_devices(testDevices):
devices = split_get_devices(testDevices(3))
def test_get_devices_returns_correct_three_devices(test_devices):
devices = split_get_devices(test_devices(3))
print(devices)
assert devices == ['FA79J1A00421', 'ZY223TDZ43', 'HT4CJ0203660']


def test_get_devices_returns_correct_five_devices(testDevices):
devices = split_get_devices(testDevices(5))
def test_get_devices_returns_correct_five_devices(test_devices):
devices = split_get_devices(test_devices(5))
print(devices)
assert devices == ["FA79J1A00421", "ZY223TDZ43",
"HT4CJ0203660", "R58M45YME1R", "emulator-5554"]


def test_get_devices_returns_correct_single_device(testDevices):
devices = split_get_devices(testDevices(1))
def test_get_devices_returns_correct_single_device(test_devices):
devices = split_get_devices(test_devices(1))
print(devices)
assert devices == ['FA79J1A00421']


def test_get_devices_returns_correct_no_devices(testDevices):
devices = split_get_devices(testDevices(0))
def test_get_devices_returns_correct_no_devices(test_devices):
devices = split_get_devices(test_devices(0))
print(devices)
assert devices == []
31 changes: 17 additions & 14 deletions tests/test_select_device.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
"""Test device selection is working as expected"""
#!/usr/bin/python3

#pylint: disable=missing-function-docstring, wrong-import-position

# Created by: Seamus Sloan
# Last Edited: July 10, 2023

import sys
sys.path.append("..")
from sadb import select_device

def test_select_one_device(monkeypatch, testDeviceList):
def test_select_one_device(monkeypatch, test_device_list):
monkeypatch.setattr('builtins.input', lambda _: 1)

device = select_device(testDeviceList)
device = select_device(test_device_list)
assert device == "FA79J1A00421"


def test_select_second_device(monkeypatch, testDeviceList):
def test_select_second_device(monkeypatch, test_device_list):
monkeypatch.setattr('builtins.input', lambda _: 2)

device = select_device(testDeviceList)
device = select_device(test_device_list)
assert device == "ZY223TDZ43"


def test_select_all_devices(monkeypatch, testDeviceList):
monkeypatch.setattr('builtins.input', lambda _: len(testDeviceList) + 1)
def test_select_all_devices(monkeypatch, test_device_list):
monkeypatch.setattr('builtins.input', lambda _: len(test_device_list) + 1)

device = select_device(testDeviceList, allow_all=True)
assert device == testDeviceList
device = select_device(test_device_list, allow_all=True)
assert device == test_device_list


def test_display_of_no_devices(capsys):
Expand All @@ -34,14 +37,14 @@ def test_display_of_no_devices(capsys):
assert captured.out == "No devices found\n"


def test_display_of_one_device(testDeviceList):
devices = [testDeviceList[0]]
def test_display_of_one_device(test_device_list):
devices = [test_device_list[0]]
assert select_device(devices) == "FA79J1A00421"


def test_select_device_multiple_devices(monkeypatch, capsys, testDeviceList):
def test_select_device_multiple_devices(monkeypatch, capsys, test_device_list):
monkeypatch.setattr('builtins.input', lambda _: "1")
select_device(testDeviceList)
select_device(test_device_list)
captured = capsys.readouterr()
assert captured.out == """Select a device:
1. FA79J1A00421
Expand All @@ -52,9 +55,9 @@ def test_select_device_multiple_devices(monkeypatch, capsys, testDeviceList):
"""


def test_display_of_multiple_devices_allow_all(monkeypatch, capsys, testDeviceList):
def test_display_of_multiple_devices_allow_all(monkeypatch, capsys, test_device_list):
monkeypatch.setattr('builtins.input', lambda _: "1")
select_device(testDeviceList, allow_all=True)
select_device(test_device_list, allow_all=True)
captured = capsys.readouterr()
assert captured.out == """Select a device:
1. FA79J1A00421
Expand Down

0 comments on commit 977c808

Please sign in to comment.