Example #1
0
    def _execute_query(
        cls,
        connection_info: misc_utils.ConnectionInfo,
        search_info: misc_utils.SearchInfo,
        timeout: float,
    ):
        """
        Takes in the given arguments and uses them to print out a formatted
        string of items the user wants to see from the Test API; if the option
        is present, repeat doing this until the user exits the program.

        For descriptions of these arguments, and more function details, see:
            Gds/src/fprime_gds/executables/fprime_cli.py
        """
        dictionary, ip_address, port = tuple(connection_info)
        is_printing_list, ids, components, search, json = tuple(search_info)

        search_filter = cls._get_search_filter(ids, components, search, json)
        if is_printing_list:
            cls._log(
                cls._list_all_possible_items(dictionary, search_filter, json))
            return

        # ======================================================================
        # Set up Test API
        pipeline, api = test_api_utils.initialize_test_api(
            dictionary, server_ip=ip_address, server_port=port)
        # ======================================================================

        if timeout:
            item = cls._get_upcoming_item(api, search_filter, "NOW", timeout)
            cls._log(cls._get_item_string(item, json))
        else:

            def print_upcoming_item(min_start_time="NOW"):
                item = cls._get_upcoming_item(api, search_filter,
                                              min_start_time)
                cls._log(cls._get_item_string(item, json))
                # Update time so we catch the next item since the last one
                if item:
                    min_start_time = predicates.greater_than(item.get_time())
                    min_start_time = filtering_utils.time_to_data_predicate(
                        min_start_time)
                return (min_start_time, )

            misc_utils.repeat_until_interrupt(print_upcoming_item, "NOW")

        # ======================================================================
        # Tear down Test API
        pipeline.disconnect()
        api.teardown()
Example #2
0
def test_repeat_with_void_function_valid():
    """
    Test repeating with a function that doesn't return anything still works
    """
    count = 0

    def exit_at_value(exit_num):
        nonlocal count
        count += 1
        if count == exit_num:
            raise KeyboardInterrupt

    misc_utils.repeat_until_interrupt(exit_at_value, 5)

    assert count == 5
Example #3
0
def test_repeat_with_function_returning_enclosed_string_valid():
    """
    Test that returning a string when encapsulating it in a tuple will count
    it as just 1 argument
    """
    count = 0

    def error_before_exit(my_string):
        nonlocal count
        count += 1
        if count == 2:
            raise KeyboardInterrupt
        return (my_string, )  # this is only 1 argument, since it's in a tuple

    misc_utils.repeat_until_interrupt(error_before_exit, "let's do this")
Example #4
0
def test_repeat_with_no_arg_returning_function_invalid():
    """
    Test repeating with a function that takes no arguments but still returns a
    value is invalid
    """
    count = 0

    def error_before_exit():
        nonlocal count
        count += 1
        if count == 2:
            raise KeyboardInterrupt
        return "this should cause an error"

    with pytest.raises(TypeError):
        misc_utils.repeat_until_interrupt(error_before_exit)
Example #5
0
def test_repeat_with_no_arg_void_function_valid():
    """
    Test repeating with a function that takes no arguments doesn't throw an
    exception
    """
    count = 0

    def exit_when_3():
        nonlocal count
        count += 1
        if count == 3:
            raise KeyboardInterrupt

    misc_utils.repeat_until_interrupt(exit_when_3)

    assert count == 3
Example #6
0
def test_repeat_with_function_returning_naked_string_problematic():
    """
    Test that returning a string without encapsulating it in a tuple will fail,
    since every character will be counted as a different argument
    """
    count = 0

    def error_before_exit():
        nonlocal count
        count += 1
        if count == 2:
            raise KeyboardInterrupt
        return "this will return 49 arguments, because characters"

    with pytest.raises(TypeError):
        misc_utils.repeat_until_interrupt(error_before_exit)
Example #7
0
def test_repeat_exits_at_counter():
    """
    Test basic functionality works as intended, can pass updated arguments, and
    exits on KeyboardInterrupt
    """
    count = 0

    def increment_count():
        nonlocal count
        count += 1

    def increment_with_interrupt(counter, exit_num, external_func):
        if counter == exit_num:
            raise KeyboardInterrupt
        external_func()
        return (counter + 1, exit_num, external_func)

    misc_utils.repeat_until_interrupt(increment_with_interrupt, 0, 3,
                                      increment_count)

    assert count == 3