コード例 #1
0
ファイル: test_cm_utils.py プロジェクト: mfkiwl/hera_mc
def test_datetime():
    from astropy.time import Time
    sys.argv = ['test']
    p = argparse.ArgumentParser()
    cm_utils.add_date_time_args(p)
    args = p.parse_args()
    assert args.date == 'now'
    assert args.time == 0.0
    import datetime
    tout = cm_utils.get_astropytime(datetime.datetime.now())
    assert type(tout) == Time
    tout = cm_utils.get_astropytime(2400001.0)
    assert type(tout) == Time
    pytest.raises(ValueError, cm_utils.get_astropytime, 0.0)
    tout = cm_utils.get_astropytime('none')
    assert tout is None
    tout = cm_utils.get_astropytime('2018/1/1', '0.0')
    assert type(tout) == Time
    pytest.raises(ValueError, cm_utils.get_astropytime, '18/1/1')
    tout = cm_utils.get_astropytime('2018/1/1', '12:30:00')
    assert type(tout) == Time
    pytest.raises(ValueError, cm_utils.get_astropytime, '2018/1/1', '0:0:0:0')
    pytest.raises(ValueError, cm_utils.get_astropytime, '2018/1/1', 'x')
コード例 #2
0
    args.date = cm_utils.query_default('date', args)
    args.time = cm_utils.query_default('time', args)
    args.date2 = cm_utils.query_default('date2', args)
    args.time2 = cm_utils.query_default('time2', args)
    return args


if __name__ == '__main__':
    parser = mc.get_mc_argument_parser()
    parser.add_argument('hpn', nargs='?', help="HERA part number")
    parser.add_argument('syspn', nargs='?', help="System part number")
    parser.add_argument('-q',
                        '--query',
                        help="Set flag if wished to be queried",
                        action='store_true')
    cm_utils.add_date_time_args(parser)
    parser.add_argument('--date2',
                        help="Stop date (if not None)",
                        default=None)
    parser.add_argument('--time2',
                        help="Stop time (if not None)",
                        default=None)
    parser.add_argument('--verbose',
                        help="Turn verbose mode on.",
                        action='store_true')
    args = parser.parse_args()

    if args.query:
        args = query_args(args)

    # Pre-process some args