def test_download(test_input, expected): with tempfile.TemporaryDirectory() as temp_dir: station, start, end = test_input start_date = datetime.strptime(start, '%Y-%m-%dT%H:%M:%SZ') end_date = datetime.strptime(end, '%Y-%m-%dT%H:%M:%SZ') r = RinexDownloader(station, start_date, end_date, temp_dir) r.download() assert glob('{}/*'.format(temp_dir)) == [ '{}/{}'.format(temp_dir, i) for i in expected ]
def test_decompress_files(test_input, expected): with tempfile.TemporaryDirectory() as temp_dir: station, start, end = test_input start_date = datetime.strptime(start, '%Y-%m-%dT%H:%M:%SZ') end_date = datetime.strptime(end, '%Y-%m-%dT%H:%M:%SZ') r = RinexDownloader(station, start_date, end_date, temp_dir) m = RinexMerger(station, start_date, end_date, temp_dir) r.download() m.decompress_files() assert set(glob('{}/{}'.format(temp_dir, '*.??o') )) == set(['{}/{}'.format(temp_dir, i) for i in expected])
def test_days_in_year(test_input, expected): r = RinexDownloader('nybp', datetime.now(), datetime.now(), 'output') assert r.get_days_in_year(test_input) == expected
def test_days_left_in_year(test_input, expected): d = datetime.strptime(test_input, '%Y-%m-%dT%H:%M:%SZ') r = RinexDownloader('nybp', datetime.now(), datetime.now(), 'output') assert r.get_days_left_in_year(d) == expected
def test_deconstruct_time(test_input, expected): d = datetime.strptime(test_input, '%Y-%m-%dT%H:%M:%SZ') r = RinexDownloader('nybp', datetime.now(), datetime.now(), 'output') assert r.deconstruct_datetime(d) == expected
def test_file_name_exceptions(test_input): r = RinexDownloader('nybp', datetime.now(), datetime.now()) year, yday, start, end, error_message = test_input with pytest.raises(ValueError, match=error_message): r.generate_file_names(year, yday, start, end)
def test_file_name_generation(test_input, expected): r = RinexDownloader('nybp', datetime.now(), datetime.now()) year, yday, start, end = test_input assert len(r.generate_file_names(year, yday, start, end)) == expected
def test_valid_station_code(test_input, expected): """ Tests if user inputted station code is valid. """ station, start_date, end_date = test_input r = RinexDownloader(station, start_date, end_date) assert r.is_valid_station_code() == expected