Loading adb/device.py +2 −1 Original line number Diff line number Diff line Loading @@ -60,6 +60,7 @@ def _get_unique_device(product=None): raise NoUniqueDeviceError() return AndroidDevice(devices[0], product) def _get_device_by_serial(serial, product=None): for device in get_devices(): if device == serial: Loading Loading @@ -220,7 +221,7 @@ class AndroidDevice(object): return self._simple_call(['wait-for-device']) def get_prop(self, prop_name): output = self.shell(['getprop', prop_name]) output = self.shell(['getprop', prop_name]).splitlines() if len(output) != 1: raise RuntimeError('Too many lines in getprop output:\n' + '\n'.join(output)) Loading adb/test_device.py +37 −1 Original line number Diff line number Diff line Loading @@ -32,6 +32,26 @@ import mock import adb def requires_root(func): def wrapper(self, *args): if self.device.get_prop('ro.debuggable') != '1': raise unittest.SkipTest('requires rootable build') was_root = self.device.shell(['id', '-un']).strip() == 'root' if not was_root: self.device.root() self.device.wait() try: func(self, *args) finally: if not was_root: self.device.unroot() self.device.wait() return wrapper class GetDeviceTest(unittest.TestCase): def setUp(self): self.android_serial = os.getenv('ANDROID_SERIAL') Loading Loading @@ -188,6 +208,9 @@ class RootUnrootTest(DeviceTest): def test_root_unroot(self): """Make sure that adb root and adb unroot work, using id(1).""" if self.device.get_prop('ro.debuggable') != '1': raise unittest.SkipTest('requires rootable build') original_user = self.device.shell(['id', '-un']).strip() try: if original_user == 'root': Loading Loading @@ -216,6 +239,20 @@ class TcpIpTest(DeviceTest): subprocess.CalledProcessError, self.device.tcpip, 'foo') class SystemPropertiesTest(DeviceTest): def test_get_prop(self): self.assertEqual(self.device.get_prop('init.svc.adbd'), 'running') @requires_root def test_set_prop(self): prop_name = 'foo.bar' self.device.shell(['setprop', prop_name, '""']) self.device.set_prop(prop_name, 'qux') self.assertEqual( self.device.shell(['getprop', prop_name]).strip(), 'qux') def compute_md5(string): hsh = hashlib.md5() hsh.update(string) Loading Loading @@ -393,7 +430,6 @@ class FileOperationsTest(DeviceTest): self.device.shell(['rm', '-rf', self.DEVICE_TEMP_DIR]) shutil.rmtree(base_dir + self.DEVICE_TEMP_DIR) def test_unicode_paths(self): """Ensure that we can support non-ASCII paths, even on Windows.""" name = u'로보카 폴리'.encode('utf-8') Loading Loading
adb/device.py +2 −1 Original line number Diff line number Diff line Loading @@ -60,6 +60,7 @@ def _get_unique_device(product=None): raise NoUniqueDeviceError() return AndroidDevice(devices[0], product) def _get_device_by_serial(serial, product=None): for device in get_devices(): if device == serial: Loading Loading @@ -220,7 +221,7 @@ class AndroidDevice(object): return self._simple_call(['wait-for-device']) def get_prop(self, prop_name): output = self.shell(['getprop', prop_name]) output = self.shell(['getprop', prop_name]).splitlines() if len(output) != 1: raise RuntimeError('Too many lines in getprop output:\n' + '\n'.join(output)) Loading
adb/test_device.py +37 −1 Original line number Diff line number Diff line Loading @@ -32,6 +32,26 @@ import mock import adb def requires_root(func): def wrapper(self, *args): if self.device.get_prop('ro.debuggable') != '1': raise unittest.SkipTest('requires rootable build') was_root = self.device.shell(['id', '-un']).strip() == 'root' if not was_root: self.device.root() self.device.wait() try: func(self, *args) finally: if not was_root: self.device.unroot() self.device.wait() return wrapper class GetDeviceTest(unittest.TestCase): def setUp(self): self.android_serial = os.getenv('ANDROID_SERIAL') Loading Loading @@ -188,6 +208,9 @@ class RootUnrootTest(DeviceTest): def test_root_unroot(self): """Make sure that adb root and adb unroot work, using id(1).""" if self.device.get_prop('ro.debuggable') != '1': raise unittest.SkipTest('requires rootable build') original_user = self.device.shell(['id', '-un']).strip() try: if original_user == 'root': Loading Loading @@ -216,6 +239,20 @@ class TcpIpTest(DeviceTest): subprocess.CalledProcessError, self.device.tcpip, 'foo') class SystemPropertiesTest(DeviceTest): def test_get_prop(self): self.assertEqual(self.device.get_prop('init.svc.adbd'), 'running') @requires_root def test_set_prop(self): prop_name = 'foo.bar' self.device.shell(['setprop', prop_name, '""']) self.device.set_prop(prop_name, 'qux') self.assertEqual( self.device.shell(['getprop', prop_name]).strip(), 'qux') def compute_md5(string): hsh = hashlib.md5() hsh.update(string) Loading Loading @@ -393,7 +430,6 @@ class FileOperationsTest(DeviceTest): self.device.shell(['rm', '-rf', self.DEVICE_TEMP_DIR]) shutil.rmtree(base_dir + self.DEVICE_TEMP_DIR) def test_unicode_paths(self): """Ensure that we can support non-ASCII paths, even on Windows.""" name = u'로보카 폴리'.encode('utf-8') Loading