From 40ebe7827d22d17addae2d54a71b9a831784e664 Mon Sep 17 00:00:00 2001 From: Malachi Soord Date: Thu, 11 Mar 2021 20:30:10 +0100 Subject: [PATCH] Fix regression with saving results (#40) * Fix regression with saving results * Correct CHANGELOG * Add testcase --- CHANGELOG.md | 6 ++++++ tell_me_your_secrets/__init__.py | 2 +- tell_me_your_secrets/__main__.py | 2 +- test/test_main.py | 26 ++++++++++++++++++++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 test/test_main.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a0afd6..e92d2b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## v2.2.1 (2020-03-11) + +### Fixed + +- Fixed regression with saving results object (#40) + ## v2.2.0 (2020-03-05) ### Added diff --git a/tell_me_your_secrets/__init__.py b/tell_me_your_secrets/__init__.py index 04188a1..36a511e 100644 --- a/tell_me_your_secrets/__init__.py +++ b/tell_me_your_secrets/__init__.py @@ -1 +1 @@ -__version__ = '2.2.0' +__version__ = '2.2.1' diff --git a/tell_me_your_secrets/__main__.py b/tell_me_your_secrets/__main__.py index e4d89ce..eaf543e 100644 --- a/tell_me_your_secrets/__main__.py +++ b/tell_me_your_secrets/__main__.py @@ -210,7 +210,7 @@ def process(self, filtered_files: list): def write_results_to_file(self): if len(self.matched_signatures) > 0: - write_df = DataFrame(self.matched_signatures) + write_df = DataFrame(map(vars, self.matched_signatures)) if '.csv' not in self.output_path: self.output_path += '.csv' file_name = self.output_path diff --git a/test/test_main.py b/test/test_main.py new file mode 100644 index 0000000..015cc1e --- /dev/null +++ b/test/test_main.py @@ -0,0 +1,26 @@ +import tempfile +import unittest + +from tell_me_your_secrets.__main__ import SignatureRecognizer +from tell_me_your_secrets.processor import SignatureMatch + + +class WriteResultsTest(unittest.TestCase): + + def test_write_results_to_file_no_issues(self): + with tempfile.NamedTemporaryFile(suffix='.csv') as output_file: + signature_recognizer = SignatureRecognizer({}, "", False, 1, write_results=True, + output_path=output_file.name) + signature_recognizer.write_results_to_file() + self.assertEqual(b"", output_file.read()) + + def test_write_results_to_file_issues(self): + with tempfile.NamedTemporaryFile(suffix='.csv') as output_file: + signature_recognizer = SignatureRecognizer({}, "", False, 1, write_results=True, + output_path=output_file.name) + signature_recognizer.matched_signatures = [ + SignatureMatch('Match', 'file', '/path/to/file') + ] + + signature_recognizer.write_results_to_file() + self.assertEqual(b',name,part,path\n0,Match,file,/path/to/file\n', output_file.read())