Ejemplo n.º 1
0
    def test_await_telemetry_count(self):
        count_seq = self.get_counter_sequence(20)
        sin_seq = self.get_oscillator_sequence(100)

        pred = predicates.greater_than_or_equal_to(10)
        search_pred = self.api.get_telemetry_pred("Counter", pred)
        count_pred = predicates.within_range(10, 20)

        t1 = self.fill_history_async(self.pipeline.enqueue_telemetry,
                                     count_seq, 0.05)
        t2 = self.fill_history_async(self.pipeline.enqueue_telemetry, sin_seq,
                                     0.01)
        results = self.api.await_telemetry_count(count_pred, search_pred)
        msg = predicates.get_descriptive_string(len(results), count_pred)
        assert count_pred(len(results)), msg
        t1.join()
        t2.join()

        self.api.clear_histories()

        t1 = self.fill_history_async(self.pipeline.enqueue_telemetry,
                                     count_seq, 0.05)
        t2 = self.fill_history_async(self.pipeline.enqueue_telemetry, sin_seq,
                                     0.01)
        results = self.api.await_telemetry_count(100)
        assert len(results) == 100, "await count should have found 100 items"
        t1.join()
        t2.join()

        self.fill_history_async(self.pipeline.enqueue_telemetry, count_seq,
                                0.05)
        self.fill_history_async(self.pipeline.enqueue_telemetry, sin_seq, 0.02)
        results = self.api.await_telemetry_count(100, timeout=1)
        assert len(
            results) < 100, "await count should have found fewer 100 items"
Ejemplo n.º 2
0
 def test_within_range(self):
     pred = predicates.within_range(5, 10)
     assert pred(5), "5 is the lower bound and within [5,10]"
     assert pred(10), "10 is the upper bound and within [5,10]"
     assert pred(7.5), "7.5 is within [5,10]"
     assert not pred(2), "2 is not within [5,10]"
     assert not pred(11), "2 is not within [5,10]"
     self.check_str(pred)
    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)
Ejemplo n.º 4
0
    def test_assert_telemetry_count(self):
        count_seq = self.get_counter_sequence(20)
        sin_seq = self.get_oscillator_sequence(100)

        pred = predicates.greater_than_or_equal_to(10)
        search_pred = self.api.get_telemetry_pred("Counter", pred)
        count_pred = predicates.within_range(10, 20)

        self.fill_history_async(self.pipeline.enqueue_telemetry, count_seq,
                                0.05)
        self.fill_history_async(self.pipeline.enqueue_telemetry, sin_seq, 0.01)
        self.api.assert_telemetry_count(count_pred, search_pred, timeout=2)
        self.api.assert_telemetry_count(count_pred, search_pred)

        self.api.clear_histories()

        t1 = self.fill_history_async(self.pipeline.enqueue_telemetry,
                                     count_seq, 0.05)
        t2 = self.fill_history_async(self.pipeline.enqueue_telemetry, sin_seq,
                                     0.01)
        self.api.assert_telemetry_count(100, timeout=2)
        t1.join()
        t2.join()
        try:
            self.api.assert_telemetry_count(100)
            raise self.AssertionFailure()
        except AssertionError:
            assert True, "api raised the correct error"
        except self.AssertionFailure:
            assert False, "api failed to raise an assertion error"

        self.api.clear_histories()

        self.fill_history_async(self.pipeline.enqueue_telemetry, count_seq,
                                0.05)
        self.fill_history_async(self.pipeline.enqueue_telemetry, sin_seq, 0.02)
        try:
            self.api.assert_telemetry_count(100, timeout=1)
            raise self.AssertionFailure()
        except AssertionError:
            assert True, "api raised the correct error"
        except self.AssertionFailure:
            assert False, "api failed to raise an assertion error"
    def test_args_predicates(self):
        a_list = ['a', 'p', 'p', 'l', 'e']
        pred = predicates.args_predicate(['a', 'p', 'p', 'l', 'e'])
        assert pred(a_list), "The list {} should have been accepted".format(
            a_list)
        a_list[4] = 'r'
        assert not pred(
            a_list), "The list {} should not have been accepted".format(a_list)
        a_list = ['a', 'p', 'p', 'l']
        assert not pred(
            a_list), "The list {} should not have been accepted".format(a_list)

        a_list = ['a', 'p', 'p', 'l', 'e']
        pred = predicates.args_predicate(['a', 'p', 'p', 'l', None])
        assert pred(a_list), "The list {} should have been accepted".format(
            a_list)
        a_list[4] = 7
        assert pred(a_list), "The list {} should have been accepted".format(
            a_list)
        a_list[4] = 'r'
        assert pred(a_list), "The list {} should have been accepted".format(
            a_list)

        l_pred = predicates.within_range(0, 10)
        pred = predicates.args_predicate([l_pred, 2, 3, 4, 5, 6])

        n_list = [1, 2, 3, 4, 5, 6]
        assert pred(n_list), "The list {} should have been accepted".format(
            n_list)

        for i in range(0, 10):
            n_list[0] = i
            assert pred(
                n_list), "The list {} should have been accepted".format(n_list)
        n_list[0] = -5
        assert not pred(
            n_list), "The list {} should not have been accepted".format(n_list)
        n_list[0] = 15
        assert not pred(
            n_list), "The list {} should not have been accepted".format(n_list)

        pred = predicates.args_predicate(8)
        assert pred(8), "The value 8 should have been accepted."