Example #1
0
def test_stdout_version(capsys):
    """Verify that version string sent to stdout agrees with the module version."""
    with pytest.raises(SystemExit):
        with patch.object(sys, "argv", ["bogus", "--version"]):
            clamav_report.main()
    captured = capsys.readouterr()
    assert (
        captured.out == f"{PROJECT_VERSION}\n"
    ), "standard output by '--version' should agree with module.__version__"
Example #2
0
def test_bad_log_level():
    """Validate bad log-level argument returns error."""
    with patch.object(
        sys,
        "argv",
        ["bogus", "--log-level=emergency", "tests/files/inventory.txt", "out.csv"],
    ):
        return_code = None
        try:
            clamav_report.main()
        except SystemExit as sys_exit:
            return_code = sys_exit.code
        assert return_code == 1, "main() should exit with error"
def test_log_levels(level):
    """Validate commandline log-level arguments."""
    with patch.object(
            sys, "argv",
        ["bogus", f"--log-level={level}", "tests/inventory.txt", "out.csv"]):
        with patch.object(logging.root, "handlers", []):
            assert (logging.root.hasHandlers() is
                    False), "root logger should not have handlers yet"
            return_code = clamav_report.main()
            assert (logging.root.hasHandlers() is
                    True), "root logger should now have a handler"
            assert return_code == 0, "main() should return success (0)"
Example #4
0
def test_log_levels(level):
    """Validate commandline log-level arguments."""
    with patch.object(
        sys,
        "argv",
        ["bogus", f"--log-level={level}", "tests/files/inventory.txt", "out.csv"],
    ):
        with patch.object(logging.root, "handlers", []):
            assert (
                logging.root.hasHandlers() is False
            ), "root logger should not have handlers yet"
            return_code = None
            try:
                clamav_report.main()
            except SystemExit as sys_exit:
                return_code = sys_exit.code
            assert return_code is None, "main() should return success"
            assert (
                logging.root.hasHandlers() is True
            ), "root logger should now have a handler"
            assert (
                logging.getLevelName(logging.root.getEffectiveLevel()) == level.upper()
            ), f"root logger level should be set to {level.upper()}"
            assert return_code is None, "main() should return success"