From 3b6fef74733ac1bd168ae1232a09bafa9da0570f Mon Sep 17 00:00:00 2001 From: julioloayzam Date: Thu, 15 Aug 2024 23:55:26 +0200 Subject: [PATCH] fix(common): pass None as filename to process_results 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 --- crypto_condor/primitives/common.py | 4 ++-- tests/primitives/test_common.py | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 tests/primitives/test_common.py diff --git a/crypto_condor/primitives/common.py b/crypto_condor/primitives/common.py index b520eb0..2652035 100644 --- a/crypto_condor/primitives/common.py +++ b/crypto_condor/primitives/common.py @@ -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: @@ -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. diff --git a/tests/primitives/test_common.py b/tests/primitives/test_common.py new file mode 100644 index 0000000..6ce3ff2 --- /dev/null +++ b/tests/primitives/test_common.py @@ -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)