def test_configure_logging(): """Assert that the ``configure_logging`` function successfully creates a log file""" log_file = logging_functions.configure_logging('test_logging_functions') assert os.path.exists(log_file) # Remove the log file shutil.rmtree(os.path.dirname(log_file), ignore_errors=True)
def test_logging_functions(): """A generic end-to-end test that creates a log file, does some basic logging, then asserts that some logging content exists""" log_file = configure_logging('test_logging_functions') perform_basic_logging() # Open the log file and make some assertions with open(log_file, 'r') as f: data = f.readlines() data = str([line.strip() for line in data]) testable_content = [ 'User:'******'System:', 'Python Executable Path:', 'INFO:', 'WARNING:', 'CRITICAL:', 'Elapsed Real Time:', 'Elapsed CPU Time:', 'Completed Successfully' ] for item in testable_content: assert item in data
def initialize_instrument_monitor(module): """Configures a log file for the instrument monitor run and captures the start time of the monitor Parameters ---------- module : str The module name (e.g. ``dark_monitor``) Returns ------- start_time : datetime object The start time of the monitor log_file : str The path to where the log file is stored """ start_time = datetime.datetime.now() log_file = configure_logging(module) return start_time, log_file
@log_fail @log_info def monitor_mast(): """Tabulates the inventory of all JWST data products in the MAST archive and generates plots. """ logging.info('Beginning database monitoring.') # Perform inventory of the JWST service jwst_inventory(instruments=JWST_INSTRUMENT_NAMES, dataproducts=['image', 'spectrum', 'cube'], caom=False, plot=True) # Perform inventory of the CAOM service jwst_inventory(instruments=JWST_INSTRUMENT_NAMES, dataproducts=['image', 'spectrum', 'cube'], caom=True, plot=True) if __name__ == '__main__': # Configure logging module = os.path.basename(__file__).strip('.py') configure_logging(module) # Run the monitors monitor_mast()
def success_check(filename): """Parse the given log file and check whether the script execution was successful or not Parameters ---------- filename : str Name of the log file to parse Returns ------- execution : str ``success`` or ``failure`` """ with open(filename, 'r') as file_obj: all_lines = file_obj.readlines() final_line = all_lines[-1] if 'complete' in final_line.lower(): execution = 'success' else: execution = 'failure' return execution if __name__ == '__main__': module = os.path.basename(__file__).strip('.py') configure_logging(module, production_mode=True) status()