Skip to content

Commit

Permalink
FileNotFoundError raised
Browse files Browse the repository at this point in the history
  • Loading branch information
venaturum committed Aug 1, 2024
1 parent 1be6a99 commit f96c759
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/gurobi_logtools/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,12 @@ def parse(patterns: Union[str, List[str]], write_to_dir=None) -> ParseResult:
result = ParseResult(write_to_dir=write_to_dir)
if type(patterns) is str:
patterns = [patterns]
logfiles = itertools.chain(*(glob.glob(pattern) for pattern in patterns))
for logfile in sorted(set(logfiles)):
logfiles = sorted(
set(itertools.chain(*(glob.glob(pattern) for pattern in patterns)))
)
if not len(logfiles):
raise FileNotFoundError(f"No logfiles found in patterns: {patterns}")
for logfile in logfiles:
result.parse(logfile)
return result

Expand All @@ -190,8 +194,10 @@ def get_dataframe(logfiles: List[str], timelines=False, prettyparams=False):
"""
result = parse(logfiles)
summary = result.summary(prettyparams=prettyparams)

if not timelines:
return summary

return summary, dict(
norel=result.progress("norel"),
rootlp=result.progress("rootlp"),
Expand Down
5 changes: 5 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,8 @@ def test_rewrite_filenames():
assert log_file.stem == expected_name
assert len(start_lines) == 1
assert len(end_lines) == 1


def test_no_logfile_error():
with pytest.raises(FileNotFoundError):
glt.parse("/file/with/a/tyop")

0 comments on commit f96c759

Please sign in to comment.