def test_audit_short_file(self, filename, expected_output):
        BashColor.disable_color()

        with mock_stdin(), mock_printer(
                # To extract the baseline output
                main_module, ) as printer_shim:
            main(['scan', filename])
            baseline = printer_shim.message

        baseline_dict = json.loads(baseline)
        with mock_stdin(), mock.patch(
                # To pipe in printer_shim
                'detect_secrets.core.audit._get_baseline_from_file',
                return_value=baseline_dict,
        ), mock.patch(
                # We don't want to clear the pytest testing screen
                'detect_secrets.core.audit._clear_screen', ), mock.patch(
                    # Gotta mock it, because tests aren't interactive
                    'detect_secrets.core.audit._get_user_decision',
                    return_value='s',
                ), mock.patch(
                    # We don't want to write an actual file
                    'detect_secrets.core.audit._save_baseline_to_file',
                ), mock_printer(audit_module, ) as printer_shim:
            main('audit will_be_mocked'.split())

            assert printer_shim.message == textwrap.dedent("""
                Secret:      1 of 1
                Filename:    {}
                Secret Type: {}
                ----------
                {}
                ----------
                Saving progress...
            """)[1:].format(
                filename,
                baseline_dict['results'][filename][0]['type'],
                expected_output,
            )

        BashColor.enable_color()
 def teardown(self):
     BashColor.enable_color()
 def setup(self):
     BashColor.disable_color()
Beispiel #4
0
 def teardown(self):
     BashColor.enable_color()
Beispiel #5
0
 def setup(self):
     BashColor.disable_color()