Example #1
0
def test_h_lead_no_pad_3_digit():
    template = "{init?fmt=%Y%m%d%H}_A{lead?fmt=%H}h"
    filepath = "1987020103_A102h"
    out = parse_template(template, filepath)
    ftime = out['valid'].strftime('%Y%m%d%H%M')
    assert (ftime == "198702050900")
Example #2
0
def test_3h_lead():
    template = "{init?fmt=%Y%m%d%H}_A{lead?fmt=%.3H}h"
    filepath = "1987020103_A003h"
    out = parse_template(template, filepath)
    ftime = out['valid'].strftime('%Y%m%d%H%M')
    assert (ftime == "198702010600")
Example #3
0
def test_filename_does_not_match_template_end():
    template = "{init?fmt=%Y%m%d%H}_dog_A{lead?fmt=%HH}h"
    filepath = "1987020103_dog_A03d"
    out = parse_template(template, filepath)
    assert (out == None)
Example #4
0
def test_filename_matches_template():
    template = "{init?fmt=%Y%m%d%H}_dog_A{lead?fmt=%HH}h"
    filepath = "1987020103_dog_A03h"
    out = parse_template(template, filepath)
    ftime = out['valid'].strftime('%Y%m%d%H%M')
    assert (ftime == "198702010600")
Example #5
0
def test_shift_time_extract():
    valid_dt = datetime.datetime.strptime("2017060406", '%Y%m%d%H')
    templ = "{valid?fmt=%Y%m%d%H?shift=-21600}"
    filename = "2017060400"
    dt = parse_template(templ, filename)['valid']
    assert (dt.strftime('%Y%m%d%H') == valid_dt.strftime('%Y%m%d%H'))
def test_parse_template(template, filepath, expected_valid):
    out = parse_template(template, filepath)
    ftime = out['valid'].strftime('%Y%m%d%H%M')
    assert (ftime == expected_valid)