From 27804d72217fb5b85e04f600f2d14ef3d695fcc3 Mon Sep 17 00:00:00 2001 From: Sourcery AI <> Date: Sat, 22 Apr 2023 06:22:57 +0000 Subject: [PATCH] 'Refactored by Sourcery' --- src/fastentrypoints.py | 6 +-- src/fprime_gds/common/data_types/ch_data.py | 18 +++++---- src/fprime_gds/common/data_types/cmd_data.py | 8 ++-- .../common/data_types/event_data.py | 20 ++++++---- src/fprime_gds/common/data_types/pkt_data.py | 2 +- .../common/decoders/file_decoder.py | 6 +-- src/fprime_gds/common/encoders/ch_encoder.py | 4 +- src/fprime_gds/common/encoders/cmd_encoder.py | 4 +- .../common/encoders/event_encoder.py | 4 +- src/fprime_gds/common/encoders/pkt_encoder.py | 4 +- src/fprime_gds/common/files/downlinker.py | 3 +- src/fprime_gds/common/files/uplinker.py | 4 +- .../common/gds_cli/base_commands.py | 4 +- src/fprime_gds/common/gds_cli/channels.py | 3 +- src/fprime_gds/common/gds_cli/command_send.py | 11 ++---- src/fprime_gds/common/gds_cli/events.py | 3 +- .../common/gds_cli/filtering_utils.py | 2 +- .../common/gds_cli/test_api_utils.py | 3 +- .../common/models/common/channel_telemetry.py | 3 +- src/fprime_gds/common/models/common/event.py | 3 +- .../common/parsers/seq_file_parser.py | 2 +- .../common/templates/event_template.py | 2 - src/fprime_gds/common/testing_fw/api.py | 2 - src/fprime_gds/common/tools/seqgen.py | 15 +++----- src/fprime_gds/executables/cli.py | 19 +++++----- src/fprime_gds/executables/fprime_cli.py | 9 ++--- src/fprime_gds/executables/run_deployment.py | 13 +++---- src/fprime_gds/executables/tcpserver.py | 4 +- src/fprime_gds/executables/utils.py | 6 +-- src/fprime_gds/flask/flask_uploads.py | 37 ++++++++----------- src/fprime_gds/flask/json.py | 2 +- .../common/gds_cli/filtering_utils_test.py | 3 +- .../common/testing_fw/api_unit_test.py | 15 ++++---- .../common/testing_fw/predicate_unit_test.py | 2 - 34 files changed, 100 insertions(+), 146 deletions(-) diff --git a/src/fastentrypoints.py b/src/fastentrypoints.py index 22ef2413..75ba09b5 100644 --- a/src/fastentrypoints.py +++ b/src/fastentrypoints.py @@ -56,7 +56,7 @@ @classmethod -def get_args(cls, dist, header=None): # noqa: D205,D400 +def get_args(cls, dist, header=None): # noqa: D205,D400 """ Yield write_script() argument tuples for a distribution's console_scripts and gui_scripts entry points. @@ -74,9 +74,7 @@ def get_args(cls, dist, header=None): # noqa: D205,D400 script_text = TEMPLATE.format( ep.module_name, ep.attrs[0], ".".join(ep.attrs), spec, group, name ) - # pylint: disable=E1101 - args = cls._get_script_args(type_, name, header, script_text) - yield from args + yield from cls._get_script_args(type_, name, header, script_text) # pylint: disable=E1101 diff --git a/src/fprime_gds/common/data_types/ch_data.py b/src/fprime_gds/common/data_types/ch_data.py index 2bc8b49f..23633c48 100644 --- a/src/fprime_gds/common/data_types/ch_data.py +++ b/src/fprime_gds/common/data_types/ch_data.py @@ -63,13 +63,15 @@ def _compute_display_text(self, val_obj, template): # in which case we just display the description if val_obj is None: return template.ch_desc - temp_val = val_obj.val if not isinstance(val_obj, (SerializableType, ArrayType)) else val_obj.formatted_val + temp_val = ( + val_obj.formatted_val + if isinstance(val_obj, (SerializableType, ArrayType)) + else val_obj.val + ) fmt_str = template.get_format_str() if temp_val is None: return "" - if fmt_str: - return format_string_template(fmt_str, (temp_val,)) - return temp_val + return format_string_template(fmt_str, (temp_val,)) if fmt_str else temp_val def set_pkt(self, pkt): """ @@ -166,13 +168,13 @@ def get_str(self, time_zone=None, verbose=False, csv=False): ch_name = self.template.get_full_name() display_text = self.get_display_text() - if verbose and csv: - return f"{time_str_nice},{raw_time_str},{ch_name},{self.id},{display_text}" - if verbose and not csv: + if verbose: + if csv: + return f"{time_str_nice},{raw_time_str},{ch_name},{self.id},{display_text}" return ( f"{time_str_nice}: {ch_name} ({self.id}) {raw_time_str} {display_text}" ) - if not verbose and csv: + if csv: return f"{time_str_nice},{ch_name},{display_text}" return f"{time_str_nice}: {ch_name} = {display_text}" diff --git a/src/fprime_gds/common/data_types/cmd_data.py b/src/fprime_gds/common/data_types/cmd_data.py index 5d43b3ec..828e120f 100644 --- a/src/fprime_gds/common/data_types/cmd_data.py +++ b/src/fprime_gds/common/data_types/cmd_data.py @@ -133,11 +133,11 @@ def get_str(self, time_zone=None, verbose=False, csv=False): arg_str = " ".join(str(arg_val_list)) - if verbose and csv: - return f"{time_str},{raw_time_str},{name},{self.id},{arg_str}" - if verbose and not csv: + if verbose: + if csv: + return f"{time_str},{raw_time_str},{name},{self.id},{arg_str}" return f"{time_str}: {name} ({self.id}) {raw_time_str} : {arg_str}" - if not verbose and csv: + if csv: return f"{time_str},{name},{arg_str}" return f"{time_str}: {name} : {arg_str}" diff --git a/src/fprime_gds/common/data_types/event_data.py b/src/fprime_gds/common/data_types/event_data.py index 93b9f0ec..63323c86 100644 --- a/src/fprime_gds/common/data_types/event_data.py +++ b/src/fprime_gds/common/data_types/event_data.py @@ -39,8 +39,12 @@ def __init__(self, event_args, event_time, event_temp): self.args = event_args self.time = event_time self.template = event_temp - self.display_text = event_temp.description if event_args is None else format_string_template( - event_temp.format_str, tuple([arg.val for arg in event_args]) + self.display_text = ( + event_temp.description + if event_args is None + else format_string_template( + event_temp.format_str, tuple(arg.val for arg in event_args) + ) ) def get_args(self): @@ -105,13 +109,13 @@ def get_str(self, time_zone=None, verbose=False, csv=False): severity = self.template.get_severity() display_text = self.display_text - if verbose and csv: - return ( - f"{time_str},{raw_time_str},{name},{self.id},{severity},{display_text}" - ) - if verbose and not csv: + if verbose: + if csv: + return ( + f"{time_str},{raw_time_str},{name},{self.id},{severity},{display_text}" + ) return f"{time_str}: {name} ({self.id}) {raw_time_str} {severity} : {display_text}" - if not verbose and csv: + if csv: return f"{time_str},{name},{severity},{display_text}" return f"{time_str}: {name} {severity} : {display_text}" diff --git a/src/fprime_gds/common/data_types/pkt_data.py b/src/fprime_gds/common/data_types/pkt_data.py index 5f33dc9a..02328d9d 100644 --- a/src/fprime_gds/common/data_types/pkt_data.py +++ b/src/fprime_gds/common/data_types/pkt_data.py @@ -87,7 +87,7 @@ def get_str(self, time_zone=None, verbose=False, csv=False): self.template.get_id(), str(self.time), ) - elif not csv and not verbose: + elif not csv: pkt_str += f"{self.time.to_readable(time_zone)}: {self.template.get_name()} {{\n" for i, ch in enumerate(self.chs): diff --git a/src/fprime_gds/common/decoders/file_decoder.py b/src/fprime_gds/common/decoders/file_decoder.py index c4761523..7045388e 100644 --- a/src/fprime_gds/common/decoders/file_decoder.py +++ b/src/fprime_gds/common/decoders/file_decoder.py @@ -57,8 +57,4 @@ def decode_api(self, data): if packetType == "END": # Packet Type is END hashValue = struct.unpack_from(">I", data, 5) return [file_data.EndPacketData(seqID, hashValue),] - if packetType == "CANCEL": # Packet Type is CANCEL - # CANCEL Packets have no data - return [file_data.CancelPacketData(seqID),] - # The data was not determined to be any of the packet types so return none - return None + return [file_data.CancelPacketData(seqID),] if packetType == "CANCEL" else None diff --git a/src/fprime_gds/common/encoders/ch_encoder.py b/src/fprime_gds/common/encoders/ch_encoder.py index ffb8bb02..21231d68 100644 --- a/src/fprime_gds/common/encoders/ch_encoder.py +++ b/src/fprime_gds/common/encoders/ch_encoder.py @@ -86,6 +86,4 @@ def encode_api(self, data): self.len_obj.val = len_val len_bin = self.len_obj.serialize() - binary_data = len_bin + desc_bin + id_bin + time_bin + val_bin - - return binary_data + return len_bin + desc_bin + id_bin + time_bin + val_bin diff --git a/src/fprime_gds/common/encoders/cmd_encoder.py b/src/fprime_gds/common/encoders/cmd_encoder.py index 3fd32ba3..95bc0b5f 100644 --- a/src/fprime_gds/common/encoders/cmd_encoder.py +++ b/src/fprime_gds/common/encoders/cmd_encoder.py @@ -102,6 +102,4 @@ def encode_api(self, data): self.len_obj.val = length_val length = self.len_obj.serialize() - binary_data = desc + length + descriptor + op_code + arg_data - - return binary_data + return desc + length + descriptor + op_code + arg_data diff --git a/src/fprime_gds/common/encoders/event_encoder.py b/src/fprime_gds/common/encoders/event_encoder.py index 3216399c..f5c7992f 100644 --- a/src/fprime_gds/common/encoders/event_encoder.py +++ b/src/fprime_gds/common/encoders/event_encoder.py @@ -92,6 +92,4 @@ def encode_api(self, data): self.len_obj.val = len_val len_bin = self.len_obj.serialize() - binary_data = len_bin + desc_bin + id_bin + time_bin + arg_bin - - return binary_data + return len_bin + desc_bin + id_bin + time_bin + arg_bin diff --git a/src/fprime_gds/common/encoders/pkt_encoder.py b/src/fprime_gds/common/encoders/pkt_encoder.py index 02e7d03a..2f3994e6 100644 --- a/src/fprime_gds/common/encoders/pkt_encoder.py +++ b/src/fprime_gds/common/encoders/pkt_encoder.py @@ -92,6 +92,4 @@ def encode_api(self, data): self.len_obj.val = len_val len_bin = self.len_obj.serialize() - binary_data = len_bin + desc_bin + id_bin + time_bin + ch_bin - - return binary_data + return len_bin + desc_bin + id_bin + time_bin + ch_bin diff --git a/src/fprime_gds/common/files/downlinker.py b/src/fprime_gds/common/files/downlinker.py index b1ebe9e2..5dd89706 100644 --- a/src/fprime_gds/common/files/downlinker.py +++ b/src/fprime_gds/common/files/downlinker.py @@ -97,8 +97,7 @@ def handle_start(self, data): ) self.active.open(TransmitFileState.WRITE) LOGGER.addHandler(self.active.log_handler) - message = "Received START packet with metadata:\n" - message += "\tSize: %d\n" + message = "Received START packet with metadata:\n" + "\tSize: %d\n" message += "\tSource: %s\n" message += "\tDestination: %s" LOGGER.info(message, size, source_path, dest_path) diff --git a/src/fprime_gds/common/files/uplinker.py b/src/fprime_gds/common/files/uplinker.py index 3fbbe7e8..bfdcea0c 100644 --- a/src/fprime_gds/common/files/uplinker.py +++ b/src/fprime_gds/common/files/uplinker.py @@ -87,9 +87,7 @@ def remove(self, source): try: first = None found = self.queue.get_nowait() - while found != first: - if found.source == source: - break + while found != first and found.source != source: if first is None: first = found self.queue.put_nowait(found) diff --git a/src/fprime_gds/common/gds_cli/base_commands.py b/src/fprime_gds/common/gds_cli/base_commands.py index aa9976d6..504f8507 100644 --- a/src/fprime_gds/common/gds_cli/base_commands.py +++ b/src/fprime_gds/common/gds_cli/base_commands.py @@ -232,9 +232,7 @@ def _get_item_string( """ if not item: return "" - if as_json: - return json.dumps(item.get_dict()) - return item.get_str(verbose=True) + return json.dumps(item.get_dict()) if as_json else item.get_str(verbose=True) @classmethod def _execute_command(cls, args, api: IntegrationTestAPI): diff --git a/src/fprime_gds/common/gds_cli/channels.py b/src/fprime_gds/common/gds_cli/channels.py index 5a7d89fe..dc4c9247 100644 --- a/src/fprime_gds/common/gds_cli/channels.py +++ b/src/fprime_gds/common/gds_cli/channels.py @@ -38,12 +38,11 @@ def _get_item_list( channels :return: List of channels that passed the filter """ - channel_list = test_api_utils.get_item_list( + return test_api_utils.get_item_list( item_dictionary=project_dictionary.channel_id, search_filter=filter_predicate, template_to_data=ChData.get_empty_obj, ) - return channel_list @classmethod def _get_upcoming_item( diff --git a/src/fprime_gds/common/gds_cli/command_send.py b/src/fprime_gds/common/gds_cli/command_send.py index 339e24da..86ac8bd4 100644 --- a/src/fprime_gds/common/gds_cli/command_send.py +++ b/src/fprime_gds/common/gds_cli/command_send.py @@ -37,8 +37,7 @@ def _get_closest_commands( :return: A list of the closest matching commands (potentially empty) """ known_commands = project_dictionary.command_name.keys() - closest_matches = difflib.get_close_matches(command_name, known_commands, n=num) - return closest_matches + return difflib.get_close_matches(command_name, known_commands, n=num) @staticmethod def _get_command_template( @@ -130,8 +129,7 @@ def _get_item_string( len(item.get_args()), ) - cmd_description = item.get_description() - if cmd_description: + if cmd_description := item.get_description(): cmd_string += f"Description: {(cmd_description)}\n" for arg in item.get_args(): @@ -159,10 +157,9 @@ def _execute_command(cls, args, api: IntegrationTestAPI): api.send_command(command, arguments) except KeyError: cls._log(f"{command} is not a known command") - close_matches = cls._get_closest_commands( + if close_matches := cls._get_closest_commands( api.pipeline.dictionaries, command - ) - if close_matches: + ): cls._log(f"Similar known commands: {close_matches}") except NotInitializedException: temp = cls._get_command_template(api.pipeline.dictionaries, command) diff --git a/src/fprime_gds/common/gds_cli/events.py b/src/fprime_gds/common/gds_cli/events.py index 1f01d959..a4118772 100644 --- a/src/fprime_gds/common/gds_cli/events.py +++ b/src/fprime_gds/common/gds_cli/events.py @@ -37,12 +37,11 @@ def _get_item_list( :param filter_predicate: Test API predicate used to filter shown events :return: List of EventData items that passed the filter """ - event_list = test_api_utils.get_item_list( + return test_api_utils.get_item_list( item_dictionary=project_dictionary.event_id, search_filter=filter_predicate, template_to_data=EventData.get_empty_obj, ) - return event_list @classmethod def _get_upcoming_item( diff --git a/src/fprime_gds/common/gds_cli/filtering_utils.py b/src/fprime_gds/common/gds_cli/filtering_utils.py index 3c938e5a..44741a9a 100644 --- a/src/fprime_gds/common/gds_cli/filtering_utils.py +++ b/src/fprime_gds/common/gds_cli/filtering_utils.py @@ -109,7 +109,7 @@ def __init__(self, search_string: str, to_string_func: Callable[[Any], str] = st :param to_string_func: An optional method for converting the given object to a string """ - self.search_string = str(search_string) + self.search_string = search_string self.to_str = to_string_func def __call__(self, item): diff --git a/src/fprime_gds/common/gds_cli/test_api_utils.py b/src/fprime_gds/common/gds_cli/test_api_utils.py index db0317f4..61fafe07 100644 --- a/src/fprime_gds/common/gds_cli/test_api_utils.py +++ b/src/fprime_gds/common/gds_cli/test_api_utils.py @@ -123,8 +123,7 @@ def repeat_until_interrupt(func: Callable, *args): """ try: while True: - new_args = func(*args) # lgtm [py/call/wrong-arguments] - if new_args: + if new_args := func(*args): args = new_args except KeyboardInterrupt: pass \ No newline at end of file diff --git a/src/fprime_gds/common/models/common/channel_telemetry.py b/src/fprime_gds/common/models/common/channel_telemetry.py index 422423e2..199d0a87 100644 --- a/src/fprime_gds/common/models/common/channel_telemetry.py +++ b/src/fprime_gds/common/models/common/channel_telemetry.py @@ -169,6 +169,5 @@ def changed(self): @changed.setter def changed(self, ch): - if not ch == False or not ch == True: - ch = True + ch = True self.__changed = ch diff --git a/src/fprime_gds/common/models/common/event.py b/src/fprime_gds/common/models/common/event.py index 5e01d5a1..197957c4 100644 --- a/src/fprime_gds/common/models/common/event.py +++ b/src/fprime_gds/common/models/common/event.py @@ -92,8 +92,7 @@ def deserialize(self, ser_data): vals.append("ERR") offset = offset + arg_obj.getSize() - vals = [0] + vals - return vals + return [0] + vals def stringify(self, event_args_list): """ diff --git a/src/fprime_gds/common/parsers/seq_file_parser.py b/src/fprime_gds/common/parsers/seq_file_parser.py index 50053951..0472ea5e 100644 --- a/src/fprime_gds/common/parsers/seq_file_parser.py +++ b/src/fprime_gds/common/parsers/seq_file_parser.py @@ -99,7 +99,7 @@ def parseArg(arg): # Otherwise it is an enum type: return str(arg) - return [item for item in map(parseArg, args)] + return list(map(parseArg, args)) def parseTime(lineNumber, time): """ diff --git a/src/fprime_gds/common/templates/event_template.py b/src/fprime_gds/common/templates/event_template.py index 2edeb089..18b9d9de 100644 --- a/src/fprime_gds/common/templates/event_template.py +++ b/src/fprime_gds/common/templates/event_template.py @@ -126,5 +126,3 @@ def get_args(self): return self.args -if __name__ == "__main__": - pass diff --git a/src/fprime_gds/common/testing_fw/api.py b/src/fprime_gds/common/testing_fw/api.py index bc94f024..05428e3e 100644 --- a/src/fprime_gds/common/testing_fw/api.py +++ b/src/fprime_gds/common/testing_fw/api.py @@ -1264,8 +1264,6 @@ def __assert_pred(self, name, predicate, value, msg="", expect=False): if predicate(value): ast_msg = f"{name} succeeded: {msg}\nassert {pred_msg}" self.__log(ast_msg, TestLogger.GREEN) - if not expect: - assert True, pred_msg return True ast_msg = f"{name} failed: {msg}\nassert {pred_msg}" if not expect: diff --git a/src/fprime_gds/common/tools/seqgen.py b/src/fprime_gds/common/tools/seqgen.py index b7cf254a..fa5501c6 100644 --- a/src/fprime_gds/common/tools/seqgen.py +++ b/src/fprime_gds/common/tools/seqgen.py @@ -48,25 +48,24 @@ def generateSequence(inputFile, outputFile, dictionary, timebase, cont=False): # Check for files if not os.path.isfile(inputFile): - raise SeqGenException("Can't open file '" + inputFile + "'. ") + raise SeqGenException(f"Can't open file '{inputFile}'. ") if not os.path.isfile(dictionary): - raise SeqGenException("Can't open file '" + dictionary + "'. ") + raise SeqGenException(f"Can't open file '{dictionary}'. ") # Check the user environment: cmd_xml_dict = CmdXmlLoader() try: (cmd_id_dict, cmd_name_dict, versions) = cmd_xml_dict.construct_dicts(dictionary) except gseExceptions.GseControllerUndefinedFileException: - raise SeqGenException("Can't open file '" + dictionary + "'. ") + raise SeqGenException(f"Can't open file '{dictionary}'. ") - # Parse the input file: - command_list = [] file_parser = SeqFileParser() parsed_seq = file_parser.parse(inputFile, cont=cont) messages = [] + command_list = [] try: for i, descriptor, seconds, useconds, mnemonic, args in parsed_seq: try: @@ -75,9 +74,7 @@ def generateSequence(inputFile, outputFile, dictionary, timebase, cont=False): "Line %d: %s" % ( i + 1, - "'" - + mnemonic - + "' does not match any command in the command dictionary.", + f"'{mnemonic}' does not match any command in the command dictionary.", ) ) # Set the command arguments: @@ -104,7 +101,7 @@ def generateSequence(inputFile, outputFile, dictionary, timebase, cont=False): writer.open(outputFile) except: raise SeqGenException( - "Encountered problem opening output file '" + outputFile + "'." + f"Encountered problem opening output file '{outputFile}'." ) writer.write(command_list) diff --git a/src/fprime_gds/executables/cli.py b/src/fprime_gds/executables/cli.py index abcbbd4a..6e438ab1 100644 --- a/src/fprime_gds/executables/cli.py +++ b/src/fprime_gds/executables/cli.py @@ -124,9 +124,9 @@ def cli_arguments(flags, argparse_inputs) -> List[str]: elif action != "store" or value is None: return [] return [best_flag] + ( - [str(value)] - if not isinstance(value, list) - else [str(item) for item in value] + [str(item) for item in value] + if isinstance(value, list) + else [str(value)] ) cli_pairs = [ @@ -256,7 +256,7 @@ def get_arguments(self) -> Dict[Tuple[str, ...], Dict[str, Any]]: """Get the argument from all constituents""" arguments = {} for constituent in self.constituents: - arguments.update(constituent.get_arguments()) + arguments |= constituent.get_arguments() return arguments def handle_arguments(self, args, **kwargs): @@ -287,15 +287,16 @@ def get_arguments(self) -> Dict[Tuple[str, ...], Dict[str, Any]]: file=sys.stderr, ) continue - adapter_arguments.update(adapter.get_arguments()) + adapter_arguments |= adapter.get_arguments() com_arguments = { ("--comm-adapter",): { "dest": "adapter", "action": "store", "type": str, "help": "Adapter for communicating to flight deployment. [default: %(default)s]", - "choices": ["none"] - + [name for name in adapter_definition_dictionaries.keys()], + "choices": ( + ["none"] + list(adapter_definition_dictionaries.keys()) + ), "default": "ip", }, ("--comm-checksum-type",): { @@ -442,7 +443,7 @@ def get_arguments(self) -> Dict[Tuple[str, ...], Dict[str, Any]]: "default": "0.0.0.0", }, } - return {**zmq_arguments, **tts_arguments} + return zmq_arguments | tts_arguments def handle_arguments(self, args, **kwargs): """ @@ -754,7 +755,7 @@ def get_arguments(self) -> Dict[Tuple[str, ...], Dict[str, Any]]: "dest": "json", "action": "store_true", "required": False, - "help": f"returns response in JSON format", + "help": "returns response in JSON format", }, } diff --git a/src/fprime_gds/executables/fprime_cli.py b/src/fprime_gds/executables/fprime_cli.py index 76d1382d..b6de7362 100644 --- a/src/fprime_gds/executables/fprime_cli.py +++ b/src/fprime_gds/executables/fprime_cli.py @@ -166,11 +166,10 @@ def create_subparser(cls, parent_parser: argparse.ArgumentParser): """ Creates the channels sub-command as a subparser, and then returns it """ - channels_parser = parent_parser.add_parser( + return parent_parser.add_parser( "channels", description="print out new telemetry data that has been received from the F Prime instance, sorted by timestamp", ) - return channels_parser @classmethod def add_arguments(cls, parser: argparse.ArgumentParser): @@ -204,11 +203,10 @@ def create_subparser(cls, parent_parser: argparse.ArgumentParser): """ Creates the command-send sub-command as a subparser, and then returns it """ - command_send_parser = parent_parser.add_parser( + return parent_parser.add_parser( "command-send", description="sends the given command to the spacecraft via the GDS", ) - return command_send_parser @staticmethod def complete_command_name( @@ -292,11 +290,10 @@ def create_subparser(cls, parent_parser: argparse.ArgumentParser): """ Creates the events sub-command as a subparser, and then returns it """ - events_parser = parent_parser.add_parser( + return parent_parser.add_parser( "events", description="print out new events that have occurred on the F Prime instance, sorted by timestamp", ) - return events_parser @classmethod def add_arguments(cls, parser: argparse.ArgumentParser): diff --git a/src/fprime_gds/executables/run_deployment.py b/src/fprime_gds/executables/run_deployment.py index ffffb4bf..41de05ae 100644 --- a/src/fprime_gds/executables/run_deployment.py +++ b/src/fprime_gds/executables/run_deployment.py @@ -89,14 +89,11 @@ def launch_html(parsed_args): reproduced_arguments = StandardPipelineParser().reproduce_cli_args(parsed_args) if "--log-directly" not in reproduced_arguments: reproduced_arguments += ["--log-directly"] - flask_env = os.environ.copy() - flask_env.update( - { - "FLASK_APP": "fprime_gds.flask.app", - "STANDARD_PIPELINE_ARGUMENTS": "|".join(reproduced_arguments), - "SERVE_LOGS": "YES", - } - ) + flask_env = os.environ | { + "FLASK_APP": "fprime_gds.flask.app", + "STANDARD_PIPELINE_ARGUMENTS": "|".join(reproduced_arguments), + "SERVE_LOGS": "YES", + } gse_args = BASE_MODULE_ARGUMENTS + [ "flask", "run", diff --git a/src/fprime_gds/executables/tcpserver.py b/src/fprime_gds/executables/tcpserver.py index 6dd0c4e6..8adcb49d 100644 --- a/src/fprime_gds/executables/tcpserver.py +++ b/src/fprime_gds/executables/tcpserver.py @@ -383,9 +383,7 @@ def readData(self, header, packet): # Read telemetry data here... tlm_packet_size = packet[:4] size = struct.unpack(">I", tlm_packet_size)[0] - data = tlm_packet_size + packet[4 : 4 + size] - - return data + return tlm_packet_size + packet[4 : 4 + size] def processNewPkt(self, header, data): """ diff --git a/src/fprime_gds/executables/utils.py b/src/fprime_gds/executables/utils.py index cef90467..879d2075 100644 --- a/src/fprime_gds/executables/utils.py +++ b/src/fprime_gds/executables/utils.py @@ -62,7 +62,7 @@ def assassin(): else: process.kill(signal.SIGINT) time.sleep(1) - except (KeyboardInterrupt, OSError, InterruptedError): + except (KeyboardInterrupt, OSError): pass # Second attempt is to terminate with extreme prejudice. No process will survive this, ensuring that it is # really, really dead. Supports both pexpect and subprocess. @@ -71,13 +71,13 @@ def assassin(): process.kill() else: process.kill(signal.SIGKILL) - except (KeyboardInterrupt, OSError, InterruptedError): + except (KeyboardInterrupt, OSError): pass # Might as well close the log file because dead men tell no tales. try: if log is not None: log.close() - except (KeyboardInterrupt, OSError, InterruptedError): + except (KeyboardInterrupt, OSError): pass atexit.register(assassin) diff --git a/src/fprime_gds/flask/flask_uploads.py b/src/fprime_gds/flask/flask_uploads.py index f3c243a9..c1d68701 100644 --- a/src/fprime_gds/flask/flask_uploads.py +++ b/src/fprime_gds/flask/flask_uploads.py @@ -11,15 +11,12 @@ Note: originally from https://github.com/maxcountryman/flask-uploads """ + import sys PY3 = sys.version_info[0] == 3 -if PY3: - string_types = (str,) -else: - string_types = (basestring,) - +string_types = (str, ) if PY3 else (basestring, ) import os.path import posixpath @@ -191,24 +188,20 @@ def config_for_set(uset, app, defaults=None): if defaults is None: defaults = dict(dest=None, url=None) - allow_extns = tuple(config.get(prefix + "ALLOW", ())) - deny_extns = tuple(config.get(prefix + "DENY", ())) - destination = config.get(prefix + "DEST") - base_url = config.get(prefix + "URL") - - if destination is None: - # the upload set's destination wasn't given - if uset.default_dest: - # use the "default_dest" callable - destination = uset.default_dest(app) - if destination is None: # still - # use the default dest from the config - if defaults["dest"] is not None: - using_defaults = True - destination = os.path.join(defaults["dest"], uset.name) - else: - raise RuntimeError(f"no destination for set {uset.name}") + allow_extns = tuple(config.get(f"{prefix}ALLOW", ())) + deny_extns = tuple(config.get(f"{prefix}DENY", ())) + destination = config.get(f"{prefix}DEST") + base_url = config.get(f"{prefix}URL") + + if destination is None and uset.default_dest: + # use the "default_dest" callable + destination = uset.default_dest(app) + if destination is None: # still + if defaults["dest"] is None: + raise RuntimeError(f"no destination for set {uset.name}") + using_defaults = True + destination = os.path.join(defaults["dest"], uset.name) if base_url is None and using_defaults and defaults["url"]: base_url = addslash(defaults["url"]) + uset.name + "/" diff --git a/src/fprime_gds/flask/json.py b/src/fprime_gds/flask/json.py index 13c20464..2faeb8ea 100644 --- a/src/fprime_gds/flask/json.py +++ b/src/fprime_gds/flask/json.py @@ -38,7 +38,7 @@ class properties assert issubclass(input_type, BaseType), "Failure to properly encode data" members = getmembers(input_type, lambda value: not isroutine(value) and not isinstance(value, property)) jsonable_dict = {name: value for name, value in members if not name.startswith("_")} - jsonable_dict.update({"name": input_type.__name__}) + jsonable_dict["name"] = input_type.__name__ return jsonable_dict diff --git a/test/fprime_gds/common/gds_cli/filtering_utils_test.py b/test/fprime_gds/common/gds_cli/filtering_utils_test.py index 5a57d6cc..31d3ba62 100644 --- a/test/fprime_gds/common/gds_cli/filtering_utils_test.py +++ b/test/fprime_gds/common/gds_cli/filtering_utils_test.py @@ -28,8 +28,7 @@ def sample_template(): @pytest.fixture def sample_event(sample_template): - event = EventData([], time_type.TimeType(), sample_template) - return event + return EventData([], time_type.TimeType(), sample_template) # A set of valid input filters that should accept the sample event diff --git a/test/fprime_gds/common/testing_fw/api_unit_test.py b/test/fprime_gds/common/testing_fw/api_unit_test.py index 32ad8075..6c6d94aa 100644 --- a/test/fprime_gds/common/testing_fw/api_unit_test.py +++ b/test/fprime_gds/common/testing_fw/api_unit_test.py @@ -146,8 +146,7 @@ def get_oscillator_sequence(self, length): def get_severity_event(self, severity="DIAGNOSTIC"): name = f"apiTester.Severity{severity}" temp = self.pipeline.dictionaries.event_name[name] - event = EventData(tuple(), TimeType(), temp) - return event + return EventData(tuple(), TimeType(), temp) def get_severity_sequence(self, length, severity="DIAGNOSTIC"): return [self.get_severity_event(severity) for _ in range(length)] @@ -779,7 +778,7 @@ def test_assert_telemetry(self): self.api.assert_telemetry("Counter", 8, start="NOW", timeout=1) raise self.AssertionFailure() except AssertionError: - assert True, "api raised the correct error" + pass except self.AssertionFailure: assert False, "api failed to raise an assertion error" @@ -790,7 +789,7 @@ def test_assert_telemetry(self): self.api.assert_telemetry("Counter", 15, timeout=1) raise self.AssertionFailure() except AssertionError: - assert True, "api raised the correct error" + pass except self.AssertionFailure: assert False, "api failed to raise an assertion error" @@ -813,7 +812,7 @@ def test_assert_telemetry_sequence(self): self.api.assert_telemetry_sequence(search_seq, start="NOW", timeout=5) raise self.AssertionFailure() except AssertionError: - assert True, "api raised the correct error" + pass except self.AssertionFailure: assert False, "api failed to raise an assertion error" @@ -825,7 +824,7 @@ def test_assert_telemetry_sequence(self): self.api.assert_telemetry_sequence(search_seq, start="NOW", timeout=1) raise self.AssertionFailure() except AssertionError: - assert True, "api raised the correct error" + pass except self.AssertionFailure: assert False, "api failed to raise an assertion error" @@ -853,7 +852,7 @@ def test_assert_telemetry_count(self): self.api.assert_telemetry_count(100) raise self.AssertionFailure() except AssertionError: - assert True, "api raised the correct error" + pass except self.AssertionFailure: assert False, "api failed to raise an assertion error" @@ -865,7 +864,7 @@ def test_assert_telemetry_count(self): self.api.assert_telemetry_count(100, timeout=1) raise self.AssertionFailure() except AssertionError: - assert True, "api raised the correct error" + pass except self.AssertionFailure: assert False, "api failed to raise an assertion error" diff --git a/test/fprime_gds/common/testing_fw/predicate_unit_test.py b/test/fprime_gds/common/testing_fw/predicate_unit_test.py index 71e18ce9..6b21f12f 100644 --- a/test/fprime_gds/common/testing_fw/predicate_unit_test.py +++ b/test/fprime_gds/common/testing_fw/predicate_unit_test.py @@ -28,7 +28,6 @@ def check_str(pred): try: pred.__str__() print(pred) - assert True, f"predicate provides string summary: {str(pred)}" except NotImplementedError: assert False, "invoking str(pred) was not supported" @@ -69,7 +68,6 @@ def test_Implemented(): str(pred) except NotImplementedError: assert False, "invoking __str__ on an complete subclass of predicate failed" - assert True, "implemented predicate had no problems invoking functions" @staticmethod def test_is_predicate():