From c44d7070c43f48865db25fff0547835472abd172 Mon Sep 17 00:00:00 2001 From: Norwid Behrnd Date: Sun, 9 Jan 2022 11:25:06 +0100 Subject: [PATCH] reorganize test section --smart-prepend for extension Ahead of the addition of checks about three stamp pattern issued by date2name, the checker about appendfilename's the option --smart-prepent is reorganized to be more compact/easier to be read. For now, this outweights each filename being checked twice. --- test_appendfilename.py | 40 +++++++++++++++++----------------------- test_generator.org | 40 +++++++++++++++++----------------------- 2 files changed, 34 insertions(+), 46 deletions(-) diff --git a/test_appendfilename.py b/test_appendfilename.py index a26df1d..5852c55 100644 --- a/test_appendfilename.py +++ b/test_appendfilename.py @@ -122,29 +122,23 @@ def test_pattern_s3_02(arg1, arg2, arg3): # analysis section: old_filename = str(arg1) - if re.search("^\d{4}-\d{2}-\d{2}_", old_filename): - # if (running date2name in default mode) then .true. - time_stamp = old_filename[:10] - time_stamp_separator = old_filename[10] - file_extension = old_filename.split(".")[-1] - - old_filename_no_timestamp = old_filename[11:] - stem_elements = old_filename_no_timestamp.split(".")[:-1] - stem = ".".join(stem_elements) - - new_filename = "".join([time_stamp, arg3, text, arg3, stem, str("."), file_extension]) - assert os.path.isfile(new_filename) - - os.remove(new_filename) - assert os.path.isfile(new_filename) is False - - elif re.search('^\d{4}-\d{2}-\d{2}T\d{2}\.\d{2}\.\d{2}_', old_filename): - # if (running date2name --withtime) then .true. - time_stamp = old_filename[:19] - time_stamp_separator = old_filename[19] - file_extension = old_filename.split(".")[-1] - - old_filename_no_timestamp = old_filename[20:] + if (re.search("^\d{4}-[012]\d-[0-3]\d_", old_filename) or + re.search('^\d{4}-[012]\d-[0-3]\dT[012]\d\.[0-5]\d\.[0-5]\d_', old_filename)): + + if re.search("^\d{4}-\d{2}-\d{2}_", old_filename): + # if (running date2name in default mode) then .true. + time_stamp = old_filename[:10] + time_stamp_separator = old_filename[10] + file_extension = old_filename.split(".")[-1] + old_filename_no_timestamp = old_filename[11:] + + elif re.search('^\d{4}-\d{2}-\d{2}T\d{2}\.\d{2}\.\d{2}_', old_filename): + # if (running date2name --withtime) then .true. + time_stamp = old_filename[:19] + time_stamp_separator = old_filename[19] + file_extension = old_filename.split(".")[-1] + old_filename_no_timestamp = old_filename[20:] + stem_elements = old_filename_no_timestamp.split(".")[:-1] stem = ".".join(stem_elements) diff --git a/test_generator.org b/test_generator.org index ea09f3a..5d7f4fb 100755 --- a/test_generator.org +++ b/test_generator.org @@ -319,29 +319,23 @@ def test_pattern_s3_02(arg1, arg2, arg3): # analysis section: old_filename = str(arg1) - if re.search("^\d{4}-\d{2}-\d{2}_", old_filename): - # if (running date2name in default mode) then .true. - time_stamp = old_filename[:10] - time_stamp_separator = old_filename[10] - file_extension = old_filename.split(".")[-1] - - old_filename_no_timestamp = old_filename[11:] - stem_elements = old_filename_no_timestamp.split(".")[:-1] - stem = ".".join(stem_elements) - - new_filename = "".join([time_stamp, arg3, text, arg3, stem, str("."), file_extension]) - assert os.path.isfile(new_filename) - - os.remove(new_filename) - assert os.path.isfile(new_filename) is False - - elif re.search('^\d{4}-\d{2}-\d{2}T\d{2}\.\d{2}\.\d{2}_', old_filename): - # if (running date2name --withtime) then .true. - time_stamp = old_filename[:19] - time_stamp_separator = old_filename[19] - file_extension = old_filename.split(".")[-1] - - old_filename_no_timestamp = old_filename[20:] + if (re.search("^\d{4}-[012]\d-[0-3]\d_", old_filename) or + re.search('^\d{4}-[012]\d-[0-3]\dT[012]\d\.[0-5]\d\.[0-5]\d_', old_filename)): + + if re.search("^\d{4}-\d{2}-\d{2}_", old_filename): + # if (running date2name in default mode) then .true. + time_stamp = old_filename[:10] + time_stamp_separator = old_filename[10] + file_extension = old_filename.split(".")[-1] + old_filename_no_timestamp = old_filename[11:] + + elif re.search('^\d{4}-\d{2}-\d{2}T\d{2}\.\d{2}\.\d{2}_', old_filename): + # if (running date2name --withtime) then .true. + time_stamp = old_filename[:19] + time_stamp_separator = old_filename[19] + file_extension = old_filename.split(".")[-1] + old_filename_no_timestamp = old_filename[20:] + stem_elements = old_filename_no_timestamp.split(".")[:-1] stem = ".".join(stem_elements)