From cc0f66cf90022f4c41030185716df25b2b1b1e22 Mon Sep 17 00:00:00 2001 From: Mackenzie Grimes - NOAA Affiliate Date: Fri, 20 Oct 2023 16:57:58 -0600 Subject: [PATCH] remove unused path_builder code --- .../idsse_common/idsse/common/path_builder.py | 38 ------------------- python/idsse_common/test/test_path_builder.py | 13 ++++++- 2 files changed, 12 insertions(+), 39 deletions(-) diff --git a/python/idsse_common/idsse/common/path_builder.py b/python/idsse_common/idsse/common/path_builder.py index c82257a8..36c81641 100644 --- a/python/idsse_common/idsse/common/path_builder.py +++ b/python/idsse_common/idsse/common/path_builder.py @@ -185,7 +185,6 @@ def parse_dir(self, dir_: str) -> dict: Returns: dict: Lookup of all information identified and extracted """ - # return self._parse(dir_, self.dir_fmt) return self._parse_times(dir_, self.dir_fmt) def parse_filename(self, filename: str) -> dict: @@ -197,7 +196,6 @@ def parse_filename(self, filename: str) -> dict: Returns: dict: Lookup of all information identified and extracted """ - # return self._parse(filename, self.filename_fmt) filename = os.path.basename(filename) return self._parse_times(filename, self.filename_fmt) @@ -210,7 +208,6 @@ def parse_path(self, path: str) -> dict: Returns: dict: Lookup of all information identified and extracted """ - # return self._parse(path, self.path_fmt) return self._parse_times(path, self.path_fmt) def get_issue(self, path: str) -> datetime: @@ -365,38 +362,3 @@ def parse_args(key: str, value: str, result: Dict): parse_args(res.group(), vals[i][res.span()[0]:], time_args) return time_args - - def _parse(self, string: str, format_str: str) -> Dict: - def get_between(query_str: str, pre_off: str, post_off: str) -> Tuple[str, str]: - idx1 = query_str.index(pre_off) + len(pre_off) - idx2 = query_str.index(post_off, idx1) - return query_str[idx1:idx2], query_str[idx2:] - - def parse_args(key: str, value: str, result: Dict): - for arg in key.split('{')[1:]: - var_name, var_size = arg.split(':') - var_type = var_size[-2:-1] - var_size = int(var_size[:-2]) - match var_type: - case 'd': - result[var_name] = int(value[:var_size]) - case _: - raise ValueError(f'Unknown format type: {var_type}') - key = key[var_size:] - value = value[var_size:] - - constants = [part for part in re.split(r'{.*?}', format_str) if part] - - arg_lookup = {} - for i in range(1, len(constants)): - pre = constants[i-1] - post = constants[i] - format_between, format_str = get_between(format_str, pre, post) - string_between, string = get_between(string, pre, post) - arg_lookup[format_between] = string_between - - time_args = {} - for key, value in arg_lookup.items(): - parse_args(key, value, time_args) - - return time_args diff --git a/python/idsse_common/test/test_path_builder.py b/python/idsse_common/test/test_path_builder.py index 741bf901..06bbd220 100644 --- a/python/idsse_common/test/test_path_builder.py +++ b/python/idsse_common/test/test_path_builder.py @@ -171,7 +171,6 @@ def test_get_valid_returns_none_if_args_empty(): def test_get_valid_from_time_args_calculates_based_on_lead(path_builder: PathBuilder): parsed_dict = path_builder.parse_path(EXAMPLE_FULL_PATH) result_valid: datetime = PathBuilder.get_valid_from_time_args(parsed_args=parsed_dict) - assert result_valid == EXAMPLE_VALID @@ -179,3 +178,15 @@ def test_get_lead_from_time_args(path_builder: PathBuilder): parsed_dict = path_builder.parse_path(EXAMPLE_FULL_PATH) lead_result: timedelta = PathBuilder.get_lead_from_time_args(parsed_dict) assert lead_result.seconds == EXAMPLE_LEAD.minute * 60 + + +def test_calculate_issue_from_valid_and_lead(): + parsed_dict = {} + parsed_dict['valid.year'] = 1970 + parsed_dict['valid.month'] = 10 + parsed_dict['valid.day'] = 3 + parsed_dict['valid.hour'] = 14 + parsed_dict['lead.hour'] = 2 + + result_issue = PathBuilder.get_issue_from_time_args(parsed_args=parsed_dict) + assert result_issue == EXAMPLE_ISSUE