def test_tidy_timestamp(): with WindowsTemp(TemporaryDirectory) as dir: log = init_log(dir, '7M', 1, 5, 0, 'test', False, 0)[0] assert_timestamp(log, '2018-7-4', '2018-07-04T00:00:00.000000') assert_timestamp(log, '2018-7-4T1:2:3.456', '2018-07-04T01:02:03.456000') assert_timestamp(log, '2018-7-4T1:3', '2018-07-04T01:03:00.000000')
def test_download_leap(): with WindowsTemp(TemporaryDirectory) as dir: log = init_log(dir, '7M', 1, 5, 0, 'test', False, 0)[0] path = join(dir, 'leap.txt') check_leap(True, DEFAULT_LEAPEXPIRE, path, DEFAULT_LEAPURL, DEFAULT_HTTPTIMEOUT, DEFAULT_HTTPRETRIES, log) assert exists(path)
def __init__(self, dir, **kargs): kargs = dict(kargs) kargs[_(DATADIR)] = join(dir, 'data') kargs[_(TEMPDIR)] = join(dir, 'tmp') kargs[_(LOGDIR)] = join(dir, 'logs') root = find_root() kargs[_(MSEEDINDEXCMD)] = join(root, '..', 'mseedindex', 'mseedindex') kargs[_(LEAP)] = False args = TestArgs(**kargs) self.command = args.command log, log_path, log_stream = init_log(args.log_dir, '7M', 1, 5, 0, 'test', args.leap, 0) dbpath = join(canonify(args.data_dir), 'timeseries.sqlite') create_parents(dbpath) super().__init__(log, log_path, args, init_db(dbpath, log), dir)
def do_all_levels(log_level, log_expected, stderr_level, stderr_expected): with WindowsTemp(TemporaryDirectory) as dir: logdir = join(dir, '.rover') stderr = StringIO() log = init_log(logdir, '7M', 1, log_level, stderr_level, 'rover', False, 0, stderr=stderr)[0] log_all(log) stderr.seek(0) stderr_contents = stderr.read() assert stderr_contents == stderr_expected, stderr_contents with open(join(logdir, 'rover.log'), 'r') as output: log_contents = remove_timestamp(output.read()) log_expected = remove_timestamp(log_expected) assert log_contents == log_expected, log_contents
def test_coverage(): with WindowsTemp(TemporaryDirectory) as dir: log = init_log(dir, '10M', 1, 5, 4, 'coverage', False, 1)[0] run(log, 0.5, 0.5, 0, 10, 0, 3, 2, 0, ((2, 5), (7, 10))) run(log, 0.5, 0.5, 2, 1, -1, 3, 2, 0, ()) run(log, 0.5, 0.5, 2, 1, -1, 3, 2, 1, ()) run(log, 0.5, 0.5, 2, 1, -1, 3, 2, 2, ()) run(log, 0.5, 0.5, 2, 1, -1, 1, 1, 0, ()) run(log, 0.5, 0.5, 2, 1, 0, 1, 1, 0, ((9.5, 10), )) run(log, 0.5, 0.5, 2, 1, 1, 1, 1, 0, ()) run(log, 0.5, 0.5, 1, 2, 0, 1, 2, 0, ()) run(log, 0.5, 0.5, 1, 2, 1, 1, 2, 0, ((2, 2.5), (5, 5.5), (8, 8.5))) run(log, 0.5, 0.5, 1, 2, 2, 1, 2, 0, ((2.5, 3), (5.5, 6), (8.5, 9))) run(log, 0.5, 0.5, 1, 2, 3, 1, 2, 0, ()) run(log, 0.5, 0.5, 2, 2, 0, 2, 2, 0, ()) run(log, 0.5, 0.5, 2, 2, 0, 2, 2, 1, ((0, 1), (4.5, 5), (8.5, 9))) run(log, 0.5, 0.5, 2, 2, 0, 2, 2, 2, ((0, 1.5), (4.5, 5.5), (8.5, 10))) run(log, 0.5, 0.5, 1, 1, 0, 3, 2, 0, ()) run(log, 0.5, 0.5, 1, 1, 0, 3, 2, 1, ((0, 0.5), )) # with tolerance 1.5 these overlap # (this was a bug with rover retrieve IU_ANMO_3?_* 2016-01-01T20:00:00 2016-01-02T04:00:00) # 0 1 2 3 4 5 6 # index | |====|====|====| | | # avail | | | |====|====| | # missing | | | | | | | run_explicit(log, 1.5, 0.5, [(1, 4)], [(3, 5)], []) # more of same (in retrospect these seem weird - we shouldn't be using a tolerance of 1.5!) seed(42) for i in range(100): # available of length at least 2 (so > tolerance) avail_start = randint(0, 4) avail_end = randint(avail_start + 2, 6) # index must start before one after start of avail (so before, within tolerance) index_start = randint(0, min(4, avail_start + 1)) # and must end with a width of at least 2, and at least one before end (so after, within tolerance) index_end = randint(max(avail_end - 1, index_start + 2), 6) run_explicit(log, 1.5, 0.5, [(index_start, index_end)], [(avail_start, avail_end)], [])