Standardize unpack_userparam.
Bug=26472080
Raise exceptions instead of return True/False.
Update all related scripts to use the new convention.
Change-Id: I7d8486bfcbc2a304c300e01c248550b5d6bf1e4a
diff --git a/acts/framework/acts/base_test.py b/acts/framework/acts/base_test.py
index 28d485e..d8a318a 100644
--- a/acts/framework/acts/base_test.py
+++ b/acts/framework/acts/base_test.py
@@ -115,17 +115,16 @@
def __exit__(self, *args):
self._exec_func(self.clean_up)
- def unpack_userparams(self, req_param_names=[], opt_param_names=[], **kwargs):
+ def unpack_userparams(self, req_param_names=[], opt_param_names=[],
+ **kwargs):
"""Unpacks user defined parameters in test config into individual
variables.
Instead of accessing the user param with self.user_params["xxx"], the
variable can be directly accessed with self.xxx.
- All missing required params will be logged in error. If an optional
- param is missing, log a note and continue. You can assert on the return
- value of this function in setup_class to ensure the required user
- params are found in test config and set.
+ A missing required param will raise an exception. If an optional param
+ is missing, an INFO line will be logged.
Args:
req_param_names: A list of names of the required user params.
@@ -135,18 +134,16 @@
self.arg_a will be "hello" unless it is specified again in
required_list or opt_list.
- Returns:
- True if all required user params were set. False otherwise.
+ Raises:
+ BaseTestError is raised if a required user params is missing from test
+ config.
"""
- missing = False
for k, v in kwargs.items():
setattr(self, k, v)
for name in req_param_names:
if name not in self.user_params:
- missing = True
- self.log.error(("Missing required user param '%s' in "
- "configuration!") % name)
- continue
+ raise BaseTestError(("Missing required user param '%s' in test"
+ " configuration.") % name)
setattr(self, name, self.user_params[name])
for name in opt_param_names:
if name not in self.user_params:
@@ -154,7 +151,6 @@
"configuration, continue.") % name)
else:
setattr(self, name, self.user_params[name])
- return not missing
def _setup_class(self):
"""Proxy function to guarantee the base implementation of setup_class
diff --git a/acts/framework/tests/BaseTestClassTests/ActsBaseClassTest.py b/acts/framework/tests/BaseTestClassTests/ActsBaseClassTest.py
index 3b5882b..c55e7a1 100644
--- a/acts/framework/tests/BaseTestClassTests/ActsBaseClassTest.py
+++ b/acts/framework/tests/BaseTestClassTests/ActsBaseClassTest.py
@@ -15,6 +15,7 @@
# limitations under the License.
from acts.base_test import BaseTestClass
+from acts.base_test import BaseTestError
from acts.signals import generated_test
from acts.signals import TestSignal
from acts.signals import TestSignalError
@@ -254,16 +255,18 @@
def test_unpack_userparams_required(self):
required_param = "something"
required = [required_param]
- self.assert_true(not self.unpack_userparams(required), ("Required "
- "param '%s' missing, unpack funtion should have "
- "returned False.") % required_param)
+ try:
+ self.unpack_userparams(required)
+ except BaseTestError:
+ self.explicit_pass("Got expected exception caused by missing "
+ "required param.")
+ self.fail(("Required param '%s' missing, unpack funtion should have "
+ "raised exception.") % required_param)
def test_unpack_userparams_optional(self):
optional_param = "something"
opt = [optional_param]
- self.assert_true(self.unpack_userparams(opt_param_names=opt),
- ("Optional param '%s' missing, unpack function should"
- "have returned True.") % optional_param)
+ self.unpack_userparams(opt_param_names=opt)
def test_unpack_userparams_default(self):
arg = "haha"
diff --git a/acts/tests/google/wifi/WifiAutoJoinTest.py b/acts/tests/google/wifi/WifiAutoJoinTest.py
index de71c9b..f0fe10a 100755
--- a/acts/tests/google/wifi/WifiAutoJoinTest.py
+++ b/acts/tests/google/wifi/WifiAutoJoinTest.py
@@ -64,7 +64,7 @@
wifi_test_device_init(self.dut)
req_params = ("reference_networks", "other_network", "atten_val",
"ping_addr", "max_bugreports" )
- assert self.unpack_userparams(req_params)
+ self.unpack_userparams(req_params)
self.log.debug("Connect networks :: {}".format(self.other_network))
configured_networks = self.droid.wifiGetConfiguredNetworks()
self.log.debug("Configured networks :: {}".format(configured_networks))
@@ -115,7 +115,6 @@
finally:
self.droid.wifiLockRelease()
self.droid.goToSleepNow()
- return True
def check_connection(self, network_bssid):
"""Check current wifi connection networks.
diff --git a/acts/tests/google/wifi/WifiEnterpriseRoamingTest.py b/acts/tests/google/wifi/WifiEnterpriseRoamingTest.py
index 54cd818..5ce693e 100644
--- a/acts/tests/google/wifi/WifiEnterpriseRoamingTest.py
+++ b/acts/tests/google/wifi/WifiEnterpriseRoamingTest.py
@@ -55,7 +55,7 @@
"eap_password",
"device_password"
)
- assert self.unpack_userparams(req_params)
+ self.unpack_userparams(req_params)
self.config_peap = {
Ent.EAP: EAP.PEAP,
Ent.CA_CERT: self.ca_cert,
@@ -89,7 +89,6 @@
# Set screen lock password so ConfigStore is unlocked.
self.droid.setDevicePassword(self.device_password)
self.set_attns("default")
- return True
def teardown_class(self):
wutils.reset_wifi(self.dut)
diff --git a/acts/tests/google/wifi/WifiEnterpriseTest.py b/acts/tests/google/wifi/WifiEnterpriseTest.py
index fbdd02f..3f35725 100755
--- a/acts/tests/google/wifi/WifiEnterpriseTest.py
+++ b/acts/tests/google/wifi/WifiEnterpriseTest.py
@@ -70,7 +70,7 @@
"roaming_consortium_ids",
"plmn"
)
- assert self.unpack_userparams(required_userparam_names,
+ self.unpack_userparams(required_userparam_names,
opt_param_names = optional_userparam_names)
# Default configs for EAP networks.
self.config_peap = {
@@ -125,7 +125,6 @@
del self.config_passpoint_ttls[WifiEnums.SSID_KEY]
# Set screen lock password so ConfigStore is unlocked.
self.droid.setDevicePassword(self.device_password)
- return True
def teardown_class(self):
wutils.reset_wifi(self.dut)
@@ -138,7 +137,6 @@
self.droid.wakeUpNow()
wutils.reset_wifi(self.dut)
self.ed.clear_all_events()
- return True
def teardown_test(self):
self.droid.wakeLockRelease()
diff --git a/acts/tests/google/wifi/WifiManagerTest.py b/acts/tests/google/wifi/WifiManagerTest.py
index 22c4b95..0ac12e9 100755
--- a/acts/tests/google/wifi/WifiManagerTest.py
+++ b/acts/tests/google/wifi/WifiManagerTest.py
@@ -51,21 +51,18 @@
"tdls_models",
"energy_info_models"
)
- self.assert_true(self.unpack_userparams(req_params),
- "Failed to unpack user params")
+ self.unpack_userparams(req_params)
self.assert_true(len(self.iot_networks) > 0,
"Need at least one iot network with psk.")
self.assert_true(wutils.wifi_toggle_state(self.dut, True),
"Failed to turn on wifi before tests.")
self.iot_networks = self.iot_networks + [self.open_network]
self.iperf_server = self.iperf_servers[0]
- return True
def setup_test(self):
self.droid.wakeLockAcquireBright()
self.droid.wakeUpNow()
self.iperf_server.start()
- return True
def teardown_test(self):
self.droid.wakeLockRelease()
diff --git a/acts/tests/google/wifi/WifiNanManagerTest.py b/acts/tests/google/wifi/WifiNanManagerTest.py
index 2bfa9c7..f6660e6 100644
--- a/acts/tests/google/wifi/WifiNanManagerTest.py
+++ b/acts/tests/google/wifi/WifiNanManagerTest.py
@@ -46,8 +46,7 @@
"subscribe_data",
"subscribe_settings"
)
- msg = "Failed to unpack user params."
- self.assert_true(self.unpack_userparams(required_params), msg)
+ self.unpack_userparams(required_params)
def setup_test(self):
assert wutils.wifi_toggle_state(self.publisher, True)
diff --git a/acts/tests/google/wifi/WifiPowerTest.py b/acts/tests/google/wifi/WifiPowerTest.py
index 9b981c0..56c7a4f 100644
--- a/acts/tests/google/wifi/WifiPowerTest.py
+++ b/acts/tests/google/wifi/WifiPowerTest.py
@@ -70,8 +70,7 @@
"network_2g",
"network_5g"
)
- self.assert_true(self.unpack_userparams(required_userparam_names),
- "Failed to unpack user params.")
+ self.unpack_userparams(required_userparam_names)
wutils.wifi_test_device_init(self.dut)
# Start pmc app.
self.dut.adb.shell(start_pmc_cmd)
diff --git a/acts/tests/google/wifi/WifiRttManagerTest.py b/acts/tests/google/wifi/WifiRttManagerTest.py
index 012572b..bfa7854 100644
--- a/acts/tests/google/wifi/WifiRttManagerTest.py
+++ b/acts/tests/google/wifi/WifiRttManagerTest.py
@@ -64,8 +64,7 @@
"vht80_5g",
"actual_distance"
)
- msg = "Failed to unpack user params."
- self.assert_true(self.unpack_userparams(required_params), msg)
+ self.unpack_userparams(required_params)
self.assert_true(self.actual_distance >= 5,
"Actual distance should be no shorter than 5 meters.")
self.visible_networks = (
diff --git a/acts/tests/google/wifi/WifiScannerBssidTest.py b/acts/tests/google/wifi/WifiScannerBssidTest.py
index c64fcc2..cf76517 100755
--- a/acts/tests/google/wifi/WifiScannerBssidTest.py
+++ b/acts/tests/google/wifi/WifiScannerBssidTest.py
@@ -70,8 +70,7 @@
req_params = ("bssid_2g", "bssid_5g", "bssid_dfs", "attenuator_id",
"max_bugreports")
self.wifi_chs = WifiChannelUS(self.dut.model)
- userparam_status = self.unpack_userparams(req_params)
- return userparam_status
+ self.unpack_userparams(req_params)
def on_fail(self, test_name, begin_time):
if self.max_bugreports > 0:
diff --git a/acts/tests/google/wifi/WifiScannerMultiScanTest.py b/acts/tests/google/wifi/WifiScannerMultiScanTest.py
index 8bf388d..db80dd2 100755
--- a/acts/tests/google/wifi/WifiScannerMultiScanTest.py
+++ b/acts/tests/google/wifi/WifiScannerMultiScanTest.py
@@ -160,8 +160,7 @@
"""
req_params = ("bssid_2g", "bssid_5g", "bssid_dfs", "max_bugreports")
self.wifi_chs = WifiChannelUS(self.dut.model)
- userparam_status = self.unpack_userparams(req_params)
- return userparam_status
+ self.unpack_userparams(req_params)
def on_fail(self, test_name, begin_time):
if self.max_bugreports > 0:
diff --git a/acts/tests/google/wifi/WifiScannerScanTest.py b/acts/tests/google/wifi/WifiScannerScanTest.py
index 3665ccc..5cd464e 100755
--- a/acts/tests/google/wifi/WifiScannerScanTest.py
+++ b/acts/tests/google/wifi/WifiScannerScanTest.py
@@ -93,15 +93,13 @@
wifi_test_device_init(self.dut)
req_params = ("connect_network", "run_extended_test", "ping_addr",
"max_bugreports")
- userparam_status = self.unpack_userparams(req_params)
- self.assert_true(userparam_status, "Required user parameter")
+ self.unpack_userparams(req_params)
self.log.debug("Run extended test: {}".format(self.run_extended_test))
self.wifi_chs = WifiChannelUS(self.dut.model)
self.assert_true(self.dut.droid.wifiIsScannerSupported(),
"Device %s doesn't support WifiScanner, abort." % self.dut.model)
self.attenuators[0].set_atten(0)
self.attenuators[1].set_atten(0)
- return True
def teardown_test(self):
BaseTestClass.teardown_test(self)