Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(999)

Unified Diff: common/battor/battor/battor_wrapper_unittest.py

Issue 1945733002: [Battor] Fix broken BattOr unit tests and set them to run in CQ. (Closed) Base URL: git@github.com:catapult-project/catapult@master
Patch Set: fix whitespace Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « common/battor/battor/__init__.py ('k') | common/battor/bin/run_py_tests » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: common/battor/battor/battor_wrapper_unittest.py
diff --git a/common/battor/battor/battor_wrapper_unittest.py b/common/battor/battor/battor_wrapper_unittest.py
index 7611a60a30d814a4f288fcfc319f96316bb3ad4b..f77585f8bfe3d6b988fa43cc6dced29500b7c972 100644
--- a/common/battor/battor/battor_wrapper_unittest.py
+++ b/common/battor/battor/battor_wrapper_unittest.py
@@ -2,17 +2,18 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-# import battor first to run the __init__ to set python paths
-from battor import battor_wrapper
-
import dependency_manager
import logging
import unittest
from battor import battor_error
+from battor import battor_wrapper
from devil.utils import battor_device_mapping
from devil.utils import find_usb_devices
+import serial
+from serial.tools import list_ports
+
class DependencyManagerMock(object):
def __init__(self, _):
@@ -44,6 +45,7 @@ class BattorWrapperTest(unittest.TestCase):
self._get_battor_list = battor_device_mapping.GetBattorList
self._is_battor = battor_device_mapping.IsBattor
self._generate_serial_map = battor_device_mapping.GenerateSerialMap
+ self._serial_tools = serial.tools.list_ports.comports
battor_device_mapping.GetBattorPathFromPhoneSerial = (
@@ -53,6 +55,7 @@ class BattorWrapperTest(unittest.TestCase):
battor_device_mapping.GetBattorList = lambda x: self._battor_list
battor_device_mapping.IsBattor = lambda x, y: self._is_battor
battor_device_mapping.GenerateSerialMap = lambda: self._fake_map
+ serial.tools.list_ports.comports = lambda: [('COM4', 'USB Serial Port', '')]
def tearDown(self):
battor_device_mapping.GetBattorPathFromPhoneSerial = (
@@ -63,11 +66,12 @@ class BattorWrapperTest(unittest.TestCase):
battor_device_mapping.GetBattorList = self._get_battor_list
battor_device_mapping.IsBattor = self._is_battor
battor_device_mapping.GenerateSerialMap = self._generate_serial_map
+ serial.tools.list_ports.comports = self._serial_tools
def _DefaultBattorReplacements(self):
self._battor._StartShellImpl = lambda *unused: PopenMock
self._battor.IsShellRunning = lambda *unused: True
- self._battor._SendBattorCommandImpl = lambda x, return_results: 'Done.\n'
+ self._battor._SendBattorCommandImpl = lambda x: 'Done.\n'
self._battor._StopTracingImpl = lambda *unused: ('Done.\n', None)
def testBadPlatform(self):
@@ -83,7 +87,7 @@ class BattorWrapperTest(unittest.TestCase):
self._fake_map = {}
battor_device_mapping.GetBattorPathFromPhoneSerial = (
self._get_battor_path_from_phone_serial)
- with self.assertRaises(KeyError):
+ with self.assertRaises(battor_error.BattorError):
self._battor = battor_wrapper.BattorWrapper('android',
android_device='abc')
@@ -95,15 +99,16 @@ class BattorWrapperTest(unittest.TestCase):
def testInitNonAndroidWithBattor(self):
self._battor = battor_wrapper.BattorWrapper('win')
- self.assertEquals(self._battor._battor_path, '/dev/battor1')
+ self.assertEquals(self._battor._battor_path, 'COM4')
def testInitNonAndroidWithMultipleBattor(self):
self._battor_list.append('battor2')
with self.assertRaises(battor_error.BattorError):
- self._battor = battor_wrapper.BattorWrapper('win')
+ self._battor = battor_wrapper.BattorWrapper('linux')
def testInitNonAndroidWithoutBattor(self):
self._battor_list = []
+ serial.tools.list_ports.comports = lambda: [('COM4', 'None', '')]
with self.assertRaises(battor_error.BattorError):
self._battor = battor_wrapper.BattorWrapper('win')
@@ -145,7 +150,7 @@ class BattorWrapperTest(unittest.TestCase):
def testStartTracingCommandFails(self):
self._battor = battor_wrapper.BattorWrapper('win')
self._DefaultBattorReplacements()
- self._battor._SendBattorCommandImpl = lambda x, return_results: 'Fail.\n'
+ self._battor._SendBattorCommandImpl = lambda *unused: 'Fail.\n'
self._battor.StartShell()
with self.assertRaises(battor_error.BattorError):
self._battor.StartTracing()
« no previous file with comments | « common/battor/battor/__init__.py ('k') | common/battor/bin/run_py_tests » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698