<NME> test_bluetooth.py
<BEF> '''
TestBluetooth
=============

Tested platforms:

* macOS - system_profiler
'''

import unittest

from plyer.tests.common import platform_import
from textwrap import dedent


class MockedSystemProfiler:
    '''
    Mocked object used instead of Apple's system_profiler
    '''
    value = "On"
    output = dedent(
        """Bluetooth:

      Apple Bluetooth Software Version: 6.0.7f11
      Hardware, Features, and Settings:
          Address: AA-00-BB-11-CC-22
          Bluetooth Low Energy Supported: Yes
          Handoff Supported: Yes
          Instant Hot Spot Supported: Yes
          Manufacturer: Broadcom
          Transport: UART
          Chipset: 1234
          Firmware Version: v00 c0000
          Bluetooth Power: {}
          Auto Seek Pointing: On
          Remote wake: On
          Vendor ID: 0x0000
          Product ID: 0x0000
          HCI Version:  (0x0)
          HCI Revision: 0x0000
          LMP Version:  (0x0)
          LMP Subversion: 0x0000
              Address: AA-00-BB-11-CC-22
              Major Type: Miscellaneous
              Minor Type: Unknown
              Services: 
              Paired: No
              Configured: Yes
              Connected: No
              Paired: No
              Configured: Yes
              Connected: No
              Class of Device: 0x00 0x00 0x0000
      Services:
          Bluetooth File Transfer:
              Folder other devices can browse: ~/Public
              When receiving items: Accept all without warning
              State: Disabled
          Bluetooth File Exchange:
              Folder for accepted items: ~/Downloads
              When other items are accepted: Save to location
              When receiving items: Accept all without warning
              State: Disabled
          Bluetooth Internet Sharing:
              State: Disabled
      Incoming Serial Ports:
          Bluetooth-Incoming-Port:
              RFCOMM Channel: 3
              Requires Authentication: No"""
    ).format(value).encode('utf-8')

    def __init__(self, *args, **kwargs):
        # only to ignore all args, kwargs
        pass

    @staticmethod
    def communicate():
        '''
        Mock Popen.communicate, so that 'system_profiler'
        isn't used.
        '''
        return (MockedSystemProfiler.output, )

    @staticmethod
    def whereis_exe(binary):
        '''
        Mock whereis_exe, so that it looks like
        macOS system_profiler binary is present on the system.
        '''
        return binary == 'system_profiler'

    @staticmethod
    def get_info():
        '''
        Return current bluetooth status from mocked output.
        '''
        return MockedSystemProfiler.value


class TestBluetooth(unittest.TestCase):
    '''
        Test macOS system_profiler for plyer.bluetooth.
        '''
        bluetooth = platform_import(
        platform='macosx',
        module_name='bluetooth',
        whereis_exe=MockedSystemProfiler.whereis_exe
        )

        bluetooth.Popen = MockedSystemProfiler
        bluetooth = bluetooth.instance()

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


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

<MSG> Added macOS battery and bluetooth instance tests

<DFF> @@ -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
@@ -102,14 +102,39 @@ class TestBluetooth(unittest.TestCase):
         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()
-        )
\ No newline at end of file
+        )
+
+
+    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()

{'commit': "diff --git a/plyer/tests/test_battery.py b/plyer/tests/test_battery.py\nindex 18888af..6a70780 100644\n--- a/plyer/tests/test_battery.py\n+++ b/plyer/tests/test_battery.py\n@@ -286,7 +286,7 @@ class MockedIOReg(object):\n         current_capacity = int(MockedIOReg.values['CurrentCapacity'])\n         max_capacity = int(MockedIOReg.values['MaxCapacity'])\n         percentage =  100.0 * current_capacity / max_capacity\n-        \n+\n         return percentage\n \n class TestBattery(unittest.TestCase):\n@@ -368,7 +368,7 @@ class TestBattery(unittest.TestCase):\n         for key in ('isCharging', 'percentage'):\n             self.assertIn(key, battery.status)\n             self.assertIsNotNone(battery.status[key])\n-    \n+\n     def test_battery_macosx(self):\n         '''\n         Test macOS IOReg for plyer.battery.\n@@ -379,7 +379,9 @@ class TestBattery(unittest.TestCase):\n             whereis_exe=MockedIOReg.whereis_exe\n         )\n         battery.Popen = MockedIOReg\n+        self.assertIn('OSXBattery', dir(battery))\n         battery = battery.instance()\n+        self.assertIn('OSXBattery', str(battery))\n \n         self.assertEqual(\n             battery.status, {\n@@ -388,5 +390,24 @@ class TestBattery(unittest.TestCase):\n             }\n         )\n \n+    def test_battery_macosx_instance(self):\n+        '''\n+        Test macOS instance for plyer.battery\n+        '''\n+\n+        def no_exe(*args, **kwargs):\n+            return\n+\n+        battery = platform_import(\n+            platform='macosx',\n+            module_name='battery',\n+            whereis_exe=no_exe\n+        )\n+\n+        battery = battery.instance()\n+        self.assertNotIn('OSXBattery', str(battery))\n+        self.assertIn('Battery', str(battery))\n+\n+\n if __name__ == '__main__':\n     unittest.main()\ndiff --git a/plyer/tests/test_bluetooth.py b/plyer/tests/test_bluetooth.py\nindex 5aa4cf1..bc61a84 100644\n--- a/plyer/tests/test_bluetooth.py\n+++ b/plyer/tests/test_bluetooth.py\n@@ -43,7 +43,7 @@ class MockedSystemProfiler(object):\n               Address: AA-00-BB-11-CC-22\n               Major Type: Miscellaneous\n               Minor Type: Unknown\n-              Services: \n+              Services:\n               Paired: No\n               Configured: Yes\n               Connected: No\n@@ -102,14 +102,39 @@ class TestBluetooth(unittest.TestCase):\n         Test macOS system_profiler for plyer.bluetooth.\n         '''\n         bluetooth = platform_import(\n-        platform='macosx',\n-        module_name='bluetooth',\n-        whereis_exe=MockedSystemProfiler.whereis_exe\n+            platform='macosx',\n+            module_name='bluetooth',\n+            whereis_exe=MockedSystemProfiler.whereis_exe\n         )\n \n         bluetooth.Popen = MockedSystemProfiler\n+        self.assertIn('OSXBluetooth', dir(bluetooth))\n         bluetooth = bluetooth.instance()\n+        self.assertIn('OSXBluetooth', str(bluetooth))\n \n         self.assertEqual(\n             bluetooth.info, MockedSystemProfiler.get_info()\n-        )\n\\ No newline at end of file\n+        )\n+\n+\n+    def test_bluetooth_macosx_instance(self):\n+        '''\n+        Test macOS instance for plyer.bluetooth.\n+        '''\n+\n+        def no_exe(*args, **kwargs):\n+            return\n+\n+        bluetooth = platform_import(\n+            platform='macosx',\n+            module_name='bluetooth',\n+            whereis_exe=no_exe\n+        )\n+\n+        bluetooth = bluetooth.instance()\n+        self.assertNotIn('OSXBluetooth', str(bluetooth))\n+        self.assertIn('Bluetooth', str(bluetooth))\n+\n+\n+if __name__ == '__main__':\n+    unittest.main()\n", 'commit_subject': 'Added macOS battery and bluetooth instance tests', 'repo_name': 'kivy/plyer', 'committer': {'name': 'Peter Badida', 'email': '02235852529b35cba14f766340afbe46d9b346d1@users.noreply.github.com', 'time_sec': '1545695931', 'tz_offset': '60', 'date': {'seconds': '1545695931'}}, 'commit_tree': 'd829efb325285a56d8de37c8851020399850ef47', 'commit_message': 'Added macOS battery and bluetooth instance tests\n', 'language_name': 'Python', 'license': 'mit', 'hunks': "@@ -43,7 +43,7 @@ class MockedSystemProfiler(object):\n               Address: AA-00-BB-11-CC-22\n               Major Type: Miscellaneous\n               Minor Type: Unknown\n-              Services: \n+              Services:\n               Paired: No\n               Configured: Yes\n               Connected: No\n@@ -102,14 +102,39 @@ class TestBluetooth(unittest.TestCase):\n         Test macOS system_profiler for plyer.bluetooth.\n         '''\n         bluetooth = platform_import(\n-        platform='macosx',\n-        module_name='bluetooth',\n-        whereis_exe=MockedSystemProfiler.whereis_exe\n+            platform='macosx',\n+            module_name='bluetooth',\n+            whereis_exe=MockedSystemProfiler.whereis_exe\n         )\n \n         bluetooth.Popen = MockedSystemProfiler\n+        self.assertIn('OSXBluetooth', dir(bluetooth))\n         bluetooth = bluetooth.instance()\n+        self.assertIn('OSXBluetooth', str(bluetooth))\n \n         self.assertEqual(\n             bluetooth.info, MockedSystemProfiler.get_info()\n-        )\n\\ No newline at end of file\n+        )\n+\n+\n+    def test_bluetooth_macosx_instance(self):\n+        '''\n+        Test macOS instance for plyer.bluetooth.\n+        '''\n+\n+        def no_exe(*args, **kwargs):\n+            return\n+\n+        bluetooth = platform_import(\n+            platform='macosx',\n+            module_name='bluetooth',\n+            whereis_exe=no_exe\n+        )\n+\n+        bluetooth = bluetooth.instance()\n+        self.assertNotIn('OSXBluetooth', str(bluetooth))\n+        self.assertIn('Bluetooth', str(bluetooth))\n+\n+\n+if __name__ == '__main__':\n+    unittest.main()\n", 'addition_count': 30, 'deletion_count': 5, 'src_file': 'a/plyer/tests/test_bluetooth.py', 'tgt_file': 'b/plyer/tests/test_bluetooth.py', 'file_extension': '.py', 'before_file': '\'\'\'\nTestBluetooth\n=============\n\nTested platforms:\n\n* macOS - system_profiler\n\'\'\'\n\nimport unittest\n\nfrom plyer.tests.common import platform_import\nfrom textwrap import dedent\n\n\nclass MockedSystemProfiler:\n    \'\'\'\n    Mocked object used instead of Apple\'s system_profiler\n    \'\'\'\n    value = "On"\n    output = dedent(\n        """Bluetooth:\n\n      Apple Bluetooth Software Version: 6.0.7f11\n      Hardware, Features, and Settings:\n          Address: AA-00-BB-11-CC-22\n          Bluetooth Low Energy Supported: Yes\n          Handoff Supported: Yes\n          Instant Hot Spot Supported: Yes\n          Manufacturer: Broadcom\n          Transport: UART\n          Chipset: 1234\n          Firmware Version: v00 c0000\n          Bluetooth Power: {}\n          Auto Seek Pointing: On\n          Remote wake: On\n          Vendor ID: 0x0000\n          Product ID: 0x0000\n          HCI Version:  (0x0)\n          HCI Revision: 0x0000\n          LMP Version:  (0x0)\n          LMP Subversion: 0x0000\n              Address: AA-00-BB-11-CC-22\n              Major Type: Miscellaneous\n              Minor Type: Unknown\n              Services: \n              Paired: No\n              Configured: Yes\n              Connected: No\n              Paired: No\n              Configured: Yes\n              Connected: No\n              Class of Device: 0x00 0x00 0x0000\n      Services:\n          Bluetooth File Transfer:\n              Folder other devices can browse: ~/Public\n              When receiving items: Accept all without warning\n              State: Disabled\n          Bluetooth File Exchange:\n              Folder for accepted items: ~/Downloads\n              When other items are accepted: Save to location\n              When receiving items: Accept all without warning\n              State: Disabled\n          Bluetooth Internet Sharing:\n              State: Disabled\n      Incoming Serial Ports:\n          Bluetooth-Incoming-Port:\n              RFCOMM Channel: 3\n              Requires Authentication: No"""\n    ).format(value).encode(\'utf-8\')\n\n    def __init__(self, *args, **kwargs):\n        # only to ignore all args, kwargs\n        pass\n\n    @staticmethod\n    def communicate():\n        \'\'\'\n        Mock Popen.communicate, so that \'system_profiler\'\n        isn\'t used.\n        \'\'\'\n        return (MockedSystemProfiler.output, )\n\n    @staticmethod\n    def whereis_exe(binary):\n        \'\'\'\n        Mock whereis_exe, so that it looks like\n        macOS system_profiler binary is present on the system.\n        \'\'\'\n        return binary == \'system_profiler\'\n\n    @staticmethod\n    def get_info():\n        \'\'\'\n        Return current bluetooth status from mocked output.\n        \'\'\'\n        return MockedSystemProfiler.value\n\n\nclass TestBluetooth(unittest.TestCase):\n    \'\'\'\n        Test macOS system_profiler for plyer.bluetooth.\n        \'\'\'\n        bluetooth = platform_import(\n        platform=\'macosx\',\n        module_name=\'bluetooth\',\n        whereis_exe=MockedSystemProfiler.whereis_exe\n        )\n\n        bluetooth.Popen = MockedSystemProfiler\n        bluetooth = bluetooth.instance()\n\n        self.assertEqual(\n            bluetooth.info, MockedSystemProfiler.get_info()\n        )\n\n\nif __name__ == \'__main__\':\n    unittest.main()\n', 'message': 'Added macOS battery and bluetooth instance tests\n', 'author_name': 'Peter Badida', 'lang': 'py'}