From 3e7feda3c52864055b6f6cc640e746bbc5282932 Mon Sep 17 00:00:00 2001 From: Spencer Low Date: Thu, 30 Jul 2015 01:19:52 -0700 Subject: [PATCH] adb/test_device.py fixes for win32 and no use of ANDROID_SERIAL If ANDROID_SERIAL was not set, test_device.py was failing. Use posixpath.join instead of os.path.join for make_random_device_files. Change-Id: I24bfa43ba2a89a9a768f505fc0bba9d873082b2f Signed-off-by: Spencer Low --- adb/test_device.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/adb/test_device.py b/adb/test_device.py index 8003eaaea..81c4a9462 100644 --- a/adb/test_device.py +++ b/adb/test_device.py @@ -55,10 +55,15 @@ def requires_root(func): class GetDeviceTest(unittest.TestCase): def setUp(self): self.android_serial = os.getenv('ANDROID_SERIAL') - del os.environ['ANDROID_SERIAL'] + if 'ANDROID_SERIAL' in os.environ: + del os.environ['ANDROID_SERIAL'] def tearDown(self): - os.environ['ANDROID_SERIAL'] = self.android_serial + if self.android_serial is not None: + os.environ['ANDROID_SERIAL'] = self.android_serial + else: + if 'ANDROID_SERIAL' in os.environ: + del os.environ['ANDROID_SERIAL'] @mock.patch('adb.device.get_devices') def test_explicit(self, mock_get_devices): @@ -311,7 +316,7 @@ def make_random_device_files(device, in_dir, num_files): size = random.randrange(min_size, max_size, 1024) base_name = 'device_tmpfile' + str(file_num) - full_path = os.path.join(in_dir, base_name) + full_path = posixpath.join(in_dir, base_name) device.shell(['dd', 'if=/dev/urandom', 'of={}'.format(full_path), 'bs={}'.format(size), 'count=1'])