More to come, with event streams.
Test: cert/run --host
Change-Id: Ie4a750c24990e9d848c673cde482ae8af71a39de
from acts.base_test import BaseTestClass
from cert.event_callback_stream import EventCallbackStream
from cert.event_asserts import EventAsserts
+from cert.truth import assertThat
# Test packet nesting
from bluetooth_packets_python3 import hci_packets
# Size is ACL (4) + L2CAP (4) + Configure (8) + MTU (4) + FCS (3)
asserts.assert_true(
len(wrapped.Serialize()) == 23, "Packet serialized incorrectly")
+
+ def test_assertThat_boolean_success(self):
+ assertThat(True).isTrue()
+ assertThat(False).isFalse()
+
+ def test_assertThat_boolean_falseIsTrue(self):
+ try:
+ assertThat(False).isTrue()
+ except Exception as e:
+ return True
+ return False
+
+ def test_assertThat_boolean_trueIsFalse(self):
+ try:
+ assertThat(True).isFalse()
+ except Exception as e:
+ return True
+ return False
+
+ def test_assertThat_object_success(self):
+ assertThat("this").isEqualTo("this")
+ assertThat("this").isNotEqualTo("that")
+ assertThat(None).isNone()
+ assertThat("this").isNotNone()
+
+ def test_assertThat_object_isEqualToFails(self):
+ try:
+ assertThat("this").isEqualTo("that")
+ except Exception as e:
+ return True
+ return False
+
+ def test_assertThat_object_isNotEqualToFails(self):
+ try:
+ assertThat("this").isNotEqualTo("this")
+ except Exception as e:
+ return True
+ return False
+
+ def test_assertThat_object_isNoneFails(self):
+ try:
+ assertThat("this").isNone()
+ except Exception as e:
+ return True
+ return False
+
+ def test_assertThat_object_isNotNoneFails(self):
+ try:
+ assertThat(None).isNotNone()
+ except Exception as e:
+ return True
+ return False
--- /dev/null
+#!/usr/bin/env python3
+#
+# Copyright 2020 - 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 time
+
+from mobly.asserts import assert_true
+from mobly.asserts import assert_false
+
+from mobly import signals
+
+import sys, traceback
+
+
+class ObjectSubject(object):
+
+ def __init__(self, value):
+ self._value = value
+
+ def isEqualTo(self, other):
+ if self._value != other:
+ raise signals.TestFailure(
+ "Expected \"%s\" to be equal to \"%s\"" % (self._value, other),
+ extras=None)
+
+ def isNotEqualTo(self, other):
+ if self._value == other:
+ raise signals.TestFailure(
+ "Expected \"%s\" to not be equal to \"%s\"" % (self._value,
+ other),
+ extras=None)
+
+ def isNone(self):
+ if self._value is not None:
+ raise signals.TestFailure(
+ "Expected \"%s\" to be None" % self._value, extras=None)
+
+ def isNotNone(self):
+ if self._value is None:
+ raise signals.TestFailure(
+ "Expected \"%s\" to not be None" % self._value, extras=None)
+
+
+class BooleanSubject(ObjectSubject):
+
+ def __init__(self, value):
+ super().__init__(value)
+
+ def isTrue(self):
+ assert_true(self._value, "")
+
+ def isFalse(self):
+ assert_false(self._value, "")
+
+
+def assertThat(subject):
+ if type(subject) is bool:
+ return BooleanSubject(subject)
+ else:
+ return ObjectSubject(subject)
import time
-from mobly.asserts import assert_true
from cert.gd_base_test_facade_only import GdFacadeOnlyBaseTestClass
+from cert.truth import assertThat
from google.protobuf import empty_pb2 as empty_proto
from facade import rootservice_pb2 as facade_rootservice
from hci.facade import controller_facade_pb2 as controller_facade
def test_get_addresses(self):
cert_address = self.cert.hci_controller.GetMacAddressSimple()
dut_address = self.dut.hci_controller.GetMacAddressSimple()
- assert_true(
- cert_address != dut_address,
- msg="Expected cert and dut address to be different %s" %
- cert_address)
+
+ assertThat(cert_address).isNotEqualTo(dut_address)
time.sleep(1) # This shouldn't be needed b/149120542
def test_get_local_extended_features(self):
request0.page_number = 0
dut_feature_response0 = self.dut.hci_controller.GetLocalExtendedFeatures(
request0)
- assert_true(
- dut_feature_response1.page != dut_feature_response0.page,
- msg="Expected cert dut feature pages to be different %d" %
- dut_feature_response1.page)
+
+ assertThat(dut_feature_response1.page).isNotEqualTo(
+ dut_feature_response0.page)
def test_write_local_name(self):
self.dut.hci_controller.WriteLocalName(
controller_facade.NameMsg(name=b'ImTheCert'))
cert_name = self.cert.hci_controller.GetLocalNameSimple()
dut_name = self.dut.hci_controller.GetLocalNameSimple()
- assert_true(
- dut_name == b'ImTheDUT', msg="unexpected dut name %s" % dut_name)
- assert_true(
- cert_name == b'ImTheCert',
- msg="unexpected cert name %s" % cert_name)
+
+ assertThat(dut_name).isEqualTo(b'ImTheDUT')
+ assertThat(cert_name).isEqualTo(b'ImTheCert')