Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS tests - audio, battery, bluetooth, storagepath #482

Merged
merged 11 commits into from
Dec 25, 2018
Prev Previous commit
Next Next commit
Added macOS battery and bluetooth instance tests
  • Loading branch information
Nephyx authored and KeyWeeUsr committed Dec 24, 2018
commit b3ff8ace3a506e78380917c394c2d895ed77530e
25 changes: 23 additions & 2 deletions plyer/tests/test_battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def percentage():
current_capacity = int(MockedIOReg.values['CurrentCapacity'])
max_capacity = int(MockedIOReg.values['MaxCapacity'])
percentage = 100.0 * current_capacity / max_capacity

return percentage

class TestBattery(unittest.TestCase):
Expand Down Expand Up @@ -368,7 +368,7 @@ def test_battery_win(self):
for key in ('isCharging', 'percentage'):
self.assertIn(key, battery.status)
self.assertIsNotNone(battery.status[key])

def test_battery_macosx(self):
'''
Test macOS IOReg for plyer.battery.
Expand All @@ -379,7 +379,9 @@ def test_battery_macosx(self):
whereis_exe=MockedIOReg.whereis_exe
)
battery.Popen = MockedIOReg
self.assertIn('OSXBattery', dir(battery))
battery = battery.instance()
self.assertIn('OSXBattery', str(battery))

self.assertEqual(
battery.status, {
Expand All @@ -388,5 +390,24 @@ def test_battery_macosx(self):
}
)

def test_battery_macosx_instance(self):
'''
Test macOS instance for plyer.battery
'''

def no_exe(*args, **kwargs):
return

battery = platform_import(
platform='macosx',
module_name='battery',
whereis_exe=no_exe
)

battery = battery.instance()
self.assertNotIn('OSXBattery', str(battery))
self.assertIn('Battery', str(battery))


if __name__ == '__main__':
unittest.main()
35 changes: 30 additions & 5 deletions plyer/tests/test_bluetooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class MockedSystemProfiler(object):
Address: AA-00-BB-11-CC-22
Major Type: Miscellaneous
Minor Type: Unknown
Services:
Services:
Paired: No
Configured: Yes
Connected: No
Expand Down Expand Up @@ -102,14 +102,39 @@ def test_bluetooth_macosx(self):
Test macOS system_profiler for plyer.bluetooth.
'''
bluetooth = platform_import(
platform='macosx',
module_name='bluetooth',
whereis_exe=MockedSystemProfiler.whereis_exe
platform='macosx',
module_name='bluetooth',
whereis_exe=MockedSystemProfiler.whereis_exe
)

bluetooth.Popen = MockedSystemProfiler
self.assertIn('OSXBluetooth', dir(bluetooth))
bluetooth = bluetooth.instance()
self.assertIn('OSXBluetooth', str(bluetooth))

self.assertEqual(
bluetooth.info, MockedSystemProfiler.get_info()
)
)


def test_bluetooth_macosx_instance(self):
'''
Test macOS instance for plyer.bluetooth.
'''

def no_exe(*args, **kwargs):
return

bluetooth = platform_import(
platform='macosx',
module_name='bluetooth',
whereis_exe=no_exe
)

bluetooth = bluetooth.instance()
self.assertNotIn('OSXBluetooth', str(bluetooth))
self.assertIn('Bluetooth', str(bluetooth))


if __name__ == '__main__':
unittest.main()