Quantum-Accelerators/quacc

Add a test for `find_recent_logfile`

Andrew-S-Rosen opened this issue · 0 comments

What would you like to report?

The following function has become untested. We should test it! It is not too hard :)

def find_recent_logfile(directory: Path | str, logfile_extensions: str | list[str]):
"""
Find the most recent logfile in a given directory.
Parameters
----------
directory
The path to the directory to search
logfile_extensions
The extension (or list of possible extensions) of the logfile to search
for. For an exact match only, put in the full file name.
Returns
-------
logfile
The path to the most recent logfile with the desired extension
"""
mod_time = 0.0
logfile = None
if isinstance(logfile_extensions, str):
logfile_extensions = [logfile_extensions]
for f in Path(directory).expanduser().iterdir():
f_path = Path(directory, f)
for ext in logfile_extensions:
if ext in str(f) and f_path.stat().st_mtime > mod_time:
mod_time = f_path.stat().st_mtime
logfile = f_path.resolve()
return logfile