Skip to content

Commit

Permalink
Merge pull request #324 from neutrinoceros/digest_empty_files
Browse files Browse the repository at this point in the history
  • Loading branch information
neutrinoceros authored Sep 6, 2023
2 parents 6fcd754 + 61ebf2f commit 72070c5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

BUG: fix `baballe digest > file.json`
- BUG: fix `baballe digest > file.json`
- BUG: fix a bug where `idfx digest` would choke on files where no line is captured

## [3.2.0] - 2023-09-06

Expand Down
8 changes: 7 additions & 1 deletion src/idefix_cli/_commands/digest.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,18 @@ def command(

data: list[list[str]] = []
_success = False
for log in log_files:

for log in log_files.copy():
captured: list[str] = []
for line in log.read_text().splitlines():
if (match := _log_line_regexp.fullmatch(line)) is not None:
captured.append(match.group("data"))
_success = True
if not captured:
# dynamically exclude files without any data
log_files.remove(log)
continue

data.append(captured)

if not _success:
Expand Down
Empty file.
26 changes: 26 additions & 0 deletions tests/test_digest.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,29 @@ def test_digest_multiple_input(capsys):
assert err2 == ""

assert out == out2


def test_digest_empty_file(capsys):
ret = main(["digest", "--dir", str(BASE_SETUP.absolute()), "--input", "empty.log"])
assert ret != 0
out, err = capsys.readouterr()
assert out == ""
assert err == "💥 Failed to parse any data\n"


@pytest.mark.parametrize(
"logs",
[
("empty.log", "idefix.0.log"),
("empty.log", "idefix.1.log"),
# order shouldn't matter
("idefix.0.log", "empty.log"),
("idefix.1.log", "empty.log"),
],
)
def test_digest_mixed_contents(capsys, logs):
ret = main(["digest", "--dir", str(BASE_SETUP.absolute()), "--input", *logs])
assert ret == 0
out, err = capsys.readouterr()
json.loads(out) # validate output
assert err == ""

0 comments on commit 72070c5

Please sign in to comment.