def test_filename_does_not_match_template_end(): logger = logging.getLogger("test") template = "{init?fmt=%Y%m%d%H}_dog_A{lead?fmt=%HH}h" filepath = "1987020103_dog_A03d" se = StringExtract(logger, template, filepath) out = se.parse_template() assert(out == None)
def test_shift_time_extract(): valid_dt = datetime.datetime.strptime("2017060406", '%Y%m%d%H') logger = logging.getLogger("testing") templ = "{valid?fmt=%Y%m%d%H?shift=-21600}" filename = "2017060400" se = StringExtract(logger, templ, filename) dt = se.parseTemplate()['valid'] assert (dt.strftime('%Y%m%d%H') == valid_dt.strftime('%Y%m%d%H'))
def test_h_lead_no_pad_3_digit(): logger = logging.getLogger("test") template = "{init?fmt=%Y%m%d%H}_A{lead?fmt=%H}h" filepath = "1987020103_A102h" se = StringExtract(logger, template, filepath) out = se.parseTemplate() ftime = out['valid'].strftime('%Y%m%d%H%M') assert (ftime == "198702050900")
def test_3h_lead(): logger = logging.getLogger("test") template = "{init?fmt=%Y%m%d%H}_A{lead?fmt=%.3H}h" filepath = "1987020103_A003h" se = StringExtract(logger, template, filepath) out = se.parseTemplate() ftime = out['valid'].strftime('%Y%m%d%H%M') assert (ftime == "198702010600")
def test_filename_matches_template(): logger = logging.getLogger("test") template = "{init?fmt=%Y%m%d%H}_dog_A{lead?fmt=%HH}h" filepath = "1987020103_dog_A03h" se = StringExtract(logger, template, filepath) out = se.parse_template() ftime = out['valid'].strftime('%Y%m%d%H%M') assert(ftime == "198702010600")