Merge "Removes the WiFiPowerTest."
diff --git a/acts/framework/acts/test_runner.py b/acts/framework/acts/test_runner.py
index 1adfc91..acfb88e 100644
--- a/acts/framework/acts/test_runner.py
+++ b/acts/framework/acts/test_runner.py
@@ -291,15 +291,15 @@
                 test_case_iterations = self.test_configs.get(
                     keys.Config.key_test_case_iterations.value, 1)
 
-            with test_cls(self.test_run_info) as test_cls_instance:
-                try:
-                    cls_result = test_cls_instance.run(test_cases,
-                                                       test_case_iterations)
-                    self.results += cls_result
-                    self._write_results_to_file()
-                except signals.TestAbortAll as e:
-                    self.results += e.results
-                    raise e
+            test_cls_instance = test_cls(self.test_run_info)
+            try:
+                cls_result = test_cls_instance.run(test_cases,
+                                                   test_case_iterations)
+                self.results += cls_result
+                self._write_results_to_file()
+            except signals.TestAbortAll as e:
+                self.results += e.results
+                raise e
 
     def run(self, test_class=None):
         """Executes test cases.
diff --git a/acts/framework/acts/test_utils/instrumentation/adb_command_types.py b/acts/framework/acts/test_utils/instrumentation/adb_command_types.py
index fe1b7ce..5c55734 100644
--- a/acts/framework/acts/test_utils/instrumentation/adb_command_types.py
+++ b/acts/framework/acts/test_utils/instrumentation/adb_command_types.py
@@ -37,9 +37,11 @@
         Args:
             values: The value(s) to run the command with
         """
-
-        return str.strip(' '.join(
-            [self._base_cmd] + [str(value) for value in values]))
+        try:
+            return self._base_cmd % values
+        except TypeError:
+            return str.strip(' '.join(
+                [self._base_cmd] + [str(value) for value in values]))
 
     def toggle(self, enabled):
         """Returns the command corresponding to the desired state.
diff --git a/acts/framework/acts/test_utils/instrumentation/instrumentation_base_test.py b/acts/framework/acts/test_utils/instrumentation/instrumentation_base_test.py
index 76978cb..a56d1c3 100644
--- a/acts/framework/acts/test_utils/instrumentation/instrumentation_base_test.py
+++ b/acts/framework/acts/test_utils/instrumentation/instrumentation_base_test.py
@@ -49,7 +49,7 @@
         # try to find the power config in the same directory as the ACTS config
         power_config_path = ''
         if 'power_config' in self.user_params:
-            power_config_path = self.user_params['power_config']
+            power_config_path = self.user_params['power_config'][0]
         elif Config.key_config_path.value in self.user_params:
             power_config_path = os.path.join(
                 self.user_params[Config.key_config_path.value],
@@ -125,13 +125,17 @@
         Args:
             cmds: A string or list of strings representing ADB shell command(s)
             non_blocking: Run asynchronously
+
+        Returns: dict mapping command to resulting stdout
         """
         if isinstance(cmds, str):
             cmds = [cmds]
         adb = self.ad_dut.adb
         adb_shell = adb.shell_nb if non_blocking else adb.shell
+        out = {}
         for cmd in cmds:
-            adb_shell(cmd)
+            out[cmd] = adb_shell(cmd)
+        return out
 
     # Basic preparer methods
 
diff --git a/acts/framework/acts/test_utils/instrumentation/intent_builder.py b/acts/framework/acts/test_utils/instrumentation/intent_builder.py
index ba3b65a..1fe4035 100644
--- a/acts/framework/acts/test_utils/instrumentation/intent_builder.py
+++ b/acts/framework/acts/test_utils/instrumentation/intent_builder.py
@@ -82,5 +82,9 @@
             if value is None:
                 cmd.append('--esn %s' % key)
             else:
-                cmd.append('%s %s %s' % (TYPE_TO_FLAG[type(value)], key, value))
+                str_value = str(value)
+                if isinstance(value, bool):
+                    str_value = str_value.lower()
+                cmd.append(
+                    ' '.join((TYPE_TO_FLAG[type(value)], key, str_value)))
         return ' '.join(cmd).strip()
diff --git a/acts/framework/acts/test_utils/power/tel_simulations/BaseSimulation.py b/acts/framework/acts/test_utils/power/tel_simulations/BaseSimulation.py
index 4053554..5b723c8 100644
--- a/acts/framework/acts/test_utils/power/tel_simulations/BaseSimulation.py
+++ b/acts/framework/acts/test_utils/power/tel_simulations/BaseSimulation.py
@@ -229,8 +229,14 @@
         # Wait for APM to propagate
         time.sleep(2)
 
-        # Power off basestation
-        self.anritsu.set_simulation_state_to_poweroff()
+        # Try to power off the basestation. An exception will be raised if the
+        # simulation is not running, which is ok because it means the phone is
+        # not attached.
+        try:
+            self.anritsu.set_simulation_state_to_poweroff()
+        except AnritsuError:
+            self.log.warning('Could not power off the basestation. The '
+                             'simulation might be stopped.')
 
     def stop(self):
         """  Detach phone from the basestation by stopping the simulation.
diff --git a/acts/framework/acts/test_utils/tel/tel_test_utils.py b/acts/framework/acts/test_utils/tel/tel_test_utils.py
index b8dcfd9..c7474c5 100644
--- a/acts/framework/acts/test_utils/tel/tel_test_utils.py
+++ b/acts/framework/acts/test_utils/tel/tel_test_utils.py
@@ -6305,12 +6305,12 @@
     # Delete existing SDM logs which were created 15 mins prior
     ad.sdm_log_path = DEFAULT_SDM_LOG_PATH
     file_count = ad.adb.shell(
-        "find %s -type f -iname *.sdm | wc -l" % ad.sdm_log_path)
+        "find %s -type f -iname *.sdm* | wc -l" % ad.sdm_log_path)
     if int(file_count) > 3:
         seconds = 15 * 60
         # Remove sdm logs modified more than specified seconds ago
         ad.adb.shell(
-            "find %s -type f -iname *.sdm -not -mtime -%ss -delete" %
+            "find %s -type f -iname *.sdm* -not -mtime -%ss -delete" %
             (ad.sdm_log_path, seconds))
     # start logging
     cmd = "setprop vendor.sys.modem.logging.enable true"
diff --git a/acts/framework/tests/test_runner_test.py b/acts/framework/tests/test_runner_test.py
index 65f50c9..b48f338 100755
--- a/acts/framework/tests/test_runner_test.py
+++ b/acts/framework/tests/test_runner_test.py
@@ -14,15 +14,15 @@
 #   See the License for the specific language governing permissions and
 #   limitations under the License.
 
-from mock import Mock
-import unittest
+import shutil
 import tempfile
+import unittest
 
-from acts import keys
+from mock import Mock
+from mock import patch
+
 from acts import test_runner
 
-import mock_controller
-
 
 class TestRunnerTest(unittest.TestCase):
     def setUp(self):
@@ -38,19 +38,16 @@
             "extra_param": "haha"
         }
 
-    def create_mock_context(self):
-        context = Mock()
-        context.__exit__ = Mock()
-        context.__enter__ = Mock()
-        return context
+    def tearDown(self):
+        shutil.rmtree(self.tmp_dir)
 
-    def create_test_classes(self, class_names):
-        return {
-            class_name: Mock(return_value=self.create_mock_context())
-            for class_name in class_names
-        }
+    @staticmethod
+    def create_test_classes(class_names):
+        return {class_name: Mock() for class_name in class_names}
 
-    def test_class_name_pattern_single(self):
+    @patch('acts.records.TestResult')
+    @patch.object(test_runner.TestRunner, '_write_results_to_file')
+    def test_class_name_pattern_single(self, *_):
         class_names = ['test_class_1', 'test_class_2']
         pattern = 'test*1'
         tr = test_runner.TestRunner(self.base_mock_test_config, [(pattern,
@@ -62,7 +59,9 @@
         self.assertTrue(test_classes[class_names[0]].called)
         self.assertFalse(test_classes[class_names[1]].called)
 
-    def test_class_name_pattern_multi(self):
+    @patch('acts.records.TestResult')
+    @patch.object(test_runner.TestRunner, '_write_results_to_file')
+    def test_class_name_pattern_multi(self, *_):
         class_names = ['test_class_1', 'test_class_2', 'other_name']
         pattern = 'test_class*'
         tr = test_runner.TestRunner(self.base_mock_test_config, [(pattern,
@@ -75,7 +74,9 @@
         self.assertTrue(test_classes[class_names[1]].called)
         self.assertFalse(test_classes[class_names[2]].called)
 
-    def test_class_name_pattern_question_mark(self):
+    @patch('acts.records.TestResult')
+    @patch.object(test_runner.TestRunner, '_write_results_to_file')
+    def test_class_name_pattern_question_mark(self, *_):
         class_names = ['test_class_1', 'test_class_12']
         pattern = 'test_class_?'
         tr = test_runner.TestRunner(self.base_mock_test_config, [(pattern,
@@ -87,7 +88,9 @@
         self.assertTrue(test_classes[class_names[0]].called)
         self.assertFalse(test_classes[class_names[1]].called)
 
-    def test_class_name_pattern_char_seq(self):
+    @patch('acts.records.TestResult')
+    @patch.object(test_runner.TestRunner, '_write_results_to_file')
+    def test_class_name_pattern_char_seq(self, *_):
         class_names = ['test_class_1', 'test_class_2', 'test_class_3']
         pattern = 'test_class_[1357]'
         tr = test_runner.TestRunner(self.base_mock_test_config, [(pattern,
diff --git a/acts/framework/tests/test_utils/instrumentation/adb_command_types_test.py b/acts/framework/tests/test_utils/instrumentation/adb_command_types_test.py
index f5b6cb9..d934cc0 100755
--- a/acts/framework/tests/test_utils/instrumentation/adb_command_types_test.py
+++ b/acts/framework/tests/test_utils/instrumentation/adb_command_types_test.py
@@ -36,6 +36,15 @@
         self.assertEqual(device_state.set_value(val1, val2),
                          'run command with vals 15 24')
 
+    def test_device_state_with_base_cmd_as_format_string(self):
+        """Tests that DeviceState returns the correct ADB command if the base
+        command is given as a format string.
+        """
+        base_cmd = 'echo %s > /test/data'
+        val = 23
+        device_state = DeviceState(base_cmd)
+        self.assertEqual(device_state.set_value(val), 'echo 23 > /test/data')
+
     def test_device_binary_state(self):
         """Tests that DeviceState returns the correct ADB commands with toggle.
         """
diff --git a/acts/tests/google/power/tel/lab/PowerTelTrafficTest.py b/acts/tests/google/power/tel/lab/PowerTelTrafficTest.py
index 507f119..6e8ce49 100644
--- a/acts/tests/google/power/tel/lab/PowerTelTrafficTest.py
+++ b/acts/tests/google/power/tel/lab/PowerTelTrafficTest.py
@@ -62,13 +62,13 @@
         self.bandwidth_limit_ul = None
 
         # Throughput obtained from iPerf
-        self.iperf_results = None
+        self.iperf_results = {}
 
         # Blackbox metrics loggers
 
-        self.dl_throughput_logger = BlackboxMetricLogger.for_test_case(
+        self.dl_tput_logger = BlackboxMetricLogger.for_test_case(
             metric_name='avg_dl_tput')
-        self.ul_throughput_logger = BlackboxMetricLogger.for_test_case(
+        self.ul_tput_logger = BlackboxMetricLogger.for_test_case(
             metric_name='avg_ul_tput')
 
     def setup_test(self):
@@ -123,12 +123,9 @@
 
         super().teardown_test()
 
-        if self.iperf_results:
-            # Log the throughput values to Blackbox
-            self.dl_throughput_logger.metric_value = self.iperf_results.get(
-                'DL', 0)
-            self.ul_throughput_logger.metric_value = self.iperf_results.get(
-                'UL', 0)
+        # Log the throughput values to Blackbox
+        self.dl_tput_logger.metric_value = self.iperf_results.get('DL', 0)
+        self.ul_tput_logger.metric_value = self.iperf_results.get('UL', 0)
 
         for ips in self.iperf_servers:
             ips.stop()