def test_telemetry_predicates(self):
        temp1 = ChTemplate(1, "Test Channel 1", "Predicate_Tester", I32Type())
        temp2 = ChTemplate(2, "Test Channel 2", "Predicate_Tester",
                           StringType())
        update1 = ChData(I32Type(20), TimeType(), temp1)
        update2 = ChData(StringType("apple"), TimeType(), temp2)

        pred = predicates.telemetry_predicate()
        assert pred(
            update1
        ), "If no fields are specified a ChData object should return True"
        assert pred(
            update2
        ), "If no fields are specified a ChData object should return True"
        assert not pred(
            "diff object"
        ), "Anything that's not a ChData object should be False"
        assert not pred(
            5), "Anything that's not a ChData object should be False"
        self.check_str(pred)

        id_pred = predicates.equal_to(1)
        pred = predicates.telemetry_predicate(id_pred=id_pred)
        assert pred(update1), "This predicate on the ID 1 should return True"
        assert not pred(
            update2), "This predicate on the ID 2 should return False"
        self.check_str(pred)

        val_pred = predicates.equal_to("apple")
        pred = predicates.telemetry_predicate(value_pred=val_pred)
        assert not pred(
            update1), "This predicate on the value 20 should return False"
        assert pred(
            update2
        ), "This predicate on the value \"apple\" should return True"
        self.check_str(pred)

        time_pred = predicates.equal_to(0)
        pred = predicates.telemetry_predicate(time_pred=time_pred)
        assert pred(update1), "This predicate on the time 0 should return True"
        assert pred(update2), "This predicate on the time 0 should return True"
        self.check_str(pred)

        val_pred = predicates.within_range(10, 30)
        pred = predicates.telemetry_predicate(id_pred, val_pred, time_pred)
        assert pred(
            update1), "Specifying all fields should return True for update 1"
        assert not pred(
            update2), "Specifying all fields should return False for update 2"
        self.check_str(pred)
Exemplo n.º 2
0
def get_upcoming_channel(
    test_api: IntegrationTestAPI,
    search_filter: predicates.predicate,
    start_time="NOW",
    timeout: float = 5,
) -> ChData:
    """
    Returns the next telemetry update matching the given search filter that
    occurs after this is called. Times out after the given amount if no
    matching new updates are found.

    :param test_api: An API instance that will be called to find the next update
    :param search_filter: A predicate each found update is tested against; if
        the item doesn't test "True" against this, we ignore it and keep
        searching
    :param start_time: An optional index or predicate to specify the earliest
        update time to search for
    :param timeout: The maximum time (in seconds) to wait for an update

    :return: The first "ChData" found that passes the filter, or "None" if no
        such update is found within time
    """
    channel_filter = predicates.satisfies_all(
        [search_filter, predicates.telemetry_predicate()])
    # Test API only takes integer timeouts
    return test_api.find_history_item(channel_filter,
                                      test_api.get_telemetry_test_history(),
                                      start_time, int(timeout))
Exemplo n.º 3
0
    def test_get_telemetry_pred(self):
        pred = predicates.telemetry_predicate()
        result = self.api.get_telemetry_pred(pred)
        assert pred == result, "should return when channel is already telem_pred"

        update = self.get_counter_sequence(1)[0]
        pred = self.api.get_telemetry_pred(update.get_id(), update.get_val())
        assert pred(
            update), "predicate should return true when fields are specified"