Skip to content

Commit

Permalink
fix(common): pass None as filename to process_results
Browse files Browse the repository at this point in the history
Console.process_results has a filename argument, that according to its
documentation, if its None the results are only displayed but not saved
to a file, and the user is not prompted for a filename.

As reported in #7, the user is still prompted when passing None. This
commit fixes this, and adds a test to confirm the fix and prevent
regressions.

Co-authored-by: Baptistin BOILOT <[email protected]>
  • Loading branch information
JulioLoayzaM and bboilot-ledger committed Aug 15, 2024
1 parent b6dc361 commit 3b6fef7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions crypto_condor/primitives/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ def print_results(self, res: Results | ResultsDict) -> None:
def process_results(
self,
res: ResultsDict | Results,
filename: str = "",
filename: str | None = "",
no_save: bool = False,
debug_data: bool | None = None,
) -> bool:
Expand Down Expand Up @@ -769,7 +769,7 @@ def process_results(
subtitle=f"crypto-condor {padded_version} by Quarkslab",
)
self.print(summary)
if no_save:
if no_save or filename is None:
# Nothing more to do.
return res.check()
# Save results.
Expand Down
20 changes: 20 additions & 0 deletions tests/primitives/test_common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""Module to test crypto_condor.primitives.common."""

from hashlib import sha256
from pathlib import Path

from crypto_condor.primitives import SHA
from crypto_condor.primitives.common import Console


class TestConsole:
"""Tests for the Console class."""

def test_filename_none(self, tmp_path: Path):
"""Tests passing None as filename.
The expected behaviour is that the user is not prompted for a filename.
"""
rd = SHA.test(lambda msg: sha256(msg).digest(), SHA.Algorithm.SHA_256)
console = Console()
assert console.process_results(rd, None)

0 comments on commit 3b6fef7

Please sign in to comment.