From a6ed1f63bc0901d292d684dd927c2ef9e89f687d Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Wed, 21 May 2025 21:07:28 +0200 Subject: [PATCH] tests: move tests to testsuite.helpers.__init__test --- src/borg/testsuite/helpers/__init__test.py | 64 ++++++++++++++++++++++ src/borg/testsuite/helpers_test.py | 61 --------------------- 2 files changed, 64 insertions(+), 61 deletions(-) create mode 100644 src/borg/testsuite/helpers/__init__test.py diff --git a/src/borg/testsuite/helpers/__init__test.py b/src/borg/testsuite/helpers/__init__test.py new file mode 100644 index 000000000..7eee4ddf5 --- /dev/null +++ b/src/borg/testsuite/helpers/__init__test.py @@ -0,0 +1,64 @@ +import pytest + +from ...constants import * # NOQA +from ...helpers import classify_ec, max_ec + + +@pytest.mark.parametrize( + "ec_range,ec_class", + ( + # inclusive range start, exclusive range end + ((0, 1), "success"), + ((1, 2), "warning"), + ((2, 3), "error"), + ((EXIT_ERROR_BASE, EXIT_WARNING_BASE), "error"), + ((EXIT_WARNING_BASE, EXIT_SIGNAL_BASE), "warning"), + ((EXIT_SIGNAL_BASE, 256), "signal"), + ), +) +def test_classify_ec(ec_range, ec_class): + for ec in range(*ec_range): + classify_ec(ec) == ec_class + + +def test_ec_invalid(): + with pytest.raises(ValueError): + classify_ec(666) + with pytest.raises(ValueError): + classify_ec(-1) + with pytest.raises(TypeError): + classify_ec(None) + + +@pytest.mark.parametrize( + "ec1,ec2,ec_max", + ( + # same for modern / legacy + (EXIT_SUCCESS, EXIT_SUCCESS, EXIT_SUCCESS), + (EXIT_SUCCESS, EXIT_SIGNAL_BASE, EXIT_SIGNAL_BASE), + # legacy exit codes + (EXIT_SUCCESS, EXIT_WARNING, EXIT_WARNING), + (EXIT_SUCCESS, EXIT_ERROR, EXIT_ERROR), + (EXIT_WARNING, EXIT_SUCCESS, EXIT_WARNING), + (EXIT_WARNING, EXIT_WARNING, EXIT_WARNING), + (EXIT_WARNING, EXIT_ERROR, EXIT_ERROR), + (EXIT_WARNING, EXIT_SIGNAL_BASE, EXIT_SIGNAL_BASE), + (EXIT_ERROR, EXIT_SUCCESS, EXIT_ERROR), + (EXIT_ERROR, EXIT_WARNING, EXIT_ERROR), + (EXIT_ERROR, EXIT_ERROR, EXIT_ERROR), + (EXIT_ERROR, EXIT_SIGNAL_BASE, EXIT_SIGNAL_BASE), + # some modern codes + (EXIT_SUCCESS, EXIT_WARNING_BASE, EXIT_WARNING_BASE), + (EXIT_SUCCESS, EXIT_ERROR_BASE, EXIT_ERROR_BASE), + (EXIT_WARNING_BASE, EXIT_SUCCESS, EXIT_WARNING_BASE), + (EXIT_WARNING_BASE + 1, EXIT_WARNING_BASE + 2, EXIT_WARNING_BASE + 1), + (EXIT_WARNING_BASE, EXIT_ERROR_BASE, EXIT_ERROR_BASE), + (EXIT_WARNING_BASE, EXIT_SIGNAL_BASE, EXIT_SIGNAL_BASE), + (EXIT_ERROR_BASE, EXIT_SUCCESS, EXIT_ERROR_BASE), + (EXIT_ERROR_BASE, EXIT_WARNING_BASE, EXIT_ERROR_BASE), + (EXIT_ERROR_BASE + 1, EXIT_ERROR_BASE + 2, EXIT_ERROR_BASE + 1), + (EXIT_ERROR_BASE, EXIT_SIGNAL_BASE, EXIT_SIGNAL_BASE), + ), +) +def test_max_ec(ec1, ec2, ec_max): + assert max_ec(ec1, ec2) == ec_max diff --git a/src/borg/testsuite/helpers_test.py b/src/borg/testsuite/helpers_test.py index 85940443c..a4f535a50 100644 --- a/src/borg/testsuite/helpers_test.py +++ b/src/borg/testsuite/helpers_test.py @@ -4,7 +4,6 @@ import pytest from ..constants import * # NOQA from ..helpers import ChunkerParams -from ..helpers import classify_ec, max_ec @pytest.mark.parametrize( @@ -37,63 +36,3 @@ def test_valid_chunkerparams(chunker_params, expected_return): def test_invalid_chunkerparams(invalid_chunker_params): with pytest.raises(ArgumentTypeError): ChunkerParams(invalid_chunker_params) - - -@pytest.mark.parametrize( - "ec_range,ec_class", - ( - # inclusive range start, exclusive range end - ((0, 1), "success"), - ((1, 2), "warning"), - ((2, 3), "error"), - ((EXIT_ERROR_BASE, EXIT_WARNING_BASE), "error"), - ((EXIT_WARNING_BASE, EXIT_SIGNAL_BASE), "warning"), - ((EXIT_SIGNAL_BASE, 256), "signal"), - ), -) -def test_classify_ec(ec_range, ec_class): - for ec in range(*ec_range): - classify_ec(ec) == ec_class - - -def test_ec_invalid(): - with pytest.raises(ValueError): - classify_ec(666) - with pytest.raises(ValueError): - classify_ec(-1) - with pytest.raises(TypeError): - classify_ec(None) - - -@pytest.mark.parametrize( - "ec1,ec2,ec_max", - ( - # same for modern / legacy - (EXIT_SUCCESS, EXIT_SUCCESS, EXIT_SUCCESS), - (EXIT_SUCCESS, EXIT_SIGNAL_BASE, EXIT_SIGNAL_BASE), - # legacy exit codes - (EXIT_SUCCESS, EXIT_WARNING, EXIT_WARNING), - (EXIT_SUCCESS, EXIT_ERROR, EXIT_ERROR), - (EXIT_WARNING, EXIT_SUCCESS, EXIT_WARNING), - (EXIT_WARNING, EXIT_WARNING, EXIT_WARNING), - (EXIT_WARNING, EXIT_ERROR, EXIT_ERROR), - (EXIT_WARNING, EXIT_SIGNAL_BASE, EXIT_SIGNAL_BASE), - (EXIT_ERROR, EXIT_SUCCESS, EXIT_ERROR), - (EXIT_ERROR, EXIT_WARNING, EXIT_ERROR), - (EXIT_ERROR, EXIT_ERROR, EXIT_ERROR), - (EXIT_ERROR, EXIT_SIGNAL_BASE, EXIT_SIGNAL_BASE), - # some modern codes - (EXIT_SUCCESS, EXIT_WARNING_BASE, EXIT_WARNING_BASE), - (EXIT_SUCCESS, EXIT_ERROR_BASE, EXIT_ERROR_BASE), - (EXIT_WARNING_BASE, EXIT_SUCCESS, EXIT_WARNING_BASE), - (EXIT_WARNING_BASE + 1, EXIT_WARNING_BASE + 2, EXIT_WARNING_BASE + 1), - (EXIT_WARNING_BASE, EXIT_ERROR_BASE, EXIT_ERROR_BASE), - (EXIT_WARNING_BASE, EXIT_SIGNAL_BASE, EXIT_SIGNAL_BASE), - (EXIT_ERROR_BASE, EXIT_SUCCESS, EXIT_ERROR_BASE), - (EXIT_ERROR_BASE, EXIT_WARNING_BASE, EXIT_ERROR_BASE), - (EXIT_ERROR_BASE + 1, EXIT_ERROR_BASE + 2, EXIT_ERROR_BASE + 1), - (EXIT_ERROR_BASE, EXIT_SIGNAL_BASE, EXIT_SIGNAL_BASE), - ), -) -def test_max_ec(ec1, ec2, ec_max): - assert max_ec(ec1, ec2) == ec_max