From 64eef66b543c54dad0d9ea623dcada04f1edfd13 Mon Sep 17 00:00:00 2001 From: SkalskiP Date: Thu, 28 Mar 2024 14:04:21 +0100 Subject: [PATCH 1/2] `get_data_item` unit tests --- test/detection/test_utils.py | 93 +++++++++++++++++++++++++++++++----- 1 file changed, 82 insertions(+), 11 deletions(-) diff --git a/test/detection/test_utils.py b/test/detection/test_utils.py index d09348ff5..899cb8589 100644 --- a/test/detection/test_utils.py +++ b/test/detection/test_utils.py @@ -1035,7 +1035,12 @@ def test_merge_data( @pytest.mark.parametrize( "data, index, expected_result, exception", [ - ({}, 0, {}, DoesNotRaise()), # empty data dict + ( + {}, + 0, + {}, + DoesNotRaise() + ), # empty data dict ( { "test_1": [1, 2, 3], @@ -1045,7 +1050,7 @@ def test_merge_data( "test_1": [1], }, DoesNotRaise(), - ), # single data dict with a single field name and list values + ), # data dict with a single list field and integer index ( { "test_1": np.array([1, 2, 3]), @@ -1055,7 +1060,7 @@ def test_merge_data( "test_1": np.array([1]), }, DoesNotRaise(), - ), # single data dict with a single field name and np.array values as 1D arrays + ), # data dict with a single np.array field and integer index ( { "test_1": [1, 2, 3], @@ -1065,7 +1070,7 @@ def test_merge_data( "test_1": [1, 2], }, DoesNotRaise(), - ), # single data dict with a single field name and list values + ), # data dict with a single list field and slice index ( { "test_1": np.array([1, 2, 3]), @@ -1075,7 +1080,7 @@ def test_merge_data( "test_1": np.array([1, 2]), }, DoesNotRaise(), - ), # single data dict with a single field name and np.array values as 1D arrays + ), # data dict with a single np.array field and slice index ( { "test_1": [1, 2, 3], @@ -1085,7 +1090,7 @@ def test_merge_data( "test_1": [3], }, DoesNotRaise(), - ), # single data dict with a single field name and list values + ), # data dict with a single list field and negative integer index ( { "test_1": np.array([1, 2, 3]), @@ -1095,7 +1100,7 @@ def test_merge_data( "test_1": np.array([3]), }, DoesNotRaise(), - ), # single data dict with a single field name and np.array values as 1D arrays + ), # data dict with a single np.array field and negative integer index ( { "test_1": [1, 2, 3], @@ -1105,7 +1110,7 @@ def test_merge_data( "test_1": [1, 3], }, DoesNotRaise(), - ), # single data dict with a single field name and list values + ), # data dict with a single list field and integer list index ( { "test_1": np.array([1, 2, 3]), @@ -1115,7 +1120,7 @@ def test_merge_data( "test_1": np.array([1, 3]), }, DoesNotRaise(), - ), # single data dict with a single field name and np.array values as 1D arrays + ), # data dict with a single np.array field and integer list index ( { "test_1": [1, 2, 3], @@ -1125,7 +1130,7 @@ def test_merge_data( "test_1": [1, 3], }, DoesNotRaise(), - ), # single data dict with a single field name and list values + ), # data dict with a single list field and integer np.array index ( { "test_1": np.array([1, 2, 3]), @@ -1135,7 +1140,73 @@ def test_merge_data( "test_1": np.array([1, 3]), }, DoesNotRaise(), - ), + ), # data dict with a single np.array field and integer np.array index + ( + { + "test_1": np.array([1, 2, 3]), + }, + np.array([True, True, True]), + { + "test_1": np.array([1, 2, 3]), + }, + DoesNotRaise(), + ), # data dict with a single np.array field and all-true bool np.array index + ( + { + "test_1": np.array([1, 2, 3]), + }, + np.array([False, False, False]), + { + "test_1": np.array([]), + }, + DoesNotRaise(), + ), # data dict with a single np.array field and all-false bool np.array index + ( + { + "test_1": np.array([1, 2, 3]), + }, + np.array([False, True, False]), + { + "test_1": np.array([2]), + }, + DoesNotRaise(), + ), # data dict with a single np.array field and mixed bool np.array index + ( + { + "test_1": np.array([1, 2, 3]), + "test_2": ['a', 'b', 'c'] + }, + 0, + { + "test_1": np.array([1]), + "test_2": ['a'] + }, + DoesNotRaise(), + ), # data dict with two fields and integer index + ( + { + "test_1": np.array([1, 2, 3]), + "test_2": ['a', 'b', 'c'] + }, + -1, + { + "test_1": np.array([3]), + "test_2": ['c'] + }, + DoesNotRaise(), + ), # data dict with two fields and negative integer index + ( + { + "test_1": np.array([1, 2, 3]), + "test_2": ['a', 'b', 'c'] + }, + np.array([False, True, False]), + { + "test_1": np.array([2]), + "test_2": ['b'] + }, + DoesNotRaise(), + ), # data dict with two fields and mixed bool np.array index ], ) def test_get_data_item( From dc5f841baef5eec6f318374cc295666dac3362c4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 28 Mar 2024 13:06:45 +0000 Subject: [PATCH 2/2] =?UTF-8?q?fix(pre=5Fcommit):=20=F0=9F=8E=A8=20auto=20?= =?UTF-8?q?format=20pre-commit=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/detection/test_utils.py | 37 +++++++----------------------------- 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/test/detection/test_utils.py b/test/detection/test_utils.py index 899cb8589..1c4a1d349 100644 --- a/test/detection/test_utils.py +++ b/test/detection/test_utils.py @@ -1035,12 +1035,7 @@ def test_merge_data( @pytest.mark.parametrize( "data, index, expected_result, exception", [ - ( - {}, - 0, - {}, - DoesNotRaise() - ), # empty data dict + ({}, 0, {}, DoesNotRaise()), # empty data dict ( { "test_1": [1, 2, 3], @@ -1172,39 +1167,21 @@ def test_merge_data( DoesNotRaise(), ), # data dict with a single np.array field and mixed bool np.array index ( - { - "test_1": np.array([1, 2, 3]), - "test_2": ['a', 'b', 'c'] - }, + {"test_1": np.array([1, 2, 3]), "test_2": ["a", "b", "c"]}, 0, - { - "test_1": np.array([1]), - "test_2": ['a'] - }, + {"test_1": np.array([1]), "test_2": ["a"]}, DoesNotRaise(), ), # data dict with two fields and integer index ( - { - "test_1": np.array([1, 2, 3]), - "test_2": ['a', 'b', 'c'] - }, + {"test_1": np.array([1, 2, 3]), "test_2": ["a", "b", "c"]}, -1, - { - "test_1": np.array([3]), - "test_2": ['c'] - }, + {"test_1": np.array([3]), "test_2": ["c"]}, DoesNotRaise(), ), # data dict with two fields and negative integer index ( - { - "test_1": np.array([1, 2, 3]), - "test_2": ['a', 'b', 'c'] - }, + {"test_1": np.array([1, 2, 3]), "test_2": ["a", "b", "c"]}, np.array([False, True, False]), - { - "test_1": np.array([2]), - "test_2": ['b'] - }, + {"test_1": np.array([2]), "test_2": ["b"]}, DoesNotRaise(), ), # data dict with two fields and mixed bool np.array index ],