Add acts.asserts.assert_false.
BUG=29094786
Change-Id: I2fade4f012d8cba69f49f79055c322a940689221
diff --git a/acts/framework/acts/asserts.py b/acts/framework/acts/asserts.py
index c51671c..4bc9d33 100644
--- a/acts/framework/acts/asserts.py
+++ b/acts/framework/acts/asserts.py
@@ -114,6 +114,19 @@
fail(msg, extras)
+def assert_false(expr, msg, extras=None):
+ """Assert an expression evaluates to false, otherwise fail the test.
+
+ Args:
+ expr: The expression that is evaluated.
+ msg: A string explaining the details in case of failure.
+ extras: An optional field for extra information to be included in
+ test result.
+ """
+ if expr:
+ fail(msg, extras)
+
+
def skip(reason, extras=None):
"""Skip a test case.
diff --git a/acts/framework/tests/acts_asserts_test.py b/acts/framework/tests/acts_asserts_test.py
new file mode 100755
index 0000000..dbf39d9
--- /dev/null
+++ b/acts/framework/tests/acts_asserts_test.py
@@ -0,0 +1,37 @@
+#!/usr/bin/env python3.4
+#
+# Copyright 2016 - The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import unittest
+
+from acts import asserts
+from acts import signals
+
+MSG_EXPECTED_EXCEPTION = "This is an expected exception."
+
+
+class ActsAssertsTest(unittest.TestCase):
+ """Verifies that asserts.xxx functions raise the correct test signals.
+ """
+
+ def test_assert_false(self):
+ asserts.assert_false(False, MSG_EXPECTED_EXCEPTION)
+ with self.assertRaisesRegexp(signals.TestFailure,
+ MSG_EXPECTED_EXCEPTION):
+ asserts.assert_false(True, MSG_EXPECTED_EXCEPTION)
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/acts/framework/tests/acts_unittest_suite.py b/acts/framework/tests/acts_unittest_suite.py
index 108bc8d..bbcd088 100755
--- a/acts/framework/tests/acts_unittest_suite.py
+++ b/acts/framework/tests/acts_unittest_suite.py
@@ -19,6 +19,7 @@
import acts_adb_test
import acts_android_device_test
+import acts_asserts_test
import acts_base_class_test
import acts_records_test
import acts_test_runner_test
@@ -26,6 +27,7 @@
def compile_suite():
test_classes_to_run = [
acts_adb_test.ActsAdbTest,
+ acts_asserts_test.ActsAssertsTest,
acts_base_class_test.ActsBaseClassTest,
acts_test_runner_test.ActsTestRunnerTest,
acts_android_device_test.ActsAndroidDeviceTest,